Repository navigation
acp: token streaming, docker project mount, replay status, leak fixes - #633
Merged
Merged
Conversation
… no threadvar leak - Docker backend: a session's project outside the workspace is now mounted in that session's container, at the same path. `pasclaw acp` runs shell_exec with -w set to the editor's project, and unmounted every command there failed in the container. The ACP host records the project per session (new SetShellSessionDir in PasClaw.Shell.Backend); BuildRunArgv adds it when it is outside the workspace and exists. POSIX only, like the worktree mount. Reopening a session in another project stops its container so the next command starts one with that project. - Replay: session/load announces each tool call with the status it ended with, so a refused call is no longer shown completed and then failed. A call with no recorded result (its turn ended first) replays as failed with the same note it got live. - Background jobs clear their thread's shell session id before the thread ends: Delphi does not finalize a string threadvar at thread exit, so it leaked one string per job. Not observable under FPC, which does. Tests: acp_tests (replay statuses), shell_backend_tests (the mount, only for that session, not for a project under the workspace or a missing directory), acp_e2e_test (the fake docker CLI's run line carries the project). Each was reverted to confirm a test fails without it; the threadvar change cannot be checked under FPC. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01KYD1zZPD7GuM8pF1btwi2U
The directory is named by pid and was never removed, so a later run
that got the same pid found an earlier run's archives in backups/ and
the rotation check failed ("10 pruned"). It failed once in a full
`make test` today; 49 such directories had piled up in /tmp.
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. |
…s, ACP An editor under `pasclaw acp` now shows the model's reply as it is written instead of once per round. - PasClaw.Providers.Stream: TSSEParseStream parses SSE as the bytes are written into it. Both HTTP backends write a response into the stream they are given as it arrives, so events fire as the model produces them; the old parser read the whole buffered body after the request had finished, which made every "stream" arrive at once. All parse state is per request. PostStreaming (Anthropic) runs on it too. Indy's error body (E.ErrorMessage) is now the transport's ErrMsg. - PasClaw.Providers.OpenAI: ChatStream really streams (it used to call Chat and hand the whole reply over as one chunk). Same request as Chat plus stream and stream_options.include_usage; text pieces passed on as they arrive; tool calls put together from their id/name and argument fragments; finish_reason; usage with cached tokens; an error sent inside the stream fails the turn. A server that refuses the streaming fields (a 400/422 naming them) is asked again without them, and one that ignores `stream` and answers with one JSON body is read as Chat would. SupportsStreaming is now True. This also makes the gateway's streamed /v1/responses path stream for these providers, and it no longer streams a failed call's error text as output. - Tool loop: TToolLoopConfig.OnTextDelta. When set and the provider streams, a round's first request goes through ChatStream and each piece is passed on as it comes, its first piece marked. That round is not passed to OnText as well, unless it ended with other text (a retry or fallback answered), which then goes to OnText as before. Retries and fallbacks are not streamed. Unset, nothing changes. - ACP: TACPTurn.TextDelta sends each piece as an agent_message_chunk, with the paragraph break between rounds at a round's first piece. Anthropic stays unstreamed in the loop: its SSE handler keeps state in unit globals and drops thinking blocks, which a tool-using turn with thinking needs back. Gemini and the relay do not stream. Tests: streaming_tests (new, make test-streaming) pins the parser fed a byte at a time, a Chat Completions stream put back together, and the loop's OnTextDelta contract. acp_tests pins TextDelta. The e2e fake model now streams chunked SSE: it holds its stream after the first piece until the editor has shown it, which only happens if PasClaw passes text on as it arrives; tool-call arguments in fragments; two rounds as two paragraphs; a server refusing stream_options. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01KYD1zZPD7GuM8pF1btwi2U
ChildObject, ChildArray and ItemObject return wrappers the caller owns. The ACP layer read params, the editor's answers, prompt blocks, MCP server entries and permission outcomes through them without freeing them, so a long editor session leaked a few small objects per message. Under FPC's heap tracer the ACP unit tests went from 80 unfreed blocks to 6, and none of the 6 comes from these paths (they carry no trace at all). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01KYD1zZPD7GuM8pF1btwi2U
FMXExpress
pushed a commit
that referenced
this pull request
Nov 12, 2026
Anthropic's ChatStream kept its parse state in unit globals, never set StatusCode, dropped every block but text and tool_use, and did not continue a pause_turn. #633 made the tool loop stream whenever a provider says SupportsStreaming -- which Anthropic always did -- so under `pasclaw acp` every Anthropic turn went through it: two sessions streaming at once got each other's text, a reply could be taken for a provider failure (StatusCode left unset) and shown as the error, and in the e2e run a tool call and a pause_turn were lost. ChatStream now reads the stream with a TAnthropicStreamAcc, one per call: - text pieces passed on as they arrive, text blocks (and pause_turn rounds) joined with a line break as Chat joins them; - tool calls from content_block_start's id/name and input_json_delta fragments, the input re-serialised as Chat reports it; - thinking (with its signature), citations, server_tool_use and server tool result blocks kept block for block, so a pause_turn is continued by re-sending the round's content exactly as Anthropic sent it, as Chat does from the JSON body (up to the same cap); - usage from message_start and message_delta (input, output, cache read and creation), summed across rounds; - StatusCode set; a non-2xx reply is the error with the server's body; an `error` event inside a 200 stream fails the turn, overloaded_error as 529 so the loop retries it like any 5xx; - a reply with no events (something in between answered with one JSON body) read as Chat would. Thinking is kept but not shown, as Chat drops it from the text. PostStreaming and its plain-procedure callback had no other users and are gone; PostSSE is the one streaming POST. ContinuePausedTurn shares AppendAssistantContent with the streamed continuation. Tests: streaming_tests pins ParseAnthropicStream (text blocks, thinking and signature, citations, a tool call from fragments, usage, the content array for a continuation, an error event). acp_e2e_test gains a fake Messages API: text shown while the model is still writing, a tool call from fragments, a pause_turn continuation re-sending the server-tool blocks as they came, an overloaded error event, and two sessions streaming at once, piece by piece interleaved, each getting only its own text. Against the old code 6 of those 12 checks fail. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01KYD1zZPD7GuM8pF1btwi2U
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.
ACP follow-ups after the pre-release check, plus token-by-token streaming.
Token streaming
An editor under
pasclaw acpnow shows the model's reply as it is written, not once per model round.PasClaw.Providers.Stream). The old SSE parser read the whole buffered response after the request had finished, so every "stream" arrived at once.TSSEParseStreamparses SSE as bytes are written into it, and both HTTP backends (Indy, and System.Net on Delphi) write into it as data arrives. Events fire as the model produces them.PostStreamingruns on it too.E.ErrorMessage) is now passed through as the error text.ChatStreamused to callChatand hand over the whole reply as one chunk. This covers OpenAI, OpenRouter, Groq, DeepSeek, Mistral, Ollama, LM Studio, vLLM and the rest of theopenaikind.Chat, plusstreamandstream_options.include_usage.streamand answers with a single JSON body is read the wayChatreads it.SupportsStreamingis nowTrue. This also makes the gateway's streamed/v1/responsespath stream for these providers, and it no longer streams a failed call's error text as output.TToolLoopConfig.OnTextDelta). When it's set and the provider streams, each round's first request goes throughChatStream, and every text piece is passed on as it comes, with the round's first piece marked.OnTextas well, unless it ended with different text (a retry or fallback answered), which then goes toOnTextas before.OnTextDeltaisn't set, nothing changes.TACPTurn.TextDeltasends each piece as anagent_message_chunk, with the paragraph break between rounds at a round's first piece.Not streamed yet: Anthropic, Gemini and the relay provider, whose text still arrives once per round. Anthropic's SSE handler keeps its state in unit globals and drops thinking blocks, which a tool-using turn with thinking needs passed back, so the loop doesn't use it.
docs/acp.mdsays which providers stream.Docker, replay, leaks
pasclaw acprunsshell_execwith-wset to the editor's project, but the container only mounted PasClaw's workspace, so every command in a project outside it failed.SetShellSessionDirinPasClaw.Shell.Backend).BuildRunArgvmounts it in that session's container at the same path, when it's outside the workspace and exists.session/loadannounces each tool call with the status it ended with. A call with no recorded result replays as failed, with the same note it got live.ChildObject,ChildArrayandItemObjectwrappers without freeing them, so a long editor session leaked a few small objects per message. Under FPC's heap tracer the ACP unit tests went from 80 unfreed blocks to 6, and none of the remaining 6 comes from these paths.backup_testsnamed its temp directory by PID and never removed it, so a reused PID inherited an earlier run's archives and the rotation check failed. It now starts from an empty directory and removes it after a pass.Tests
make test-streaming(new):nullcontent, finish reason, usage with cached tokens, an error inside the stream;OnTextDeltacontract: a streamed round, no delta callback, a provider that doesn't stream, a mismatch, text after what was streamed, two rounds.make test-acp:TextDeltapieces go out one chunk each, with a paragraph per new round; replay statuses.make test-shell-backend: the project mount.make test-acp-e2e:stream_options, and the Dockerrunline carrying the project mount.make testpasses on FPC 3.2.2. Delphi (dcc64) isn't available here.Still not supported
Images and audio in prompts (
TMessagecarries text only), and the editor's file system and terminals (the file and shell tools don't go through the editor).🤖 Generated with Claude Code
https://claude.ai/code/session_01KYD1zZPD7GuM8pF1btwi2U