Skip to content

fix(circuit-breaker): make repetitive detection target-aware and add enabled escape hatch#2655

Merged
code-yeongyu merged 4 commits intocode-yeongyu:devfrom
tad-hq:infinite-circuit-target-fix
Mar 18, 2026
Merged

fix(circuit-breaker): make repetitive detection target-aware and add enabled escape hatch#2655
code-yeongyu merged 4 commits intocode-yeongyu:devfrom
tad-hq:infinite-circuit-target-fix

Conversation

@tad-hq
Copy link
Copy Markdown
Contributor

@tad-hq tad-hq commented Mar 17, 2026

Summary

  • Fix false-positive background task cancellations by changing repetitive detection from tool-name counting to target-aware tool signatures.
  • Add circuitBreaker.enabled (default true) as an escape hatch for repetitive-pattern cancellation.
  • Preserve the absolute maxToolCalls safety backstop and keep cancellation messages human-readable.

Changes

  • Added config support:
    • src/config/schema/background-task.ts: circuitBreaker.enabled?: boolean
    • src/features/background-agent/constants.ts: DEFAULT_CIRCUIT_BREAKER_ENABLED = true
    • assets/oh-my-opencode.schema.json regenerated
  • Updated loop detection internals:
    • ToolCallWindow.toolNames -> toolSignatures
    • Added deterministic signature generation: toolName::sortedJson(input)
    • Empty/missing input falls back to bare tool name for backward compatibility
    • recordToolCall(...) now accepts optional toolInput
    • Repetitive detection still uses the same threshold math, but now counts signatures instead of bare tool names
    • Returned cancellation toolName remains bare (no signature payload leakage)
  • Updated background manager wiring:
    • MessagePartInfo.state now includes optional input
    • Passes partInfo.state?.input to recordToolCall(...)
    • Repetitive-pattern cancellation now guarded by if (circuitBreaker.enabled)
    • Absolute maxToolCalls cancellation remains unconditional
  • Added tests:
    • loop-detector.test.ts: enabled flag resolution, signature normalization/order stability, different-target no-trigger, same-target trigger, no-input fallback
    • manager-circuit-breaker.test.ts: integration coverage for different-target run-through, same-target cancellation with bare tool name, enabled=false behavior, and absolute-cap backstop

Testing

bun run typecheck
bun run build
bun test src/features/background-agent/loop-detector.test.ts src/features/background-agent/manager-circuit-breaker.test.ts src/config/schema/background-task-circuit-breaker.test.ts

Additional verification:

  • OpenCode smoke-tested with isolated config (XDG_CONFIG_HOME=/tmp/omo-smoke-xdg) and local plugin path (file:///.../dist/index.js) so user config was not modified.

Known upstream baseline (not introduced by this PR):

  • bun test src/features/background-agent/ has one pre-existing failure in src/features/background-agent/manager.test.ts:
    • BackgroundManager process cleanup > should remove listeners after last shutdown
    • reproduced on clean dev in a temporary worktree

Related Issues

Closes #2652


Summary by cubic

Make the circuit breaker target-aware to stop false-positive cancellations, and add an escape hatch to disable repetitive-pattern checks. Keeps the absolute maxToolCalls backstop unchanged. Closes #2652.

  • Bug Fixes

    • Detect repetition by tool signature (toolName::sortedJson(input)) instead of tool name.
    • Deterministic signature generation; empty/missing input falls back to bare tool name.
    • Manager forwards state.input to loop detection; cancellation message shows only the bare tool name.
    • Prevents cancelling when the same tool runs on different targets; still cancels on true same-target loops.
  • New Features

    • Add circuitBreaker.enabled (default true) to disable repetitive-pattern cancellation.
    • Update JSON schema and defaults; preserve unconditional absolute cap via maxToolCalls.
    • Add tests covering enabled flag, signature stability, different-target pass-through, and same-target cancellation.

Written for commit 224ecea. Summary will update on new commits.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 17, 2026

All contributors have signed the CLA. Thank you! ✅
Posted by the CLA Assistant Lite bot.

@tad-hq
Copy link
Copy Markdown
Contributor Author

tad-hq commented Mar 17, 2026

I have read the CLA Document and I hereby sign the CLA

github-actions bot added a commit that referenced this pull request Mar 17, 2026
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 8 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Auto-approved: The PR correctly implements target-aware circuit breaking by using tool signatures, reducing false positives while maintaining safety via the absolute tool call limit and comprehensive tests.


Since this is your first cubic review, here's how it works:

  • cubic automatically reviews your code and comments on bugs and improvements
  • Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
  • Add one-off context when rerunning by tagging @cubic-dev-ai with guidance or docs links (including llms.txt)
  • Ask questions if you need clarification on any suggestion

@code-yeongyu code-yeongyu merged commit 1d5652d into code-yeongyu:dev Mar 18, 2026
7 of 9 checks passed
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.

[Bug][Agent-generated] Background circuit breaker falsely cancels explore/librarian during legitimate search bursts

2 participants