Skip to content

core: Stop waits for a pending snapshot after pre-output provider failure #55401

Open

Description

@CasualDeveloper

Description

I reproduced a Stop hang in the Core runner fixture on current dev (34d8ded0c58dd66808c1d60e081e8c66da12a896). If the provider stream fails before any output while the initial snapshot is pending, interruption cannot settle execution until that capture unblocks. Both retryable and terminal failures reproduce it.

The raw-failure path skips the provider-event readiness wait, then enters uninterruptible publication while capture is still pending. This is separate from #37751's staged-revert wake/resume bug.

Plugins

No external plugins; the fixture registers a retry hook as a synchronization barrier.

OpenCode version

dev at 34d8ded0c58dd66808c1d60e081e8c66da12a896 (2.0.29).

Steps to reproduce

  1. Hold the runner's initial Snapshot.capture with a deferred latch.
  2. Make the provider stream fail before emitting an event, using either providerUnavailable or invalidRequest.
  3. After the retry hook runs, interrupt the session without releasing capture.
  4. Check execution idle: both controlled cases fail the existing one-second deadline. Making readiness interruptible before publication lets both settle without releasing capture.

I tested the actual runner with controlled snapshot/provider boundaries, not a live provider or a stuck Git process.

Screenshot and/or share link

No visual change; the focused PR will include both regression cases.

Operating System

macOS.

Terminal

Bun test runner (1.4.2).

Activity

  1. opencode-agent commented on Oct 14, 2026

    @opencode-agent
    Contributor

    Thanks for the detailed report. I reproduced this in the Core runner test fixture on dev at 34d8ded, which is still the latest dev.

    I replaced the fixture's snapshot service with one whose capture waits on a latch. The provider stream fails before emitting any event, with either providerUnavailable or invalidRequest. After a registered retry hook runs, I call session.interrupt and wait one second for awaitIdle while the capture is still held. In both cases the execution does not go idle within that second.

    As a control, I ran the same scenarios with the capture released immediately, and both settled within the second. The script below reproduces both cases. With REPRO_CONTROL=1 it runs the control instead.

    This looks separate from #37751 / #55394, as you said. #48657 describes a real-world way for Snapshot.capture() to get stuck, which would make this hang show up outside tests.

    Reproduction script (repro-55401.sh)
    #!/usr/bin/env bash
    # Reproduces anomalyco/opencode#55401 in the Core runner test fixture.
    # Usage: REPO=/path/to/opencode bash repro-55401.sh   (REPRO_CONTROL=1 releases the capture immediately as a control)
    set -euo pipefail
    REPO=${REPO:-/workspace/repo}
    SRC="$REPO/packages/core/test/session-runner.test.ts"
    DST="$REPO/packages/core/test/repro-55401.test.ts"
    # Swap the no-op snapshot layer for one whose capture blocks on a latch.
    perl -0pe 's/Snapshot\.node\.replace\(Snapshot\.noopLayer\)/Snapshot.node.replace(reproSnapshotLayer())/' "$SRC" > "$DST"
    grep -q reproSnapshotLayer "$DST"
    cat >> "$DST" <<'TS'
    
    // ---- #55401 reproduction ----
    var reproLatch: Promise<void> | undefined
    function reproSnapshotLayer() {
      return Layer.succeed(
      Snapshot.Service,
      Snapshot.Service.of({
        transform: () => Effect.succeed({ dispose: Effect.void }),
        reload: () => Effect.void,
        capture: () => Effect.promise(() => reproLatch ?? Promise.resolve()).pipe(Effect.as(undefined)),
        files: () => Effect.succeed([]),
        diff: () => Effect.succeed([]),
        restore: () => Effect.void,
      }),
    )
    }
    
    describe("repro55401", () => {
      for (const [name, failure] of [
        ["providerUnavailable", providerUnavailable],
        ["invalidRequest", invalidRequest],
      ] as const) {
        scenario(`repro55401 Stop settles while start snapshot pending after pre-output ${name}`, function* (s) {
          let release!: () => void
          reproLatch = new Promise<void>((r) => (release = r))
          if (process.env.REPRO_CONTROL) release()
          try {
            yield* s.admit(`Fail before output: ${name}`)
            yield* s.llm.always(Stream.fail(failure()))
            const hooks = yield* PluginHooks.Service
            const hookRan = yield* Deferred.make<void>()
            yield* hooks.register("session", "retry", (event) =>
              Deferred.succeed(hookRan, undefined).pipe(
                Effect.andThen(Effect.sync(() => (event.decision = { retry: false }))),
              ),
            )
            const run = yield* s.resume.pipe(Effect.forkChild)
            yield* Deferred.await(hookRan)
            const interrupting = yield* s.session.interrupt(sessionID).pipe(Effect.forkChild)
            const execution = yield* SessionExecution.Service
            const idle = yield* execution.awaitIdle(sessionID).pipe(Effect.forkChild)
            // Real-time one-second deadline, capture still held.
            yield* Effect.promise(() => new Promise((r) => setTimeout(r, 1000)))
            const settled = idle.pollUnsafe() !== undefined
            console.log(`[repro55401] ${name}: idle within 1s while capture pending = ${settled}`)
            release()
            yield* Fiber.await(run)
            yield* Fiber.await(interrupting)
            expect(settled).toBe(true)
          } finally {
            release?.()
            reproLatch = undefined
          }
        })
      }
    })
    TS
    cd "$REPO/packages/core"
    timeout 300 bun test test/repro-55401.test.ts -t repro55401 2>&1 | tail -40 || true
    rm -f "$DST"

    Run it: bash repro-55401.sh

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions