Skip to content

acp: keep each session's shell session on its own threads and jobs - #632

Merged
FMXExpress merged 1 commit into
mainfrom
claude/pasclaw-desktop-plan-uapzcp
Nov 12, 2026
Merged

FMXExpress merged 1 commit into
mainfrom
claude/pasclaw-desktop-plan-uapzcp

Conversation

@FMXExpress

Copy link
Copy Markdown
Owner

Fixes the Codex P1 comment on #631: background tool execution lost, or borrowed, the shell session of the turn that started it.

The bug

In #631 the ACP host set the shell backend's session id as one process-wide value for the length of a turn, and cleared it afterwards. A background job the turn started (spawn_background, shell_background) reads that id later, on its own thread, and the turn lock didn't cover jobs:

  • After the turn had answered, the id was empty, so the docker backend refused the job's commands.
  • If another session's turn had started in the meantime, the id belonged to that session, so the job's commands ran in the other session's container.

The fix

The shell session id is now per thread, the same way the sandbox workspace already is.

  • PasClaw.Shell.Backend. New SetThreadShellSessionId. GetCurrentSessionId returns the thread's id when one is set, otherwise the process-wide value. Every other surface still sets the process-wide value exactly as before.
  • TToolLoopConfig.ShellSessionId. Applied around each dispatch, as Workspace is, so parallel workers get it too.
  • Background jobs. spawn_background and shell_background capture the spawning thread's session id and run the job under it.
  • The job's workspace. A background job's loop also gets the parent's thread workspace. With an empty value it fell back to the process-wide workspace, so a job started from an editor turn worked in PasClaw's workspace instead of the editor's project. Same root cause.
  • spawn. A synchronous child's parallel workers get the parent's session id and workspace the same way.
  • The ACP host. It sets the id on the turn's thread and in the loop config, and the turn lock is gone: sessions run their turns side by side, each in its own container.

Tests

  • make test-worktree:
    • a thread's id wins over the process-wide one, and other threads never see it
    • the dispatch sets and restores Cfg.ShellSessionId
    • a spawned child's parallel workers run in the parent's session and workspace (the test asserts the calls really ran on worker threads)
  • make test-acp-e2e, with a fake docker CLI:
    • two sessions' turns held in flight together; each shell command lands in its own session's container
    • a background sub-agent whose first model round waits until the spawning turn has answered; its shell command still runs in that session's container and in the editor's project
  • Revert checks. Each of the 7 parts was reverted, and a test failed every time. Without the job propagation, the sub-agent's command never runs, which is the Codex scenario.
  • Full make test passes on FPC 3.2.2. Delphi (dcc64) isn't available here.

Generated by Claude Code

Codex on #631: the ACP host set the shell backend's session id as a
process-wide value for the length of a turn and cleared it after. A
background job the turn started (spawn_background, shell_background)
reads that id later, from its own thread: after the turn it was gone,
so the docker backend refused the job's commands, and if another
session's turn had started it pointed at that session's container. The
turn lock did not cover jobs, which run their own tool loop.

The shell session id is now per thread, like the sandbox workspace:
- PasClaw.Shell.Backend: SetThreadShellSessionId; GetCurrentSessionId
  prefers it over the process-wide value, which every other surface
  still sets as before.
- TToolLoopConfig.ShellSessionId, applied around each dispatch as
  Workspace is, so parallel workers see it too.
- spawn_background and shell_background capture the spawning thread's
  session id and run the job under it. The job's loop also gets the
  parent's thread workspace: with '' it fell back to the process-wide
  one, so a job started from an editor turn worked in PasClaw's
  workspace instead of the editor's project. spawn does the same for
  its child's parallel workers.
- The ACP host sets both on the turn's thread and in the loop config,
  and drops the turn lock: sessions now run their turns side by side,
  each in its own container.

Tests: worktree_tests pins the thread override, the dispatch bracket and
a spawned child's parallel workers getting the parent's session and
workspace. acp_e2e_test (fake docker CLI) runs two sessions' turns at
once and checks each command's container, and a background subagent
whose shell command runs after its turn has answered, in that session's
container and the project. Each part was reverted to confirm a test
fails without it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KYD1zZPD7GuM8pF1btwi2U
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-12T21:55:09.436909Z df1fc78 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@FMXExpress
FMXExpress merged commit 0966f31 into main Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants