Skip to content

feat(turn): run read-only tool-call batches sequentially in one step - #494

Merged
ajianaz merged 2 commits into
developfrom
feat/sequential-tool-batches
Nov 3, 2026
Merged

ajianaz merged 2 commits into
developfrom
feat/sequential-tool-batches

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

What (description of the change)

A response's tool calls now run as a sequential batch in one model step when every call is a registered ReadOnly tool; any non-ReadOnly or unknown call keeps the old first-call-only behavior for that response. Each call runs in model order as its own effect sandwich with its own ReplaySafety — this is not concurrent execution. Provider-side, ProviderOutput is unchanged; a new defaulted Provider::last_extra_tool_calls() carries the calls after the first (OpenAiProvider fills it in both modes, Box<P> and FailoverProvider forward; the list stops at the first malformed extra). On the wire, the 2nd..Nth intents carry a "batch": true marker (machine::begin_batch_member) and the transcript flattening merges them into one assistant tool_calls array with results in call order; unmarked intents flatten exactly as before. Batch members are checked by the loop guard and gate::authorize individually; a failed call stops the batch and the remaining calls are recorded as intents settled with "not executed: an earlier call in this batch failed" (every tool_call has a result). Docs: docs/prd.md non-goal now reads "no concurrent execution; sequential batches supported", docs/architecture.md matching line updated, and docs/tool-batches.md records the design note. CHANGELOG under [Unreleased].

Why (the problem you're solving)

Closes #480. The fleet model emits parallel tool calls routinely (measured in the issue: 22 emitted / 11 dropped / all 11 re-asked; the first response's extra calls alone accounted for 43% of requests and ~32% of wall time). Owner decision 3 Nov 2026: revisit the non-goal with the SEQUENTIAL batch option, v1 restricted to all-ReadOnly batches, no ProviderOutput shape change.

Testing (how you verified this works)

  • RED first: tests/tool_batches.rs with stubs — 3 passed / 5 failed (the read-only batch ran only [1] instead of [1,2,3]; the step-budget test counted 31 intents instead of 93). The two early passes were the fallback and crash-resume guards, which exist before the feature.
  • GREEN: 8/8 — read-only batch runs [1,2,3] in one step; mixed batch falls back to [1] only; a failing call stops the batch with stub results for the rest; step budget counts one step for a 93-call batch; loop guard, cancel mid-batch, crash mid-batch (at most one pending intent, replayed as before, unstarted calls re-asked after resume) all pinned.
  • cargo fmt --all -- --check, cargo clippy --workspace --all-targets -- -D warnings, cargo test --workspace --no-fail-fast (944 passed / 0 failed, 52 suites — verified independently on a second full run), cargo test -p tole-core --no-default-features (373 passed / 0 failed), cargo build -p tole-cli --no-default-features: all pass.
  • One workspace flake in the very first full run (943/1, test not captured; two clean re-runs since) — treated as load-related, not proven; nothing was changed for it.
  • Decisions recorded in docs/tool-batches.md: terminal aborts (loop trip, cancel, unknown tool, denial) leave unstarted calls unrecorded (in an all-ReadOnly batch the approver is never consulted, so mid-batch denial is effectively unreachable); observers see one tool_started/finished pair per executed call in order; the poll-tool step refund applies only to the batch's first call; the cache prefix stays append-only.
  • UNVERIFIED: a live-model mission against glm-5.1 (the round-trip saving is the issue's measurement, not re-confirmed here); local cora pre-commit hit its timeout with no verdict — the CI Cora Review job is the check (if it times out on the ~860-line diff, chunked review per the v0.9.0 precedent).

@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

Owner decision (3 Nov 2026): revisit the no-parallel non-goal with the sequential-batch option from #480. A response whose tool calls are all ReadOnly runs them in model order, each as its own sandwich, inside one step; any other batch keeps first-call-only. See docs/tool-batches.md.
@ajianaz
ajianaz force-pushed the feat/sequential-tool-batches branch from ba32f0c to 996ceb1 Compare November 3, 2026 09:00
Comment thread CHANGELOG.md Outdated
- Interruptible provider calls (#484): a cancel (Esc, `--timeout`, ACP `session/cancel`, serve cancel) now interrupts a provider call already in flight instead of waiting for the provider to answer or the 120 s HTTP timeout. New additive `Provider::complete_with_cancel(&mut self, transcript, &CancelToken)` (default delegates to `complete`, so embedders and mocks are unchanged); `OpenAiProvider` runs the request on a helper thread and re-checks the token every 100 ms, `FailoverProvider` and `Box<P>` forward it, and the turn loop calls it. On cancel the thread is abandoned, nothing is committed for the call, and the turn settles as cancelled as before (resumable). A streaming call also stops reading and stays silent on the live sinks. The abandoned request may still be billed by the provider. Measured: `tole run --timeout 1` against a provider silent for 8 s returned after 8.25 s, now about 1 s, in stream and non-stream modes.

### Changed
<<<<<<< HEAD
@ajianaz
ajianaz merged commit ce585fa into develop Nov 3, 2026
16 checks passed
@ajianaz
ajianaz deleted the feat/sequential-tool-batches branch November 3, 2026 09:39
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.

harness: only the first tool call of a response runs — measured cost of the 'no parallel tool calls' non-goal on the real fleet model

2 participants