babysitter icon indicating copy to clipboard operation
babysitter copied to clipboard

[SDK/breakpoint] Rejection-recovery loop — don't hard-abort on breakpoint rejection

Open rogelsm opened this issue 5 months ago • 4 comments

Summary

When an owner rejects a breakpoint, the run should branch into a re-scope/re-prompt task seeded with the rejection text and re-enter the iterate loop, rather than treating rejection as an immediate hard-abort.

Motivation / Evidence

cookbook native-apps-bugfix-jun-06 (run 01KTF43QXQBJ816D9TRXFXX50R) abandoned at BP-1 after the owner correctly rejected a wrong-scope spec (C1 'hide hands-free' baked in from an unresolved 'cloud-STT vs disable' product fork). The process hard-coded if(!bp1.approved) return {aborted:true} (process.js:238); ~3 days of re-scoped cloud-STT + H7 auth work then shipped via untracked direct commits (851407b, d1e09a9) and ~38 orphaned bf-build logs.

Proposal

On !approved, capture bp.response and branch into a re-scope / re-prompt task seeded with the rejection text, then re-enter the iterate loop. Abandonment should require an explicit owner Hold/abort choice, never be the default rejection path. Pairs with the documented retry/refine pattern.

Alternatives considered

  • Leave hard-abort as default and rely on process authors to hand-roll recovery branches — this is exactly what failed here, since the boilerplate return {aborted:true} is the path of least resistance.
  • Auto-retry without seeding the rejection text — wastes a loop because the agent re-proposes the same rejected scope.
  • Document the pattern only — insufficient; the unsafe default needs to change, not just the docs.

Related

  • #87 — breakpoint rejection return value going unchecked is the same class of silent-rejection-handling gap.
  • #191 — non-interactive auto-approve / rejection sequencing context.
  • #880 (run:halt) covers explicit sealing; R1 instead keeps the run alive and recoverable after a rejection.

Reported from a cookbook babysitter retrospective (retro-jun-09) via /babysitter:contrib.

rogelsm avatar Jun 09 '26 19:06 rogelsm

Triage Summary

  • One-line: Breakpoint rejection is preserved by the SDK, but there is no generic recovery branch that turns owner rejection feedback into a re-scope/re-prompt task and resumes the orchestration loop.

Critical Evaluation

  • Reporter's analysis is accurate: this is a real workflow gap, not a missing rejection return value.
  • The safest fix is not to make every ctx.breakpoint() auto-loop globally. Existing processes may intentionally treat rejection as terminal.

Root Cause Analysis

  • Affected files/functions:
    • packages/babysitter-sdk/src/runtime/intrinsics/breakpoint.ts (runBreakpointIntrinsic)
    • packages/babysitter-sdk/src/runtime/processContext.ts (ctx.breakpoint binding)
    • packages/babysitter-sdk/src/runtime/types.ts (BreakpointResult)
    • packages/babysitter-sdk/src/prompts/templates/breakpoint-handling.md
    • library/reference/ADVANCED_PATTERNS.md
    • library/processes/shared/n-strikes-escalation.js
  • Actual root cause: ctx.breakpoint() correctly returns approved:false plus response/feedback after rejection, but rejection recovery is left to each process author. The docs recommend retry/refine loops, and n-strikes-escalation demonstrates a safer pattern, but there is no generic SDK/library primitive that makes owner rejection recoverable by default.
  • Code evidence:
    • runBreakpointIntrinsic returns the posted breakpoint result for interactive mode and auto-approves only in non-interactive mode.
    • Runtime tests already verify rejection returns approved:false with feedback.
    • Prompt/reference docs say rejection should loop back, but this guidance is advisory.

Affected Components

  • Packages: sdk
  • Effort: effort:medium

Recommended Approach

Implement an explicit reusable recovery branch for owner breakpoints rather than changing raw ctx.breakpoint() semantics globally.

Suggested shape:

  • Add a SDK/library helper or process-library primitive for rejection recovery.
  • On approved:false, capture response || feedback, pass it into a re-scope/re-prompt task as previousFeedback, include an attempt counter, and re-enter the caller's bounded loop.
  • Make explicit Hold/abort a separate owner choice; rejection alone should mean “revise with this feedback,” not terminal abandonment.
  • Update process templates/examples to use the helper and avoid if (!approved) return {aborted:true} boilerplate.
  • Add regression coverage for reject -> feedback threaded into re-scope task -> iterate resumes.

Reproduction

Create a process that awaits ctx.breakpoint(...), post a breakpoint result such as { "approved": false, "response": "re-scope to cloud-STT" }, then have the process branch on !approved by returning { aborted: true }. The runtime resumes faithfully with approved:false; the process hard-aborts because no generic recovery helper intercepts the rejection or creates a re-scope task.

Related Issues/PRs

  • #87: adjacent class; unchecked breakpoint return values can silently ignore rejection.
  • #191: different non-interactive breakpoint/journal sequencing problem.
  • #880: explicit run:halt sealing; related to deliberate abort/hold semantics, not a duplicate.

Priority: medium

This affects a core orchestration control path and can waste substantial tracked work, as the report describes. It is not critical because the runtime preserves rejection data and process authors can work around it manually, but the unsafe pattern is easy to repeat.

Risk Analysis

  • Risk Level: risk:medium
  • Global behavior change risk: changing ctx.breakpoint() to auto-loop could break processes where rejection intentionally terminates or holds a run.
    • Mitigation: implement an explicit helper/option first; keep raw ctx.breakpoint() stable unless a migration plan is approved.
  • Feedback drift risk: recovery loops may re-propose the same rejected scope if the rejection text is not threaded.
    • Mitigation: require previousFeedback and attempt in the re-scope/re-prompt task.
  • Replay determinism risk: additional tasks can destabilize replay if keys or loop bounds are unstable.
    • Mitigation: use stable task keys, bounded attempts, and tests covering replay after rejection.
  • Non-interactive risk: non-interactive mode currently auto-approves breakpoints.
    • Mitigation: scope rejection-recovery behavior to interactive/user-posted rejections and keep non-interactive auto-approval unchanged.

Ready for development.

a5c-ai avatar Jul 02 '26 01:07 a5c-ai

Triage Summary

This is a valid SDK/process-authoring feature request: breakpoint rejection should default to a recoverable re-scope/refine path seeded with owner feedback, not a hard abort unless the owner explicitly chooses Hold/Abort.

Critical Evaluation

The reporter's analysis is accurate. The SDK already preserves rejection data, but process authors still have to hand-write the recovery branch. Docs contain a retry/refine example, yet current library processes still include hard-stop patterns on !approved, so documentation alone has not made the safe path the default.

Root Cause Analysis

Affected code paths:

  • packages/babysitter-sdk/src/runtime/intrinsics/breakpoint.ts: runBreakpointIntrinsic dispatches breakpoint effects and returns the posted BreakpointResult; in non-interactive mode it auto-approves.
  • packages/babysitter-sdk/src/runtime/types.ts: BreakpointResult includes approved, response, and feedback, but no recovery contract.
  • packages/babysitter-sdk/src/runtime/__tests__/intrinsics.behaviors.test.ts: verifies approved:false plus response/feedback are returned correctly.
  • packages/babysitter-sdk/src/prompts/templates/breakpoint-handling.md: already documents a retry/refine loop.
  • Process-library examples such as library/cradle/feature-implementation-contribute.js, library/cradle/project-install.js, and library/contrib/joe-habu/superbabysitter/quality-gated-development.js still hard-stop on rejection in some gates.

The real gap is not that rejection feedback is lost by the SDK. The gap is that process generation/library defaults still allow ordinary approval-gate rejection to become terminal control flow.

Affected Components

  • Packages: packages/babysitter-sdk, process-authoring prompts/templates, process-library examples
  • Labels: feature, enhancement, sdk, effort:medium

Recommended Approach

Implement this as an explicit rejection-recovery contract in process authoring/runtime helpers rather than an invisible SDK auto-loop.

Suggested work:

  • Add/update a reusable approval-gate helper or generated process pattern where !approval.approved branches into a re-scope/refine task with approval.response || approval.feedback.
  • Reserve terminal stop behavior for an explicit Hold/Abort option or an explicit process annotation.
  • Add generator/prompt tests that reject hard-abort boilerplate for ordinary approval gates.
  • Add a process-library scan or lint rule that flags patterns like if (!approval.approved) return { aborted: true } unless explicitly annotated as terminal.
  • Update existing library examples that use terminal rejection paths where the rejection should be recoverable.

Reproduction

Create a process that awaits ctx.breakpoint(), post { approved:false, response:'change scope' }, then branch on !approval.approved by returning { aborted:true } or { success:false }. The SDK preserves feedback, but the run exits instead of re-scoping unless the process author manually wrote the loop.

Related Issues/PRs

  • #87: same rejection-handling class, focused on unchecked ctx.breakpoint() return values.
  • #191: different breakpoint issue around non-interactive journal sequencing.
  • #880: explicit run:halt for sealing divergent runs; related but not a replacement for recoverable rejection handling.
  • Recent adjacent commit: 1f20e5cf2 fixed repeated breakpoint identity collision, not this recovery behavior.

Priority: medium

This can waste significant orchestration work and discard owner steering in high-value workflows, but the SDK does preserve rejection data and process authors can work around it today.

Risk Analysis

Risk level: risk:medium.

  • Over-automating ctx.breakpoint rejection handling could make intentional cancel/hold gates loop forever.
    • Mitigation: keep terminal stop as an explicit option/annotation and test both recoverable rejection and intentional abort paths.
  • A broad lint rule could flag legitimate cancellation gates.
    • Mitigation: scope it to ordinary approval-gate patterns or require an explicit terminal-rejection marker.
  • Updating docs alone will not prevent recurrence.
    • Mitigation: add generator tests and process-library scans that fail on unsafe boilerplate.

Ready for development.

a5c-ai avatar Jul 02 '26 01:07 a5c-ai

Triage Summary

  • One-line: #950 is a valid SDK/process-library enhancement: breakpoint rejection should feed a retry/re-scope loop by default in generated process patterns, rather than making hard-abort the easiest path.

Critical Evaluation

  • The reporter's analysis is directionally accurate. The unsafe behavior is not that the SDK loses rejection data; it is that ctx.breakpoint() returns rejection data and process authors/templates must manually wire the recovery path.
  • The proposed fix is correct in spirit, but should not be implemented as a magical runtime auto-loop. The SDK cannot infer the right refine task or scope state for every process.

Root Cause Analysis

  • Affected files/functions:
    • packages/babysitter-sdk/src/runtime/processContext.ts: exposes ctx.breakpoint() as runBreakpointIntrinsic(...).
    • packages/babysitter-sdk/src/runtime/intrinsics/breakpoint.ts: returns BreakpointResult from an interactive breakpoint task; in non-interactive mode it returns { approved: true, response: "Auto-approved (non-interactive mode)" }.
    • packages/babysitter-sdk/src/runtime/types.ts: defines BreakpointResult with approved, response, and feedback.
    • packages/babysitter-sdk/src/prompts/templates/breakpoint-handling.md: documents the desired retry/refine loop, but that is guidance rather than an executable guardrail.
  • Actual root cause: rejection handling is author-controlled. Existing or generated processes can still ignore approved, return early, or hard-abort on !approved.
  • Code evidence: existing tests cover non-interactive auto-approval and repeated breakpoint key disambiguation, but not an enforced rejection-recovery path.

Affected Components

  • Packages: sdk
  • Effort: effort:medium

Recommended Approach

  • Add an explicit SDK/process-library helper or template primitive for retryable approval gates, where the process supplies:
    • the approval breakpoint payload/options,
    • the refine/re-scope task to run on approved === false,
    • max attempts and explicit abort/hold semantics.
  • Add a lint or verification rule for approval gates that flags ignored ctx.breakpoint() results and !approved branches that immediately hard-abort without an explicit abort/hold option.
  • Update high-use process-library templates to use the helper/pattern.
  • Add regression tests covering request-changes loops separately from explicit cancel/hold behavior.

Reproduction

Create a process with a final ctx.breakpoint() approval gate, post a task result like:

{"approved": false, "response": "change scope"}

Then iterate. Unless the process explicitly branches on that result and schedules refinement/re-scope work, the SDK will not automatically create a recovery task.

Related Issues/PRs

  • #87: same general breakpoint rejection-handling class, focused on unchecked breakpoint return values.
  • #191: related breakpoint/non-interactive behavior, but a separate journal sequence collision issue.
  • #880: explicit run:halt command for sealing divergent runs; useful for abort semantics but not a duplicate of recovery-loop behavior.
  • Recent related commit: 1f20e5cf2 fixed repeated breakpoint invocation-key collisions, but does not address rejection recovery.

Priority: medium

Owner rejection is a core orchestration feedback path. Mishandling it can waste runs and discard scope corrections, but it is not crash/data-loss severity and individual processes can work around it today by explicitly checking approved === false.

Risk Analysis

  • Risk Level: risk:medium
  • Runtime auto-looping could invent the wrong refinement path for process-specific state.
    • Mitigation: make the recovery path explicit in a helper/template API; do not make raw ctx.breakpoint() guess.
  • Lint/template enforcement may flag legitimate terminal cancellation gates.
    • Mitigation: distinguish retryable request-changes gates from explicit abort/hold/cancel gates.
  • Existing processes may keep unsafe behavior after docs/templates change.
    • Mitigation: add a scanner/migration checklist for ignored breakpoint results and direct aborted:true returns.

a5c-ai avatar Jul 02 '26 01:07 a5c-ai

Triage Summary

  • One-line: Owner breakpoint rejection currently depends on process authors to branch correctly; unsafe process defaults can hard-abort instead of using rejection feedback to re-scope and continue.

Critical Evaluation

  • Reporter's analysis is accurate: the failure mode is real, but the safest fix is not a blanket runtime hard-abort or unconditional auto-retry.
  • The desired default should be: explicit owner Hold/abort stops the run; ordinary rejection/request-changes feeds a re-scope/re-prompt/refine task and re-enters the loop.

Root Cause Analysis

  • Affected files/functions:
    • packages/babysitter-sdk/src/runtime/intrinsics/breakpoint.ts (runBreakpointIntrinsic)
    • packages/babysitter-sdk/src/runtime/__tests__/intrinsics.behaviors.test.ts (rejected breakpoint result behavior)
    • packages/babysitter-sdk/src/runtime/intrinsics/__tests__/breakpointSkip.test.ts (non-interactive auto-approval behavior)
    • scripts/lint-breakpoint-results.cjs (current guardrail only checks discarded results)
    • packages/babysitter-sdk/src/prompts/templates/breakpoint-handling.md
    • library/reference/sdk.md
    • library/reference/ADVANCED_PATTERNS.md
  • Actual root cause: breakpoint rejection is returned as ordinary successful task output ({ approved: false, response, feedback }). Existing guardrails catch ignored breakpoint results, but do not catch or replace if (!approval.approved) return { aborted: true } hard-abort branches.
  • Code evidence: tests already verify rejected breakpoints return { approved: false, response, feedback }; the SDK leaves branching to process code. Prompt templates include retry/refine guidance, while some references still show return-on-rejection examples.

Affected Components

  • Packages: sdk, breakpoints-mux
  • Effort: effort:medium

Recommended Approach

  1. Add a reusable rejection-recovery primitive or documented helper pattern for owner approval gates:
    • capture approval.response || approval.feedback
    • schedule a re-scope/re-prompt/refine task seeded with that text
    • loop back to the approval gate
    • allow terminal exit only for explicit owner Hold/abort choices
  2. Update process-generation templates and reference docs so request-changes paths use the recovery loop by default.
  3. Extend lint/verification beyond “breakpoint result must be read” to flag hard-abort branches after !approval.approved, with an escape hatch for explicit terminal choices.
  4. Add regression tests covering a rejected owner breakpoint that produces a follow-up refinement task carrying the rejection text.

Reproduction

Create or run a process with an owner approval breakpoint followed by:

if (!approval.approved) return { aborted: true, feedback: approval.response || approval.feedback };

Reject the breakpoint with feedback. On the next iterate, the run terminates instead of scheduling a refinement/re-scope task using the feedback.

Related Issues/PRs

  • Related but not duplicate: #87 covers unchecked breakpoint results causing false success.
  • Related but not duplicate: #191 covers non-interactive auto-approval journal sequencing.
  • Related but not duplicate: #880 covers explicit run:halt sealing for divergent runs.
  • Recent related work: 1f20e5cf2 disambiguated repeated ctx.breakpoint() calls so a later breakpoint cannot inherit an earlier approval.

Priority: medium

This affects a core human-in-the-loop orchestration path and can waste substantial work, but existing processes can manually implement retry/refine loops and there is no data-loss or runtime crash severity.

Risk Analysis

  • Risk Level: risk:medium
  • Runtime semantic over-correction
    • Mitigation: do not globally make every rejection continue or abort; preserve explicit Hold/abort terminal paths.
  • Retry loop repeats rejected scope
    • Mitigation: tests must assert rejection feedback is passed into the re-scope/refine task and reflected in the next prompt.
  • Lint false positives
    • Mitigation: scope linting to owner approval gates and allow documented explicit terminal options.

Ready for development.

a5c-ai avatar Jul 02 '26 01:07 a5c-ai