Skip to content

acp: fix the PR #630 review findings - #631

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 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)

  • Provider failures. A provider that cannot answer (bad key, rate limit, no connection) is now the prompt's JSON-RPC error, carrying the provider's message. The tool loop returns a failure as Content with a non-2xx status. Before this fix it was sent as end_turn with no text, and the error text was saved as the assistant's reply. ProviderRefused moves from the gateway into PasClaw.Tools.ToolLoop so both surfaces use one check.
  • Modes after the first turn. session/set_mode now 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 new RetargetModeSection (PasClaw.Agent.Prompt) swaps the mode directive. The REPL's /mode had the same bug and now uses it too.
  • The editor's project builds the prompt. The project is the thread's workspace for the whole turn, not only during tool dispatches. The system prompt is built for it: the workspace section, the project's AGENTS.md and its instruction files (Codex comment).
  • Docker backend. Each turn sets the shell backend's session id; with an empty id the backend refused every command. Turns run one at a time when the backend keeps per-session state. Containers are already stopped at exit by the backend, and a reloaded session keeps its container.
  • Editor MCP servers. These connect through the new 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.
  • Session location. The session records the editor's project as its location, so pasclaw resume <id> works there. A session reopened from another project records that project.
  • Profiles. session/load refuses a session created under a different profile, unless --profile or $PASCLAW_PROFILE chose this process's profile. The error names the command that opens it. Without this, a security session 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)

  • Output shortened for display, tool titles, and replayed results stay valid UTF-8. Utf8SafeTruncate moves to PasClaw.Utils and doesn't split surrogate pairs on Delphi.
  • Calls a turn announced but never finished are shown as failed before the turn answers. They no longer capture a later call's result with the same tool name.
  • Each tool call's arguments are parsed once instead of about a dozen times.
  • Request ids come from the new JsonIdLiteral (PasClaw.JSON), which the MCP server now shares. A null id is echoed as null. The Delphi branch checks TJSONNumber before TJSONString, 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:
    • plan and improve mode reach the system prompt after the first turn
    • the project's AGENTS.md is in the prompt
    • a provider 401 becomes a JSON-RPC error, and neither the error nor the unanswered prompt is saved
    • Location is recorded, including on reopening from another project
    • profile refusal and the matching --profile open
    • --max-iterations 8 stops at 8 rounds
    • code_catalog lists the editor server's tools
    • a fake docker CLI: commands run in the session's container, a reload keeps it, and it is stopped at exit
  • The cancel test now waits for the model call to arrive instead of sleeping 0.5 s.
  • Each behavior fix was reverted to confirm a test fails without it (14 revert checks, all caught).
  • Full make test passes with FPC 3.2.2. Delphi (dcc64) is not available here, so the Delphi branches of JsonIdLiteral and Utf8SafeTruncate are not compiled.

Generated by Claude Code

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
@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:07:05.695356Z a751ea4 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 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".

Comment on lines +2450 to +2451
SetCurrentSessionId('');
FTurnLock.Leave;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

@FMXExpress
FMXExpress merged commit f3857ce into main Nov 12, 2026
FMXExpress pushed a commit that referenced this pull request Nov 12, 2026
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
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