Refactor session ownership, turn cancellation, and tool execution - #198
Merged
Merged
Conversation
The runtime hands its persistence the nodes and journal entries that changed since the last checkpoint instead of a full copy of the session. Conversation tracks edited nodes, ToolJournal tracks recorded entries, and the session store merges the delta by id. This removes the per-checkpoint JSON round-trip of every tool result, the dead linear-history copy, and the metadata-notifying persistence wrapper: the manager publishes the session metadata itself after the merge.
Read-only tools no longer write a started record before running; a missing record means the call did not happen and repeating it is harmless. The batch-wide not-started records are gone for the same reason. A completion is committed with one checkpoint that also carries what the hooks derived from it.
…d tokens The runtime races its own token against the permission check; the mediator and ToolPermissions no longer carry a copy of it, and the mediator's guard settles a dropped prompt. Sub-agents get a child token that is cancelled with the parent run, which replaces the propagation task and the double select.
…terruption The dispatcher spawns one task per lane that runs its commands in arrival order and plain tasks for read-only queries; the select loop with its queue map and join set is gone, and so is the block_on-inside- spawn_blocking detour. Run preparation is still abandoned on stop, but the commit under the manager lock now runs to completion.
…ings clear_context wiped the in-memory conversation without persisting it, and the next message reloaded the session from disk, so the history came back. History must never be lost anyway: /clear now creates a new session that inherits project, worktree, model, sandbox policy and permission tier, and the terminal switches to it.
MockLLMProvider can replay its responses through the streaming callback and hand out a client factory; PendingLLMProvider replaces the three never-answering stubs. The scripted, waiting, failing and two-call providers the new tests had defined for themselves are gone, and the test modules read like the rest of the code base.
…eeds message_contains_invocation existed only for the history normalization that deleted dangling tool calls on load; restores keep them now.
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.
Summary
Implements three incremental architecture improvements, with regression tests written and run red before the corresponding fixes.
1. Session state ownership and canonical conversation
2. Turn lifecycle and cancellation
3. Tool execution and recovery
{}).Review order
4bb7282c— canonical conversation and session-owned checkpoint boundariesca6b02e6— run preparation, command lanes, and cancellation9ff102f8— shared tool pipeline and individual outcome journalaecda236— empty JSON input streaming fix35916ad3— sub-agent finalization, cleanup, and cancellation propagationValidation
Locally verified on macOS, without the document-conversion feature:
tools_core,agent_core,code_assistant_core, andmcp_client.-D warnings: passed.git diff --check: passed.Commands:
cargo test --locked --offline --no-default-features -p tools_core -p agent_core -p code_assistant_core -p mcp_client --lib -- --test-threads=1 cargo clippy --locked --offline --no-default-features -p tools_core -p agent_core -p code_assistant_core -p mcp_client --all-targets -- -D warnings cargo check --locked --offline -p code-assistant --no-default-features --features gpui-frontend,acp-frontend,terminal-frontend,mcp-server --tests cargo fmt --all -- --check git diff --checkScope and limitations
read-only/outwardclassification semantics are unchanged.