Heuristic:A5c ai Babysitter Breakpoint Disambiguation Counter
| Knowledge Sources | |
|---|---|
| Domains | Debugging, Runtime |
| Last Updated | 2026-10-23 00:00 GMT |
Overview
Per-call counter disambiguation prevents repeated breakpoint calls with the same ID from silently inheriting an earlier approval resolution.
Description
When a process calls `ctx.breakpoint()` multiple times without an explicit `label` or `breakpointId`, all calls resolve to the same default breakpoint ID (`"breakpoint"`). Without disambiguation, the second call collides with the first invocation's key and silently inherits its resolution — a sign-off prompt gets skipped because it reuses an earlier "approved" result. The fix appends a per-call counter (sharing the task intrinsic's `invocationKeyCounts` map) to the breakpoint's invocation key. The counter is deterministic across replay because each iteration re-executes the process from the start in the same order. The first occurrence keeps the bare key for backward compatibility with already-recorded in-flight runs.
Usage
Use this heuristic when debugging silent breakpoint approval inheritance — when a breakpoint that should prompt for human sign-off is auto-approved because a prior breakpoint with the same ID was already resolved. This commonly occurs when a process has multiple `ctx.breakpoint()` calls without explicit labels.
The Insight (Rule of Thumb)
- Action: Append a per-call occurrence counter to the breakpoint invocation key when the same `breakpointId` is used more than once.
- Value: `invocationKey = occurrence === 0 ? baseKey : baseKey.${occurrence}` where `baseKey = __sdk.breakpoint.${breakpointId}`.
- Trade-off: The first occurrence uses the bare key (backward compatible with recorded runs); subsequent occurrences get suffixed keys. This means replay of old runs with only the first breakpoint will work, but new runs with multiple same-ID breakpoints will have distinct keys.
- Compatibility: The counter shares the task intrinsic's `invocationKeyCounts` map, ensuring determinism across replay iterations.
Reasoning
The breakpoint effect uses an explicit invocation `key` that bypasses the task intrinsic's per-call cursor (`deriveStableTaskKey`). Without disambiguation, the effect index lookup finds the first call's resolved record and returns it immediately, skipping the dispatch of a new effect. This is a silent failure — the process continues as if the breakpoint was approved, but the human was never prompted. The per-call counter ensures each invocation gets a unique key, forcing a new effect request for each breakpoint call.
Code Evidence
Disambiguation logic from `packages/babysitter-sdk/src/runtime/intrinsics/breakpoint.ts:87-101`:
// Disambiguate repeated breakpoints within one process run. The breakpoint
// effect uses an explicit invocation `key`, which bypasses the task
// intrinsic's per-call cursor (deriveStableTaskKey). Without disambiguation a
// second ctx.breakpoint() that resolves to the same breakpointId (e.g. the
// default "breakpoint" when no explicit label/breakpointId is given) collides
// with the first and silently inherits its resolution — a sign-off prompt
// gets skipped because it reuses an earlier "approved". Append a per-call
// counter (sharing the task intrinsic's counter map, so it is deterministic
// across replay — each iteration re-executes the process from the start in
// the same order). Keep the first occurrence's bare key for backward
// compatibility with already-recorded in-flight runs.
const baseKey = `__sdk.breakpoint.${breakpointId}`;
const counts = (context.invocationKeyCounts ??= new Map<string, number>());
const occurrence = counts.get(baseKey) ?? 0;
counts.set(baseKey, occurrence + 1);
const invocationKey = occurrence === 0 ? baseKey : `${baseKey}.${occurrence}`;