Repository navigation
refactor(subagents): run the subagent loop on the shared turn engine - #2113
Merged
Merged
Conversation
runSubagentConversation's while(true) loop becomes a TurnEngineAdapter. Progress events, the live session view, usage reporting, the transcript, token estimates and per-call execution move into adapter hooks unchanged. Subagents keep today's behaviour through a new TurnEnginePolicy: no text tool-call parsing, no empty/truncated/repeated engine guards, no turn ceiling, and content-only replies returned rather than recorded (so the final turn is not compacted). Their own repeated-call check runs in the new onToolCallsEmitted hook, before the turn is recorded, as before; the session view update runs in onTurnRecorded, after compaction. prepareTurn may now be async for the 50ms render yield, and an abort that surfaces as a thrown model call carries that error. The contract spec now runs every scenario through subagents too, asserting what they do where they run without the guards. It passes against the old loop and the new one. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Contributor
No changeset foundThis PR does not add a changeset, so it will not appear in the changelog or trigger a release. If the change is user-facing, add one: pnpm changesetPick a bump (patch / minor / major) and write the changelog entry in our usual voice ("Added X... Thanks to @you. Closes #123."), then commit the generated If this PR is docs-only or a chore that needs no release note, you can ignore this — or run |
Contributor
|
nc-review could not produce a verdict this run (agent exit |
This was referenced Nov 11, 2026
jay23606
added a commit
to jay23606/nanocoder
that referenced
this pull request
Nov 12, 2026
…ano-Collective#2113) runSubagentConversation's while(true) loop becomes a TurnEngineAdapter. Progress events, the live session view, usage reporting, the transcript, token estimates and per-call execution move into adapter hooks unchanged. Subagents keep today's behaviour through a new TurnEnginePolicy: no text tool-call parsing, no empty/truncated/repeated engine guards, no turn ceiling, and content-only replies returned rather than recorded (so the final turn is not compacted). Their own repeated-call check runs in the new onToolCallsEmitted hook, before the turn is recorded, as before; the session view update runs in onTurnRecorded, after compaction. prepareTurn may now be async for the 50ms render yield, and an abort that surfaces as a thrown model call carries that error. The contract spec now runs every scenario through subagents too, asserting what they do where they run without the guards. It passes against the old loop and the new one. Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
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.
Step 3 of moving the agent loops onto the shared turn engine (#2097 plain, #2102 ACP).
runSubagentConversation'swhile (true)loop now runs onrunTurnEngine. Subagents keep their current behaviour: the engine features they did not have are switched off through a new policy object. Turning the guards on is a separate follow-up with a changeset.Engine additions
TurnEnginePolicy(every flag defaults to on, so plain and ACP do not change):parseTextToolCalls,emptyTurnGuard,truncatedTurnGuard,repeatedToolCallGuard, andrecordToolFreeTurns. WhenrecordToolFreeTurnsis off, a turn with no tool calls is returned and not recorded, so the final turn is never compacted.onToolCallsEmitted(toolCalls): runs before the turn is recorded. Subagents run their own repeated-call check and argument token estimate here, at the same point as before. That point comes before the assistant message is recorded and before compaction.onTurnRecorded(): runs after the assistant message is recorded and compaction has run, before the abort check. Subagents reset streaming and update the live session view here.prepareTurnmay be async, for the subagent's 50ms render yield. An abort that shows up as a thrown model call now carries that error (aborted.error), so a subagent rethrows what the client threw, as it did before. The abort check after compaction now sits inside the recorded-turn block. For plain and ACP every turn is recorded, so nothing changes for them.Subagent adapter
Each part of the old loop moved into an adapter hook unchanged:
iterations++, therunningprogress event, the 50ms yield, capturing provider and modelprepareTurnbeginModelCallonApiCallCompleteusage and the assistant transcriptonModelResponseexecuteToolCallrefuses tools the subagent can't use with its own message)partitionToolCallsSubagentLoopStopError(same message and partial output), and the token estimate for argumentsonToolCallsEmittedexecuteToolCall, and the incremental session-view updateexecuteToolsThe policy turns off text parsing, the empty and truncated guards, the engine's repeated guard and the turn ceiling (
maxTurns: Infinity). It also stops content-only turns from being recorded. How a run ends:completedandno-responseemitcompleteand return the answer, or''for no reply. An abort emitserrorand throwsAborted, or rethrows the client's error. A model error is rethrown. The remaining result kinds can't happen under this policy and throw.Ignoring whitespace,
subagent-executor.tsis +190/−100. The rest of the raw diff is re-indentation into the adapter.Behaviour
No change intended. The contract spec now runs every scenario through subagents as well. Where they don't have the guards, it asserts what they do instead: an empty, malformed or truncated reply is the answer; an unknown tool gets the subagent's own "not available" result; there is no turn ceiling. The extended contract spec passes against the old
subagent-executor.tsfrom main and against the new one.Tests
turn-engine.contract.spec.ts: plain, ACP and subagent runners (30 scenarios).turn-engine.spec.ts: new tests for each policy flag, the order of the two new hooks, and a throw from a hook. The existing abort test now also asserts the carried error.tsc --noEmit,biome check,knip(both passes), and AVA oversource/agent-loop,source/plain,source/acp,source/subagents(590) andsource/hooks(513), plustools/agent-toolandno-ink-fast-paths. All passed after merging the latest main.No changeset: this is a refactor with no user-visible change.
Next in the sequence
guarded: falseexceptions.🤖 Generated with Claude Code