Skip to content

fix: preserve cwd for Codex handoffs - #27326

Open
ai-jz wants to merge 1 commit into
NousResearch:mainfrom
ai-jz:fix/handoff-preserve-cwd
Open

fix: preserve cwd for Codex handoffs#27326
ai-jz wants to merge 1 commit into
NousResearch:mainfrom
ai-jz:fix/handoff-preserve-cwd

Conversation

@ai-jz

@ai-jz ai-jz commented May 17, 2026

Copy link
Copy Markdown

What does this PR do?

Preserves the CLI working directory when /handoff <platform> moves a session into the gateway, so Codex app-server starts in the original project instead of the gateway install directory.

The change keeps the scope narrow:

  • capture the CLI cwd when /handoff marks the session pending
  • persist it on the handoff row and destination gateway session entry
  • pass it to the cached AIAgent for that gateway session
  • use it only when spawning the Codex app-server subprocess

Why?

Without this, a handoff from a project directory can continue from Slack while Codex app-server starts from the Hermes install cwd, so Codex loads the wrong local context and answers from the wrong workspace.

Related: #21427 covers broader resume cwd restoration. This PR is narrower and handoff-specific.

How has this been tested?

  • scripts/run_tests.sh tests/hermes_cli/test_session_handoff.py tests/gateway/test_session.py tests/agent/transports/test_codex_app_server_runtime.py -q
  • git diff --check

Platform tested: macOS.

@cardtest15-coder

This comment was marked as spam.

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/cli CLI entry point, hermes_cli/, setup wizard comp/gateway Gateway runner, session dispatch, delivery comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint labels May 17, 2026
@teknium1

teknium1 commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Thanks for the focused handoff fix. The underlying failure remains on current main: /handoff calls request_handoff() without a cwd (hermes_cli/cli_commands_mixin.py:623), while Codex falls back to resolve_agent_cwd() when agent.session_cwd is absent (agent/codex_runtime.py:342-345).

Problems

  • Current main already persists the CLI workspace as sessions.cwd (hermes_state.py:743; run_agent.py:600-609). Adding a separate handoff_cwd column would create competing cwd state.
  • Setting only agent.session_cwd is incomplete. Gateway cwd resolution is also bound through gateway/session_context.py:209-211, but GatewayRunner._set_session_env() currently does not pass a cwd (gateway/run.py:15000-15011). That leaves context-file discovery and other runtime-cwd consumers on the gateway fallback.
  • The patch's implementation targets have moved: /handoff is now in hermes_cli/cli_commands_mixin.py:518, and the Codex spawn is in agent/codex_runtime.py:342-345.

Suggested changes

  • Rework the salvage around sessions.cwd, propagate it through the gateway session-context path, and add an end-to-end handoff-cwd regression rather than only a Codex helper test.

Automated hermes-sweeper review.

@teknium1 teknium1 added sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 13, 2026

@GottZ GottZ left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was generated by AI during triage.

Summary

Two PRs touch the CLI-to-gateway handoff path but address distinct causes: #27326 preserves the originating workspace for Codex after handoff, while #65505 carries an explicit Discord initiator into newly created handoff threads. Neither current diff is merge-ready because each introduces or reuses the wrong persistence path for its data.

Related pull requests

  • #27326 related — (+138/-15) — keep open and rework: The diff captures the CLI cwd and propagates it to the Codex app-server, addressing the reported wrong-workspace failure, but it creates a competing handoff_cwd alongside the existing sessions.cwd and updates only agent.session_cwd, leaving gateway context-file and other runtime-cwd consumers on fallback resolution. This agrees with the keep_open review on #27326: salvage the fix by using sessions.cwd and propagating it through the current gateway cwd-resolution path.
  • #65505 related — (+199/-10) — keep open and rework separately: The diff adds the missing Discord initiator argument and inserts that member into both direct and fallback-created threads, but transports the value through durable sessions.user_id; this can overwrite ownership metadata and clear it for existing no-ID handoff callers. This agrees with the keep_open review on #65505: use a handoff-specific initiator field and add preservation coverage for both explicit-ID and no-ID paths.

Suggested consolidation

Do not merge or deduplicate these PRs as-is: rework #27326 around the canonical sessions.cwd and complete gateway cwd propagation, and keep #65505 separate because it fixes Discord thread membership rather than cwd restoration. After their respective blocking review concerns are resolved, they can be evaluated independently; neither PR should be closed as a duplicate of the other.

Cross-PR triage: Reviewed 2 pull requests and 0 issues in this complex. Each diff was read against this issue; Assessment working set: 32 kB of PR diffs, 3 kB of issue/PR text, 3 kB of discussion (4 comments), 0 verify verdicts. verdicts reflect diff content, not PR titles. Part of an automated triage batch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/cli CLI entry point, hermes_cli/, setup wizard comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants