Repository navigation
acp: keep each session's shell session on its own threads and jobs - #632
Merged
Merged
Conversation
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
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:The fix
The shell session id is now per thread, the same way the sandbox workspace already is.
PasClaw.Shell.Backend. NewSetThreadShellSessionId.GetCurrentSessionIdreturns 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, asWorkspaceis, so parallel workers get it too.spawn_backgroundandshell_backgroundcapture the spawning thread's session id and run the job under it.spawn. A synchronous child's parallel workers get the parent's session id and workspace the same way.Tests
make test-worktree:Cfg.ShellSessionIdmake test-acp-e2e, with a fakedockerCLI:make testpasses on FPC 3.2.2. Delphi (dcc64) isn't available here.Generated by Claude Code