Skip to content

perf(runtime): overlap leading reads in mixed turns; soften the 16-call cap (C5) - #62

Merged
lg2m merged 1 commit into
perf/context-usability-4-cache-breakpointsfrom
perf/context-usability-5-parallel-reads
Sep 17, 2026
Merged

lg2m merged 1 commit into
perf/context-usability-4-cache-breakpointsfrom
perf/context-usability-5-parallel-reads

Conversation

@lg2m

@lg2m lg2m commented Sep 17, 2026

Copy link
Copy Markdown
Collaborator

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

  • A turn like read, read, read, edit, read now 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.
  • A turn that names more than 16 tool calls no longer fails the run. Calls 17+ return not executed: this turn requested more than 16 tool calls and only the first 16 ran; call this again next turn as tool errors; the run continues. Naming more than 64 calls in one turn is still a provider-protocol failure.
  • The system prompt (version 14) tells the model to batch independent read_file/search/tree calls and states the 16-call cap.

What changed

  • lib.rs tool phase: take_while(overlappable) splits approved; the prefix goes through the existing buffer_unordered(MAX_PARALLEL_READS) path, the remainder through the existing sequential path. Overlappable = ToolClass::ReadOnly and not a spend-bounded spawn_agent, exactly the prior all-or-nothing predicate.
  • MAX_ADMITTED_TOOL_CALLS_PER_TURN = 64; over-cap calls get their rejection at ToolCallStarted, 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_VERSION 13 → 14. plan.rs golden 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 --workspace green; fmt; strict all-target clippy.
  • New: 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 see before, trailing read sees after, 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_while per turn on ≤ 64 calls; execution paths are the pre-existing ones.

Docs

docs/design/tools.md § Loop Bounds, § Within a turn; ledger.

…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
lg2m merged commit d595eee into perf/context-usability-4-cache-breakpoints Sep 17, 2026
4 checks passed
@lg2m
lg2m deleted the perf/context-usability-5-parallel-reads branch September 17, 2026 01:49
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.
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.

1 participant