Skip to content

fix: trim the per-call ctx_batch_execute footer#922

Open
uwuclxdy wants to merge 1 commit into
mksglu:nextfrom
uwuclxdy:fix/batch-terms-footer-gating
Open

fix: trim the per-call ctx_batch_execute footer#922
uwuclxdy wants to merge 1 commit into
mksglu:nextfrom
uwuclxdy:fix/batch-terms-footer-gating

Conversation

@uwuclxdy

@uwuclxdy uwuclxdy commented Jul 5, 2026

Copy link
Copy Markdown

What / Why / How

Root cause: ctx_batch_execute appended two footers on every call. The Searchable terms for follow-up: line fired whenever store.getDistinctiveTerms returned terms, though the adjacent comment scopes it to "edge cases where follow-up is needed". Separately, formatBatchQueryResults repeated its > **Tip:** Results are scoped to this batch only... line on every non-global call. On a batch whose queries all matched, that is roughly 140 tokens of trailing footer with nothing to act on.

Fix: two changes, each tying a footer to when it is actually useful.

  • formatBatchQueryResults takes an optional stats out-parameter and sets stats.anyMiss when a query returns no matches. The handler computes distinctiveTerms only when batchStats.anyMiss is true, so the searchable-terms line shows only on the follow-up case the comment describes. The return type stays string[], so existing callers are unaffected.
  • The batch scoping tip is emitted once per server process (the first non-global batch call) via a module-level flag, rather than on every call. The query_scope: "global" line is unchanged. An exported resetBatchFooterState() restores the flag so tests stay deterministic under vitest's shared fork pool; production never calls it.

The flag lives inside the formatter for locality. It could equally sit at the handler call site if you prefer to keep the formatter free of module state.

Affected platforms

  • Claude Code
  • Cursor
  • VS Code Copilot (GitHub Copilot)
  • JetBrains Copilot
  • Gemini CLI
  • Qwen Code
  • OpenCode
  • KiloCode
  • Codex CLI
  • OpenClaw (Pi Agent)
  • Pi
  • Kiro
  • Antigravity
  • Zed
  • All platforms

Test plan

  • npx tsc -b --noEmit clean.
  • npx vitest run tests/core/server.test.ts green (500 tests). Added coverage: stats.anyMiss is false for an all-hit batch and true when a query misses. A separate case asserts the scoping tip shows on the first batch call in a fresh process and is omitted on a second call in the same process.

Checklist

  • Tests added/updated (TDD: red → green)
  • npm test passes
  • npm run typecheck passes
  • Docs updated if needed (README, platform-support.md)
  • No Windows path regressions (forward slashes only)
  • Targets next branch (unless hotfix)
Cross-platform notes

Our CI runs on Ubuntu, macOS, and Windows.

  • If touching file paths, verify forward-slash normalization on Windows
  • If touching hook paths, verify no backslash separators
  • Use path.join() / path.resolve(), never hardcode / separators
  • Use event-based stdin reading — readFileSync(0) breaks on Windows
  • Use os.tmpdir(), never hardcode /tmp

Two footers were appended on every ctx_batch_execute call. The
`Searchable terms for follow-up:` line now appears only when a query returned
no matches, threaded via a `stats.anyMiss` out-parameter on
`formatBatchQueryResults` that keeps its `string[]` return type. The
`Results are scoped to this batch only` tip is now emitted once per server
process instead of on every call; `resetBatchFooterState()` restores the flag
so tests stay deterministic under vitest's shared fork pool.
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