Repository navigation
acp: fix the PR #630 review findings - #631
Conversation
Fixes the code review of `pasclaw acp` (#630) and two Codex review comments on it. The host (PasClaw.Cmd.Agent): - A provider that cannot answer is now the prompt's JSON-RPC error, with the provider's message. The tool loop hands a failure back as Content with a non-2xx status; it was sent as end_turn with no text and saved as the assistant's reply. ProviderRefused moves from the gateway into PasClaw.Tools.ToolLoop so both use the same check. - session/set_mode reaches the system prompt after the first turn. The kept prompt (it can carry a compaction summary) was reused whole, so the gate changed and the model was not told. New RetargetModeSection (PasClaw.Agent.Prompt) swaps the mode directive; the REPL's /mode had the same bug and uses it too. - The editor's project is the thread's workspace for the whole turn, so the system prompt is built for it (its AGENTS.md, instruction files, workspace section), not only the tool dispatches. - The docker shell backend works: each turn sets the backend's session id (it refused every command with an empty one), and turns run one at a time when the backend keeps per-session state. Containers already stop at exit (the backend reaps the ones it started); a reloaded session keeps its container. - Editor-supplied MCP servers connect through the new ConnectMCPServerList (PasClaw.MCP.Bridge) instead of swapping the shared config's server list while other sessions' turns read it, and without re-registering tool_search's disclosure from the editor's servers alone. - The session records the editor's project as its location, so `pasclaw resume <id>` works there. - session/load refuses a session created under another profile unless --profile or $PASCLAW_PROFILE chose this one, naming the command that opens it, so a `security` session is not run without its sandbox. - An explicit --max-iterations is kept, 8 included (it became 50). The protocol layer (PasClaw.ACP): - Output cut for display, titles and replayed results stay valid UTF-8 (Utf8SafeTruncate moves to PasClaw.Utils, surrogate-safe on Delphi). - Calls a turn announced but never finished are shown failed before the turn answers, and no longer take a later same-named result. - Each tool call's arguments are parsed once, not about a dozen times. - Ids come from the new JsonIdLiteral (PasClaw.JSON), shared with the MCP server; a null id is echoed as null. Its Delphi branch tests TJSONNumber before TJSONString (the former descends from the latter). Tests: unit tests for open calls, the UTF-8 cut, null ids and RetargetModeSection; e2e checks for each host fix (a fake docker CLI for the backend), an event-driven cancel instead of a 0.5 s sleep, and the unit test's scratch directory is removed. Each behavior fix 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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a751ea4e76
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| SetCurrentSessionId(''); | ||
| FTurnLock.Leave; |
There was a problem hiding this comment.
Preserve the originating session ID for background tool execution
With the Docker backend, an ACP turn can launch spawn_background and finish while the child is still running. Clearing the process-wide session ID here makes the child's subsequent shell calls fail with Docker's empty-session refusal; if another session starts a turn first, those calls instead execute in that other session's container. The turn lock does not protect background workers: TBgJob.Execute runs its own tool loop, and shell tools read GetCurrentSessionId at execution time (as does TBgJob.RunShellJob). Capture and propagate the originating session ID to background jobs rather than relying on a global value scoped only to the foreground turn.
Useful? React with 👍 / 👎.
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
Fixes the code review of
pasclaw acp(#630), plus two Codex review comments on it: the provider failure and the system prompt's workspace.The host (
PasClaw.Cmd.Agent)Contentwith a non-2xx status. Before this fix it was sent asend_turnwith no text, and the error text was saved as the assistant's reply.ProviderRefusedmoves from the gateway intoPasClaw.Tools.ToolLoopso both surfaces use one check.session/set_modenow reaches the system prompt. The kept prompt, which can carry a compaction summary, was reused whole, so the permission gate changed but the model was never told. The newRetargetModeSection(PasClaw.Agent.Prompt) swaps the mode directive. The REPL's/modehad the same bug and now uses it too.AGENTS.mdand its instruction files (Codex comment).ConnectMCPServerList(PasClaw.MCP.Bridge). The old code swapped the shared config's server list while other sessions' turns were reading it, and re-registered tool_search's disclosure list from the editor's servers alone.pasclaw resume <id>works there. A session reopened from another project records that project.session/loadrefuses a session created under a different profile, unless--profileor$PASCLAW_PROFILEchose this process's profile. The error names the command that opens it. Without this, asecuritysession could be opened without its sandbox.--max-iterations. An explicit value is kept, including 8. Before, 8 was indistinguishable from the default and became 50.The protocol layer (
PasClaw.ACP)Utf8SafeTruncatemoves toPasClaw.Utilsand doesn't split surrogate pairs on Delphi.JsonIdLiteral(PasClaw.JSON), which the MCP server now shares. A null id is echoed as null. The Delphi branch checksTJSONNumberbeforeTJSONString, because the former descends from the latter.Tests
make test-acp: new tests for calls left open, the UTF-8 cut at the 32 KiB boundary, null ids, and removal of the scratch directory.make test-plan-build-mode:RetargetModeSection, covering plan→improve→build, idempotence, a built prompt equal to the retargeted one for each mode, and a compaction summary kept.make test-acp-e2e, new checks:AGENTS.mdis in the prompt--profileopen--max-iterations 8stops at 8 roundscode_cataloglists the editor server's toolsdockerCLI: commands run in the session's container, a reload keeps it, and it is stopped at exitmake testpasses with FPC 3.2.2. Delphi (dcc64) is not available here, so the Delphi branches ofJsonIdLiteralandUtf8SafeTruncateare not compiled.Generated by Claude Code