fix(tools): close scheduler coverage gaps; regen persistence catalog

The coverage gate flagged three untaken paths in the bridge scheduler:
- the exclusive-head inFlight re-check was dead (the shared guard above
  already returns for an exclusive head with any in-flight sibling) — removed;
- the commit-cursor undefined-dispatched break was structurally unreachable
  once entries join commitQueue only after start() ran synchronously —
  reordered the pump so the invariant holds by construction, annotated;
- the finish (final-result) commit arm and the pump re-entry guard gain a
  covering test (throwing tools/pre-execute listener) and a defensive
  annotation respectively; mid-run unregistration test renamed to match its
  actual post-result settlement path.

Also covers the direct-construction maxParallelSubCalls default (index.ts)
and commits the regenerated persistence catalog for the new dispatch pair.
This commit is contained in:
Tianyi Cui
2026-07-26 13:24:34 +08:00
parent 6333b51f2f
commit 06556237f4
3 files changed
+84 -8

No files matched your search

+12 -6
View File
@@ -285,6 +285,7 @@ export function createRunCodeTool(registry: ToolRegistry, requireRuntime: () =>
const head = commitQueue[0]
/* v8 ignore next -- the loop condition bounds the index. */
if (head === undefined) break
/* v8 ignore next -- entries join commitQueue only after start() set dispatched (see pump). */
if (head.dispatched === undefined) break
await head.dispatched
commitQueue.shift()
@@ -295,7 +296,11 @@ export function createRunCodeTool(registry: ToolRegistry, requireRuntime: () =>
}
}
const pump = (): void => {
// The finally-driven re-entry below would otherwise recurse.
// Defensive re-entry guard: today every caller (binding submission,
// flight.finally, drain) runs off promise callbacks, never while pump
// is on the stack, so this cannot fire — kept against a future
// synchronous caller.
/* v8 ignore next -- see the re-entry note above. */
if (pumping) return
pumping = true
try {
@@ -310,12 +315,10 @@ export function createRunCodeTool(registry: ToolRegistry, requireRuntime: () =>
// Reclassify at start time (fail-closed on registry changes).
const mode = head.classify()
if (exclusiveActive || inFlight.size >= (mode === 'exclusive' ? 1 : maxParallel)) return
if (mode === 'exclusive') {
if (inFlight.size > 0) return
exclusiveActive = true
}
// The guard above already returned for an exclusive head with any
// in-flight sibling, so claiming the barrier here is race-free.
if (mode === 'exclusive') exclusiveActive = true
pendingQueue.shift()
commitQueue.push(head)
const flight = head.start().finally(() => {
inFlight.delete(flight)
if (mode === 'exclusive') exclusiveActive = false
@@ -325,6 +328,9 @@ export function createRunCodeTool(registry: ToolRegistry, requireRuntime: () =>
void commitReady()
pump()
})
// Joined AFTER start() ran synchronously, so every commitQueue
// entry already carries its `dispatched` promise.
commitQueue.push(head)
inFlight.add(flight)
}
} finally {