Skip to content

prompt: ask the model to batch independent reads, so parallel dispatch fires - #537

Merged
FMXExpress merged 2 commits into
mainfrom
claude/prompt-batch-tool-calls
Aug 14, 2026
Merged

FMXExpress merged 2 commits into
mainfrom
claude/prompt-batch-tool-calls

Conversation

@FMXExpress

Copy link
Copy Markdown
Owner

The gap

PasClaw.Tools.ToolLoop has been able to dispatch a round's read-only calls in parallel for a long time — tcReadOnly calls coalesce into one batch, every mutating call gets a batch of one, order preserved. But a batch only forms when the model emits several tool_use blocks in one response, and nothing in the ~1000-line system prompt ever asked it to. The machinery was built and under-fed: it fired only when the model happened to batch on its own.

No engine change needed. This is the cheapest remaining latency lever precisely because the execution side already exists.

The rule

Rule 7, written in the terms the loop actually honours:

  • emit every read or search whose input doesn't depend on another's output together — read_file, list_dir, grep_files, find_files, memory_search, kb_search run in parallel
  • don't interleave an edit, run_command or web_fetch between them — each mutating call splits the batch
  • keep the dependent half sequential: gather in parallel → make the edit → run one focused check

I checked the batching semantics in ToolLoop before writing it, so the prompt doesn't advertise parallelism for tools that stay serial (shell and web_fetch are tcMutating).

Why there's a test

The rule asserts a category that a different unit owns — the familiar two-owners shape. Flip read_file to tcMutating and the prompt starts advertising parallelism the loop will never deliver, degrading silently into wasted round trips rather than breaking visibly.

test-prompt-batching checks the rule text against the registry: every tool named parallel-safe must be tcReadOnly, every tool named batch-splitting must not be.

I verified the guard actually bites rather than trusting it — flipped read_file to tcMutating, watched the test fail, restored it, watched it pass:

1 prompt batching test(s) FAILED     <- with read_file flipped
all prompt batching tests passed     <- restored

Context

Prompted by a write-up on Bullet, whose headline finding ("model speed matters less than reducing round trips") is this exact lever. Their other four are already implemented here — model routing is PasClaw.Agent.AutoRouter, targeted non-embedding search is the six-tier fs_grep, bounded tool output is OutputCache, and their "most surprising obstacle" (regex-dialect silent misses) is already covered by LooksLikeRegexPattern's next-move hint.

Worth noting their benchmark numbers are self-reported on their own blog; the mechanism is the useful part, not the figure.

Gates

make test-prompt-batching · test-skills-prompt · test-loop-shaping-defaults · test-orient-preamble · make smoke — all green.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LGQKz579j1ZnDRwmr6h1V6


Generated by Claude Code

…h fires

The tool loop has been able to run a round's read-only calls in parallel
for a long time: PasClaw.Tools.ToolLoop coalesces tcReadOnly calls into one
batch and gives every mutating call a batch of one. But a batch only forms
when the MODEL emits several tool_use blocks in a single response, and
nothing in the 1000-line system prompt ever asked it to. The machinery was
built and under-fed -- it fired only when the model happened to batch on
its own.

Rule 7 now asks for it, in the terms the loop actually honours: emit every
read or search whose input does not depend on another's output together
(read_file, list_dir, grep_files, find_files, memory_search, kb_search run
in parallel); do not interleave an edit, run_command or web_fetch between
them, because each mutating call splits the batch; then keep the dependent
half sequential -- gather in parallel, make the edit, run one focused
check. No engine change: this is the cheapest available latency lever
because the execution side already exists.

The rule asserts a CATEGORY that a different unit owns, which is the
familiar two-owners shape -- flip read_file to tcMutating and the prompt
starts advertising parallelism the loop will never deliver, degrading
silently into wasted round trips rather than breaking visibly. So
test-prompt-batching checks the rule text against the registry: every tool
named parallel-safe must be tcReadOnly, every tool named batch-splitting
must not be. Confirmed the guard actually bites by flipping read_file to
tcMutating -- the test fails -- and restoring it.

Prompted by a write-up on Bullet, whose headline finding is this exact
lever. Their other four (model routing, targeted non-embedding search,
bounded tool output, regex-dialect fallbacks) are already implemented here
as AutoRouter, the six-tier fs_grep, OutputCache, and the
LooksLikeRegexPattern hint.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LGQKz579j1ZnDRwmr6h1V6

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 14366c29f4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/pkg/agent/PasClaw.Agent.Prompt.pas Outdated
Comment on lines +696 to +697
'`read_file`, `list_dir`, `grep_files`, `find_files`, `memory_search` ' +
'and `kb_search` calls IN PARALLEL when they arrive together in one ' +

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep memory_search out of parallel batches

When the model batches two independent memory_search calls against a fresh or changed memory directory, these calls are not actually read-only: Tool_MemorySearch invokes IMemoryIndex.SyncDir, and the FTS implementation deletes/inserts rows and commits them. Concurrent connections can therefore contend on .index.db and return a locking/worker error instead of complete search results. Either serialize this tool, make its synchronization concurrency-safe, or omit it from the new batching instruction.

Useful? React with 👍 / 👎.

Comment thread src/pkg/agent/PasClaw.Agent.Prompt.pas Outdated
'another''s output as a single batch rather than one per turn. Three ' +
'files you already know you need is ONE response with three ' +
'`read_file` calls, not three round trips. Anything that changes state ' +
'-- edits, `run_command`, `web_fetch` -- runs serially and SPLITS the ' +

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Name shell_exec as the serial command tool

When an investigation mixes file reads with a shell command, this guidance names the nonexistent run_command tool, while RegisterShellTool exposes the mutating command tool as shell_exec. A model following the rule may either attempt an unavailable tool or fail to recognize that shell_exec splits the read batch, undermining the intended batching behavior; use the registered tool name here.

Useful? React with 👍 / 👎.

#537)

Both findings are legit and both were verified against the code rather
than taken on trust.

1. The rule named `run_command`, which is registered nowhere -- the
   command tool is `shell_exec`. A model told to watch for a phantom tool
   cannot recognise the thing that actually splits its batch, which is
   the half of the rule that keeps reads batched.

2. memory_search is worse than a naming slip. It is registered
   tcReadOnly, so ToolLoop genuinely WILL batch it, but
   Tool_MemorySearch calls IMemoryIndex.SyncDir, which reindexes files
   and deletes rows in .index.db. Two in one batch are two writers on one
   SQLite file. Dropped from the rule, along with kb_search.

Deliberately NOT fixing the category here, and this is the interesting
part: tcReadOnly is overloaded. PasClaw.Tools.PlanWrite documents that it
doubles as the plan-mode dispatch gate -- it labels itself tcReadOnly
despite writing, precisely to pass that gate. So flipping memory_search
to tcMutating would fix the concurrency hazard and simultaneously break
memory_search in plan mode. That is a real latent bug that predates this
PR: the hazard exists today whenever a model happens to emit
memory_search beside a read. It wants its own change that separates
"parallel-safe" from "allowed in plan mode", not a drive-by flip inside a
prompt PR.

Test now pins both: the rule must name shell_exec and must not name
run_command, and rule 7 specifically must not advertise memory_search or
kb_search. The memory check is scoped to rule 7 on purpose -- rule 5
tells the model to use memory_search before answering from prior
conversations, which is a good instruction; only the batching claim was
wrong. Confirmed both guards bite by re-introducing run_command and
watching the test fail.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LGQKz579j1ZnDRwmr6h1V6
@FMXExpress
FMXExpress merged commit 81cbaca into main Aug 14, 2026
khongten001 pushed a commit to khongten001/PasClaw that referenced this pull request Nov 10, 2026
…g batches

TToolCategory was answering two unrelated questions with one field.
ToolLoop read tcReadOnly as "safe to run concurrently" when partitioning a
round into parallel batches; the plan-mode gate and the read-only MCP
server read it as "does not really mutate, so allow it". Those disagree
for any tool that writes but is labelled tcReadOnly to pass the gate --
and re-categorising cannot fix it, because whichever meaning you correct
you break the other.

Auditing every tcReadOnly registration found three such tools, not one:

  memory_search  Tool_MemorySearch calls IMemoryIndex.SyncDir, which
                 reindexes changed files and drops rows for deleted ones
                 -- writes and commits against .index.db. Two searches in
                 one batch (two different queries is an ordinary ask) are
                 two writers on that file. Reported by Codex on PR FMXExpress#537.
  plan_write     writes workspace/PLAN.md; PasClaw.Tools.PlanWrite
                 documents choosing tcReadOnly precisely to pass the
                 pmPlan gate.
  todo_write     rewrites the checklist file, and its comment actively
                 claimed the parallel batch as a benefit.

TTool gains SerialOnly, and the batcher now requires BOTH properties:
tcReadOnly AND not SerialOnly. Category keeps answering the gate and MCP
questions unchanged, so plan mode and read-only exposure behave exactly as
before -- verified by test-plan-build-mode, test-guardfall,
test-progress-ledger and test-mcp-server.

Polarity is deliberate and is the one thing worth re-checking in review.
TTool records are built on the stack and this codebase does not FillChar
them (managed strings), so a site assigning fields one by one leaves a new
Boolean holding stack garbage. With SerialOnly, garbage-True costs a batch
slot. With the inverse field, garbage-True would batch a writer
concurrently -- uninitialised memory becoming a data race. The safe
failure had to be the default one.

PartitionToolBatches is exported for tests: which tools share a batch is a
correctness property, and asserting the flags that feed the decision is
weaker than asserting the decision. The new test does the latter -- three
reads coalesce into one batch, a tcReadOnly writer splits it into three
and sits alone. Confirmed it fails against the old predicate.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LGQKz579j1ZnDRwmr6h1V6
khongten001 pushed a commit to khongten001/PasClaw that referenced this pull request Nov 10, 2026
The week's agent-optimization work (batch rule FMXExpress#537, SerialOnly FMXExpress#538,
compact results, disclosure, turn clock FMXExpress#543) all shipped on mechanistic
arguments with no measured effect. The plan closes that by wiring together
what already exists rather than building a bench from scratch.

Census findings the plan is grounded in:
- a scripted ILLMProvider (TScripted) already drives RunToolLoop in the
  progress-ledger tests -- the in-process bench substrate exists
- TToolLoopResult already carries the metrics (iterations, usage with
  cache read/created tokens, truncations, dispatched calls)
- context hygiene already exists and is untested for effect: per-turn
  hash-aware read dedup (C3) and stale-read stubbing after writes --
  which corrects the earlier Bullet-eval claim that PasClaw has no
  re-read guard
- PR FMXExpress#313 holds a real 13-fixture SWE-shaped bench with oracles and an
  ablation grid, but its branch has NO merge base with main -- the plan
  mines it onto main and closes the PR, same treatment for FMXExpress#308

Phases: P0 bench record (NDJSON per turn incl. prefix byte-stability),
P1 in-process scenario bench with committed budgets as a failing CI gate,
P2 extract bench/swe from the orphaned branch, P3 opt-in live-model A/B of
the shipped levers (needs a key; refuses without --spend), P4 the backlog
each item lands only with its bench delta attached.

Honest boundary stated up front: harness properties are fully measurable
in-sandbox with the scripted provider; model-dependent effects (does rule
7 change batching) need the live tier.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LGQKz579j1ZnDRwmr6h1V6
khongten001 pushed a commit to khongten001/PasClaw that referenced this pull request Nov 10, 2026
…llel

First measured evidence for two things this week shipped on reasoning
alone. PartitionToolBatches is unit-tested and FMXExpress#538 pinned that a
SerialOnly writer gets its own batch, but both assert the PLAN. This
asserts the consequence -- wall time -- through the real binary.

Three turns against a deliberately fat corpus, plus a no-tool turn to
calibrate:

  turn overhead (no tools)   256 ms
  one grep                   284 ms of work
  three greps in ONE round   292 ms of work   ~= 1.0x  -> they ran together
  grep, todo_write, grep     475 ms of work   ~= 1.7x  -> the writer split them

The second line is the parallel-dispatch claim from FMXExpress#537's machinery. The
third is FMXExpress#538: todo_write writes the checklist, so it must land in a batch
of its own, which forces the two greps apart. Had it been wrongly treated
as parallel-safe, that round would have collapsed toward 1.0x like the one
above it.

Calibration is the part worth reviewing. The first draft compared raw turn
times and read a correct 2x split as 1.3x -- roughly half of every number
was gateway + relay overhead, not work. Measuring a no-tool turn and
subtracting it makes the ratios mean what they say, and keeps the budgets
portable: a slower or loaded machine moves all four numbers together.
There is also a floor check, so if the corpus stops being fat the bench
says so instead of asserting on noise.

PRE-EXISTING FAILURE, not from this change: `histelide` fails on
unmodified main -- verified by stashing this work and re-running. Its
elision assertions pass (no verbatim replay, marker present); what fails
is the size budget, Length(EnvAt(1)) < 20000 against an actual 31858. That
reads as the fixed per-request overhead having grown past a committed
number rather than elision breaking, which is exactly the
tool-description-budget item in docs/agent-bench-plan.md. Left alone here:
it wants its own change and a decision about whether to trim the schemas
or move the budget.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LGQKz579j1ZnDRwmr6h1V6
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.

2 participants