Skip to content

[Bug]: atlas boulder-continuation loops forever on a failed compaction (Anthropic 400 tool_use/tool_result); missing the #6109 guards #6303

Open

Description

@sonny-travix-dev

Prerequisites

Bug Description

The atlas boulder-continuation path infinitely re-injects [SYSTEM DIRECTIVE: OH-MY-OPENCODE - BOULDER CONTINUATION] after a compaction that fails with a non-retryable Anthropic 400, leaving the session permanently stuck.

The trigger is an opencode-core bug (a tool_use block whose paired tool_result gets split off during compaction/normalize → Anthropic invalid_request_error, tracked upstream in anomalyco/opencode#25774, #27594, #14367). oh-my-openagent cannot fix opencode's message splitting — but it can and should stop looping on it, exactly like todo-continuation-enforcer already does after #6109.

The problem is the asymmetry: todo-continuation-enforcer/idle-event.ts gained a full set of compaction/API-error guards in #6109, but the atlas boulder path (boulder-continuation-injector.ts + idle-continuation.ts) never got them, so boulder plans loop forever while todo-driven sessions now recover.

Steps to Reproduce

  1. Run a long Atlas boulder plan (dozens of tasks) that accumulates a large, tool-heavy history — many consecutive task subagent tool_use turns with no user turn between them.
  2. Context grows until opencode's auto-compaction triggers.
  3. opencode's compaction builds an invalid Anthropic request: a tool_use block is separated from its paired tool_result (opencode-core bug, fix(provider): Anthropic normalize splits tool-call from tool-result causing dangling tool_use error anomalyco/opencode#25774). Anthropic returns HTTP 400 invalid_request_error with isRetryable: false:
    messages.2: `tool_use` ids were found without `tool_result` blocks immediately after: toolu_XXXX.
    Each `tool_use` block must have a corresponding `tool_result` block in the next message.
    
  4. The compaction assistant message is persisted with an error; the latest session state is now a failed compaction.
  5. On idle, atlas boulder-continuation re-injects the BOULDER CONTINUATION directive → opencode re-attempts the same compaction → same 400 → repeat every ~7 seconds, forever. Every subsequent turn (including a manual message) re-fires the broken compaction. The session never recovers.

Expected Behavior

Boulder continuation should behave like todo-continuation-enforcer post-#6109: when the latest assistant turn is a failed/errored compaction or a non-retryable API 400, it must stop re-injecting — skip on latestMessageWasCompaction, respect the compaction guard, honor tokenLimitDetected, and back off / mark the session stalled and surface the error, instead of looping.

Actual Behavior

Boulder continuation ignores the failed compaction and re-injects every ~7s indefinitely.

Observed in a real session (opencode 1.18.4 + oh-my-openagent 4.11.1): 8 consecutive compaction attempts, all HTTP 400 tool_use/tool_result, each followed ~7s later by a fresh BOULDER CONTINUATION directive; the plan was frozen (e.g. 22/35) and could not advance. The orphaned tool_use belonged to a completed task subagent turn (so a "pending/running tool" guard does not catch it — the pairing was broken by compaction slicing, not by an unfinished tool).

Root cause on the boulder path (verified against latest dev, 4.19.1):

  1. Failure accounting is blind to compaction failures. In boulder-continuation-injector.ts, injectBoulderContinuation() resets promptFailureCount = 0 the moment the prompt injection succeeds:

    sessionState.promptFailureCount = 0
    markContinuationInjectedAwaitingToolProgress(sessionState)
    return "injected"

    The compaction 400 happens afterwards, asynchronously, inside opencode's own turn processing — the injector only ever sees "prompt dispatched successfully". So promptFailureCount never accumulates, and the MAX_CONSECUTIVE_PROMPT_FAILURES guard in idle-continuation.ts::scheduleRetry() (if (sessionState.promptFailureCount >= MAX_CONSECUTIVE_PROMPT_FAILURES) return) never fires.

  2. None of the 🐛 [BUG] todo-continuation-enforcer hook causes system-directive spam loop, mid-stream text fragmentation, and unresponsive sessions #6109 guards exist on the boulder path. todo-continuation-enforcer/idle-event.ts has all of these; atlas boulder-continuation has none:

    • if (state.tokenLimitDetected) return — non-retryable/context-overflow skip
    • if (latestMessageWasCompaction) { ... return } — skip when the latest message is a compaction marker
    • if (isCompactionGuardActive(state, ...)) return — compaction-epoch guard
    • isLastAssistantMessageAborted(...) — errored/aborted last-turn skip
    • exponential backoff CONTINUATION_COOLDOWN_MS * 2 ** min(consecutiveFailures, 5)

Because the boulder path lacks both the honest failure accounting and the compaction/error skips, it loops on a deterministic, non-retryable failure until the user kills the session.

Error Logs

APIError 400 (isRetryable: false)
messages.2: `tool_use` ids were found without `tool_result` blocks immediately after: toolu_XXXX.
Each `tool_use` block must have a corresponding `tool_result` block in the next message.
(request to https://api.anthropic.com/v1/messages)

Repeated 8× over ~5 minutes, each retry preceded by an injected [SYSTEM DIRECTIVE: OH-MY-OPENCODE - BOULDER CONTINUATION] user message ~7s apart.

Doctor Output

bunx oh-my-openagent doctor currently crashes on this machine (likely a separate minor packaging issue), so environment info is provided manually:

$ bunx oh-my-openagent doctor
.../oh-my-opencode.js:2
import { spawnSync } from "node:child_process";
^^^^^^
SyntaxError: Cannot use import statement outside a module
Node.js v20.10.0

Manual environment:

  • opencode: 1.18.4
  • oh-my-openagent: 4.11.1 (latest available on npm: 4.19.1)
  • OS: macOS 14.2.1 (arm64)
  • node: v20.10.0
  • bun: 1.3.6

Suggested Fix

Give the atlas boulder-continuation path the same guards todo-continuation-enforcer already has (ideally by sharing the logic):

  1. Before injecting (in idle-continuation.ts and/or the scheduleRetry timer), fetch the latest messages and skip when the latest assistant turn is a compaction marker or carries an error (latestMessageWasCompaction, isLastAssistantMessageAborted), and honor the compaction guard + tokenLimitDetected.
  2. Treat a non-retryable API failure detected on the session (not just a failed injection dispatch) as a promptFailureCount increment / stall condition, so MAX_CONSECUTIVE_PROMPT_FAILURES can actually trip.
  3. When stalling, surface the compaction error to the user and stop the loop instead of silently re-firing.

Additional Context

Activity

  1. code-yeongyu commented on Aug 6, 2026

    @code-yeongyu
    Owner

    [sisyphus-bot] Thanks for the detailed comparison with #6109 and the upstream Anthropic failure. The boulder path still has the reported failure mode: it resets its failure count when the directive dispatch is accepted, while the later compaction 400 is invisible to that accounting, and it lacks the todo enforcer's compaction/non-retryable-error guards. This can re-inject the directive indefinitely against the same failed compaction.

    Evidence: packages/omo-opencode/src/hooks/atlas/idle-continuation.ts:143-184 retries only on promptFailureCount/stall flags and has no compaction/error guards; packages/omo-opencode/src/hooks/atlas/boulder-continuation-injector.ts:105-116 resets promptFailureCount after accepted injection. By contrast, packages/omo-opencode/src/hooks/todo-continuation-enforcer/idle-event.ts:50-75, 89-108, and 146-184 has token-limit, non-retryable-error, aborted-turn, compaction-marker, and backoff guards.

  2. self-assigned this
    on Aug 6, 2026
  3. code-yeongyu commented on Aug 6, 2026

    @code-yeongyu
    Owner

    [sisyphus-bot] Triage: this report (atlas boulder-continuation looping on failed compaction) is still open and needs maintainer investigation. We reviewed the current dev code around the reported area and could not confirm an existing fix, so we're treating it as a real open bug. Assigning to @code-yeongyu. If you can still reproduce on the latest release, any fresh logs or a minimal repro in the thread would speed up the fix. Thanks for the detailed report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions