Session restore relaunches agents without their original flags, environment, and pane cwd #1080
Replies: 6 comments
|
thanks for the report. i’m going to close this as a feature request rather than a bug. agent restore currently means: restore the pane, then run the supported agent’s resume command with the saved session id, e.g. that boundary is intentional. the current path is safe and robust because herdr does not parse shell history, last commands, or process invocations. preserving flags, inline env, and exact launch context would require process/pane launch tracking or a shim, which is a separate feature with different tradeoffs and a much larger scope. for now, put persistent agent behavior in the agent’s own settings where possible, e.g. claude permission settings instead of one-off cli flags. feel free to open a discussion for this as a feature idea. |
|
Following up on #965 — closed as needing "process/pane launch tracking or a shim." I think there's a much smaller version of this that avoids launch tracking entirely, scoped to the one piece that actually breaks unattended fleets: the permission/approval mode. The key point: the dangerous-mode signal is already persisted in the agent's own session file — the same file herdr reads to resume. So herdr doesn't need to know how the process was originally launched; it can derive the correct resume flag from the session it's already resuming from. Codex (rollout JSONL) records the effective policy per turn: { "type": "turn_context",
"payload": {
"approval_policy": "never",
"sandbox_policy": { "type": "danger-full-access" } } }
Claude Code (session JSONL) records the mode directly: { "type": "permission-mode", "permissionMode": "bypassPermissions", "sessionId": "..." }(user rows also carry Proposed scope — on restore, after resolving the session id, read the last known mode from that session file and map it to the resume argv:
This is deliberately not the broad request from #965. No argv replay, no env reconstruction, no per-pane cwd tracking — just reading a field that's already in the file herdr opens to resume. It targets the specific failure that makes restore unsafe for autonomous fleets: every agent silently downgrades to per-command approval prompts on server restart/update and freezes at its first tool call until a human repairs the pane. The "put it in agent settings" workaround doesn't fully cover this — these flags are intentionally one-off/per-invocation (there's no persistent config equivalent for Codex |
|
moved to discussion since it's a shape of feature req now but i'll test @rjyo's idea soon. |
|
Another concrete case of this: Claude profiles via The workaround suggested there (set the var from shell rc or a directory-aware env tool) doesn't cover setups where the profile isn't derivable from the cwd. This case fits the "derive it from what herdr already reads" approach discussed above: the claude integration hook already reports the transcript's full path as |
|
Adding an adjacent case that I think matters for how this gets designed: agents launched through a sandbox wrapper. I run Claude Code with So I am currently losing The pane record Herdr persists is just cwd plus agent_session (source/agent/kind/value), so there is nothing to replay and no wrapper-side fix available (that is with Herdr 0.7.5 on Linux). Of course one could entirely deactivate session restore (which I am doing currently), but that's inconvenient since it hits all agents and sessions, not those launched via a wrapper. A minimal suggestion would therefore be for automatic restore to be skipped if HERDR_AGENT was set on the foreground process. Ideally, there would be a way to specify not only the manifest via HERDR_AGENT, but also an explicit restore command line via another env variable: |
|
I’m hitting the same restore gap, specifically for per-invocation agent flags. I don’t need Herdr to reconstruct the original argv, environment, cwd, or wrapper. Would you be open to a smaller opt-in config surface that appends literal argv items to Herdr’s canonical resume command, for example: [session.agent_resume_args]
claude = ["--dangerously-skip-permissions"]
codex = ["--yolo"]It would be empty by default and scoped per agent. Alternatively, would you prefer the explicit resume-command override suggested above? I’m willing to implement the shape you prefer after approval. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Is this a reproducible bug?
Current behavior
After
herdr server stopand relaunching the same named session, the layout restores great - workspaces, tabs, panes, ids, labels all intact, and each pane's agent relaunches with its session id. But the relaunch drops everything else about how the agent was originally started:claude --dangerously-skip-permissionscame back as plain resumedclaude, silently downgraded to per-command approval prompts (the missing "bypass permissions on" footer line is the tell)CLAUDE_CODE_ENABLE_PROMPT_SUGGESTION=falseset at launch was not present after restoreI hit this across multiple server restarts in one afternoon running a fleet of agent panes. Every pane needed manual repair: interrupt, exit, relaunch with the right cwd + flags +
--resume <id>.Expected behavior
A restored pane relaunches its agent with the same argv, environment, and per-pane working directory it had before the stop. The session-id resume part already works - it's the launch context around it that gets lost.
Reproduction
herdr, create a tab in directory Acd /some/other/dir-B, thenFOO=bar claude --dangerously-skip-permissionsherdr server stop, relaunchherdr, let the session restore--dangerously-skip-permissions(default permission mode in the footer),FOOunset, cwd is A instead of dir-BImpact
Unattended agent fleets silently lose autonomy on every server restart - each agent freezes at its first tool-approval prompt until a human fixes the pane by hand. Bit me twice in one afternoon before I worked out the repair routine.
Environment
update_check = false,manifest_check = falseAll reactions