Repository navigation
perf(runtime): overlap leading reads in mixed turns; soften the 16-call cap (C5) - #62
Merged
lg2m merged 1 commit intoSep 17, 2026
Conversation
…r-turn call cap (C5) A turn with one edit and five reads ran all six in series; a turn naming seventeen calls killed the run with a provider-protocol failure. Every reference harness overlaps read-only calls and none fails a run for batching well. The tool phase now splits the turn at the first call that is not an overlappable read: the leading reads run under MAX_PARALLEL_READS, the rest in request order, so a read after a mutation is still ordered against it. Calls past the sixteenth are admitted with a not-executed tool error that tells the model to re-issue them; a turn naming more than 64 calls remains a protocol failure. Prompt version 14 asks the model to batch independent calls and names the cap.
lg2m
merged commit Sep 17, 2026
d595eee
into
perf/context-usability-4-cache-breakpoints
4 checks passed
lg2m
added a commit
that referenced
this pull request
Sep 17, 2026
…r-turn call cap (C5) (#62) A turn with one edit and five reads ran all six in series; a turn naming seventeen calls killed the run with a provider-protocol failure. Every reference harness overlaps read-only calls and none fails a run for batching well. The tool phase now splits the turn at the first call that is not an overlappable read: the leading reads run under MAX_PARALLEL_READS, the rest in request order, so a read after a mutation is still ordered against it. Calls past the sixteenth are admitted with a not-executed tool error that tells the model to re-issue them; a turn naming more than 64 calls remains a protocol failure. Prompt version 14 asks the model to batch independent calls and names the cap.
lg2m
added a commit
that referenced
this pull request
Sep 17, 2026
…edrock Converse (C4) (#61) * perf(provider): mark prompt-cache breakpoints for Anthropic Messages and Bedrock Converse (C4) Neither codec asked the provider to cache anything, so every turn of a long Anthropic or Bedrock session re-processed the full transcript uncached: time to first token grew linearly with context and input cost was roughly an order of magnitude higher than it needed to be. Both providers require explicit breakpoints. Anthropic Messages now sends the system prompt as one text block with `cache_control: ephemeral`, marks the last tool declaration and the last block of the last message, and leaves everything else unmarked so consecutive turns extend one cached prefix. Bedrock Converse places the equivalent `cachePoint` blocks at the same three positions, gated to the Anthropic model family (regional, global, and inference-profile ids) because Converse rejects the block for families without prompt caching. `ResolvedModel.prompt_cache.control` reports `Native` for both APIs. Wire change: single-text Anthropic messages serialize as block arrays. `provider_encode` anthropic 195 → 204 µs on a 1.1 MiB body. * perf(runtime): overlap leading reads in mixed turns and soften the per-turn call cap (C5) (#62) A turn with one edit and five reads ran all six in series; a turn naming seventeen calls killed the run with a provider-protocol failure. Every reference harness overlaps read-only calls and none fails a run for batching well. The tool phase now splits the turn at the first call that is not an overlappable read: the leading reads run under MAX_PARALLEL_READS, the rest in request order, so a read after a mutation is still ordered against it. Calls past the sixteenth are admitted with a not-executed tool error that tells the model to re-issue them; a turn naming more than 64 calls remains a protocol failure. Prompt version 14 asks the model to batch independent calls and names the cap.
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.
C5: concurrent leading reads in mixed turns; soft per-turn cap; batching guidance
Spec: docs/plans/context-usability.md § C5. Stacked on #61 (C4); review against that base.
User-visible behavior
read, read, read, edit, readnow runs the three leading reads concurrently (4-wide, the existing bound), then the edit, then the trailing read — previously all five ran in series because one call was mutating. Read-only-only and mutation-first turns are unchanged.not executed: this turn requested more than 16 tool calls and only the first 16 ran; call this again next turnas tool errors; the run continues. Naming more than 64 calls in one turn is still a provider-protocol failure.read_file/search/treecalls and states the 16-call cap.What changed
lib.rstool phase:take_while(overlappable)splitsapproved; the prefix goes through the existingbuffer_unordered(MAX_PARALLEL_READS)path, the remainder through the existing sequential path. Overlappable =ToolClass::ReadOnlyand not a spend-boundedspawn_agent, exactly the prior all-or-nothing predicate.MAX_ADMITTED_TOOL_CALLS_PER_TURN = 64; over-cap calls get theirrejectionatToolCallStarted, don't count toward slice/budget tool calls, and settle through the existing rejection path (one result per call, transcript stays provider-valid).runtime/prompt.rs: one new working-conventions line;AGENT_PROMPT_VERSION13 → 14.plan.rsgolden descriptor digest re-pinned (same procedure as feat(tools)!: fetch under a Network effect class with host grants and SSRF pinning, protocol 22 (T9) #50); headless test expects 14.How verified
cargo test --workspacegreen; fmt; strict all-target clippy.calls_past_the_per_turn_cap_settle_as_tool_errors_and_the_run_continues(20 reads → 16 results + 4 typed errors, run completes);a_mixed_turn_overlaps_its_leading_reads_then_runs_the_rest_in_order(leading reads seebefore, trailing read seesafter, results in call order, file edited). The former hard-fail test now exercises the 64 admitted bound.Measurements
None new: the split is one
take_whileper turn on ≤ 64 calls; execution paths are the pre-existing ones.Docs
docs/design/tools.md§ Loop Bounds, § Within a turn; ledger.