Skip to content

fix(opencode): count doom-loop failures per step (Refs #725) - #760

Closed
agenteinstinct1-max wants to merge 12 commits into
dev-vibecodedfrom
arena/3d0a9b9e-silvercode
Closed

agenteinstinct1-max wants to merge 12 commits into
dev-vibecodedfrom
arena/3d0a9b9e-silvercode

Conversation

@agenteinstinct1-max

Copy link
Copy Markdown
Collaborator

Issue for this PR

Refs #725

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Draft replacement for #753 (that branch belongs to the previous owner and is left untouched; this one carries the same fix plus the review follow-up).

The doom-loop guard now treats a generation step, not an individual tool call, as one attempt. It asks only when the two most recent execution steps contain completed error outcomes for the same tool and identical input, so the current call is the third consecutive failure. Successful calls, mixed-outcome steps, a different tool, and a different input all break that streak. The reserved invalid repair placeholder stays excluded because it never executes, calls fanned out in one step cannot manufacture a loop, and the guard records an ask per step so sibling error events can neither suppress nor duplicate it.

This branch is a normal three-way merge of two exact commits, no rebase/rewrite/force/two-dot patch:

  • head 7245b7a8f91fa71217442b73d9b08e9135c3d27d — the doom-loop per-step repair on top of the accepted baseline, which also removes four unaccepted seed owner-death test files (that seed PR is closed and the baseline never contained them).
  • tip 4a08a04b100834757008ebf6582e8adac6c1c56b — the merged test(opencode): preload config before permission waits (Refs #489, #732) #751 permission flake reduction.

Blobs preserved byte-for-byte: test/permission/next.test.ts and test/permission/timeout.test.ts (#751), src/util/activity.ts and both activity tests (#735), and the CLI retry fixtures test/cli/run/run-retry-wait.test.ts, test/cli/run/run-process.test.ts, test/lib/llm-server.ts. src/session/processor.ts is byte-identical to the reviewed head.

The only change this branch adds on top is the review follow-up: the independent review killed 11 of 15 mutants with no logic defect, but M14 (deleting the input comparison from isRepeatedFailureStep) survived all 42 tests, because every existing streak case either varies the tool name or keeps the input identical. The new P4 probe runs six consecutive steps whose single failing lookup call uses inputs same, same, different, same, same, same: the one differing input sits inside the two-step window of every call up to the fifth send, so nothing may ask, and the sixth send is the first whose two predecessors are the identical call. Name-only matching asks on the third send and fails there.

M10/M11 (the two retry-path resets, priorStepsMemo and doomLoopAskedSteps) are equivalent mutants rather than gaps, so no test was added for them: both resets run only at the top of a retry attempt, and a retry only happens when the failed attempt had no tool activity (sawToolActivity false). The guard and loadPriorSteps are reachable only from the tool-call path, which sets sawToolActivity and whose failures become a non-retryable StreamInterruptedAfterToolCallError, so the mutated state is always empty/undefined when those lines run. No assertion, timeout or budget was weakened or reordered.

How did you verify your code works?

  • bun test --timeout 30000 test/session/processor-effect.test.ts (packages/opencode): 43 pass, 0 fail, 205 expect() calls (was 42).
  • Mutation control on this exact tree: with the input comparison deleted, bun test -t "doom loop" goes red on exactly the new test (3 unexpected asks, Expected length: 0) while all 12 pre-existing doom tests still pass; reverting restores 43/43. src/session/processor.ts is byte-identical to the head blob afterwards.
  • Preserved suites re-run here: test/permission/next.test.ts + test/permission/timeout.test.ts 98 pass; packages/tui activity suites 59 pass; test/cli/run/run-retry-wait.test.ts + test/cli/run/run-process.test.ts 27 pass.
  • oxlint packages/opencode/src/session/processor.ts packages/opencode/test/session/processor-effect.test.ts: 0 errors (11 pre-existing warnings, unchanged).
  • Typecheck: tsc --noEmit over a scoped project containing exactly src/session/processor.ts and test/session/processor-effect.test.ts (plus the project's ambient src/audio.d.ts) is clean, 0 errors. The full-package tsc --noEmit could not complete in this 3 GB sandbox — it aborts at the V8 heap limit at the default size and at 2.6 GB, and tsgo is OOM-killed — so the package-wide leg is left to CI, which runs it with the usual runner memory.

Screenshots / recordings

N/A — backend session processor logic only.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

arena-agent and others added 12 commits October 31, 2026 09:38
…#442)

win32-gated integration coverage that runs on the existing windows-latest
matrix leg and exercises the real spawn path bound to the Job Object: the
owner is force-killed with TerminateProcess and the worker tree is then
verified gone through real process inspection (OpenProcess + tasklist),
with both listening ports probed for release.

Two properties are covered:

- happy path: a force-killed owner takes the worker tree and its listening
  ports with it; incremental identity capture off the Bun.spawn handle
  (worker -> child -> child-port -> ready) means every PID is known as soon
  as it is created, so cleanup can reap a tree that never finished starting.
- stall path: the grandchild binds its port but never writes its ready line
  (SILVERCODE_TEST_GRANDCHILD_SILENT=1), so the bounded identity wait must
  fail at the deadline rather than hang, and the half-built tree must still
  leave nothing behind. Anti-vacuous-pass guards assert both PIDs were
  captured and grandchildPort stayed undefined, so a slow startup cannot
  masquerade as the stall.

All waits are hard-bounded (tasklist capped to the remaining budget, socket
probes 2s, cleanup raced against its own budget). The stall test sets its own
per-test timeout; the package default --timeout 30000 is unchanged.

Tests and fixtures only - no production or workflow changes. Existing #561
and #568 unit tests are untouched.

Co-authored-by: arena-agent <[email protected]>
unit (windows) failed at 366f0a9. The stall test's identity wait consumes
STALL_BUDGET_MS by design - `ready` is suppressed, so the bounded promise
never settles - which left the original `deadline` in the past for every
phase that followed:

  tasklistHasPid(pid, deadline)
    -> Math.max(1, Math.min(15000, negative)) = 1ms allowance
    -> exitedDueToTimeout, so it throws instead of reporting the pid
  bounded(owner.exited, ..., deadline)
    -> Math.max(0, negative) = 0ms allowance
    -> rejects with "the owner never exited after TerminateProcess"
       before the owner has had time to die

Reproduced directly: after the identity wait the remainder is -1ms, and a
0ms bounded rejects a promise that settles 30ms later, while the same
promise resolves against a fresh deadline.

The happy-path test was never affected because its bounded(treeReady)
resolves early and leaves most of the budget intact. Local verification
missed this because the Linux harness substitutes process.kill(pid, 0) for
tasklist and already used fresh deadlines.

Every phase after the identity wait now runs on its own fresh deadline:
STALL_PROBE_MS (15s) for pre-kill liveness and the owner's exit, and
STALL_VERIFY_MS (20s) for post-kill verification. STALL_BUDGET_MS is raised
15s -> 40s to match the budget already proven comfortable on windows-latest,
so a slow cold start cannot make the anti-vacuous-pass guards fire. The
per-test timeout follows the arithmetic: 40 + 15 + 20 + 5 cleanup = 80s,
so STALL_TEST_TIMEOUT_MS = 90_000. The package default --timeout 30000 is
still untouched. No assertion was weakened or reordered.

Co-authored-by: arena-agent <[email protected]>
…t await throws

unit (windows) at 34d8f92 failed the stall test at
win-owner-death.integration.test.ts:507:102 - inside `.rejects.toThrow(` -
with `Received message: "The user aborted a request"`.

That line was the first statement of the `try`. Asserting the bounded
identity wait inline means ANY rejection there throws straight out of the
test, so every post-timeout assertion is skipped and the "leaves nothing
behind" property - the whole point of the test - is never verified.

Reproduced both halves locally:

- before: injecting that rejection makes the test bail immediately with
  zero assertions executed and no cleanup verification
- after: 7 cleanup/safety assertions run and pass (no survivors, both PIDs
  gone, both absent from the process list, worker port closed and
  rebindable), and only then does the diagnostic assertion report
  `Received: "The user aborted a request"`

Structure is now capture -> kill -> verify -> clean up -> assert. The
outcome of the identity wait is captured instead of asserted inline; probes
are wrapped so a wedged one yields its message (which then fails the
assertion consuming it) rather than either throwing early or being silently
read as "absent"; `settled()` is the non-throwing form of `until()`. Cleanup
runs before the assertions, so no failed assertion can leave a live process
on the runner.

The FETCH_ABORTED itself is not produced by this test. Verified: there is no
fetch, AbortController or abort signal anywhere in the four files;
make-fetch-happen, minipass-fetch and npm-registry-fetch are absent from the
entire repository; and bounded(treeReady, ...) can only ever reject with its
own message, because treeReady has no reject path. Locally the identity wait
rejects with exactly "the worker never reported its identity" and the
assertion passes. So this commit does not claim to fix the source of that
error - it makes the test survive it, verify what it exists to verify, and
report the unexpected message precisely.

No budget or timeout changed: STALL_BUDGET_MS stays 40_000,
STALL_TEST_TIMEOUT_MS stays 90_000, and the package default
(--timeout 30000) is untouched. No assertion was removed or weakened.

Co-authored-by: arena-agent <[email protected]>
…, harden deadlines

Applies the independent review verdict on 34d8f92.

Budget envelope. The 90s per-test timeout was a consequence of raising
STALL_BUDGET_MS from 15s to 40s, not of the negative-allowance fix. With a
fresh deadline per phase the fix stands on its own, so the raise is
reverted: STALL_BUDGET_MS 40_000 -> 15_000 and STALL_TEST_TIMEOUT_MS
90_000 -> 45_000, back inside the previously accepted 40/50 envelope. No
new deviation. Verified locally on a Linux-runnable copy of the real file:
the stall test now completes in 15.09s and both tests pass.

The timeout comment claimed 40+15+20+5=80s and omitted the `finally`
reapTree. It now gives the arithmetic by case instead of one sum: nominal
~21s, worst single-phase-failure 15+3+20+5=43s which fits, and the one
path that does not fit - probe AND verify phases both exhausting their
ceilings, 55s - where the timeout fires and the test fails loudly rather
than hanging.

Deadline guards. `bounded` and `tasklistHasPid` no longer clamp a spent
deadline to 0ms/1ms, which reported "the thing never happened" when the
real cause was "the caller's budget was already gone". Both now throw a
distinct "deadline already expired" error. Covered by a test that asserts
the exact messages, so the guard cannot rot silently.

PID-recycling guard. `reapTree` now takes the set of PIDs this test already
proved dead and skips them: a recycled PID would otherwise be signalled,
killing something the runner needs. The survivor check applies the same
guard, so a reused PID cannot be reported as a false survivor. Survivors
are also now computed BEFORE the manual reap, so the assertion proves the
job took the tree down rather than that our own cleanup did.

Positive log control. The adopter only logs on failure, so a clean run
produces no `log:` messages at all - which let the "(#442)"-free assertion
pass vacuously if IPC forwarding broke. The owner fixture now sends a
`log:owner-log-channel-ok` sentinel and both tests assert it arrived, so an
empty log is a failure rather than a pass.

No assertion removed or weakened; the package default --timeout 30000 is
untouched.

Co-authored-by: arena-agent <[email protected]>
…next commit)

Temporary, deliberately broken commit. `adoptWorkerProcess` no longer calls
the adopter, so a spawned worker is never put into the owner's kill-on-close
Job Object - i.e. the state #561/#568 exist to prevent.

Expected: unit (windows) goes RED on the owner-death tests' survivor
assertion, because a force-killed owner no longer takes the worker tree
down. If those tests still passed with the binding disabled they would be
proving nothing.

win-job's own 21 unit tests still pass under this mutation because they
drive `createOwnerJobAdopter` directly rather than `adoptWorkerProcess`, so
the red signal is isolated to the integration coverage.

Reverted in the next commit.

Co-authored-by: arena-agent <[email protected]>
Review item (b) covered the happy path's `owner.exited` as well as the stall
test's, and only the stall test had been converted. The happy path still
passed its original `deadline` to ten calls - `tasklistHasPid` four times,
`bounded(owner.exited)`, `until` four times and `bounded(canBind)` twice.
Those were tolerable while a spent deadline merely clamped to a 1ms/0ms
allowance; once the distinct expiry guard landed, every one of them became a
hard throw as soon as the budget was spent.

Both tests now use `deadline` for exactly one thing - the identity wait - and
take a fresh `PROBE_BUDGET_MS` (15s) for the pre-kill liveness and owner exit
and a fresh `VERIFY_BUDGET_MS` (20s) for everything after the kill. The two
constants were renamed out of their stall-specific names because both tests
use them; their values are unchanged, so no budget was raised.

Verified on a Linux-runnable copy of the real file with the Job Object
contract emulated: both tests pass, the stall test completing in 15.10s, 33
expect() calls.

Co-authored-by: arena-agent <[email protected]>
Three-way merge of the exact doom-repair head 7245b7a
into this branch. No rebase, no rewrite, no force, no two-dot patch.

The merge inherits:
- fix(opencode): count doom-loop failures per step (#725) in
  packages/opencode/src/session/processor.ts, with its session tests.
- the accepted integration baseline 2e94981: #735 activity-kind work blocks
  and the CLI retry fixtures, preserved byte-for-byte.
- removal of the four unaccepted seed owner-death test files, which the
  head commit already deleted and which exist nowhere on the baseline.

Co-authored-by: arena-agent <[email protected]>
… base

Three-way merge of the exact integration tip
4a08a04. Merge base is 2e94981, so this
adds only the preloaded-config permission waits in next.test.ts and
timeout.test.ts. Blobs are preserved byte-for-byte.

Co-authored-by: arena-agent <[email protected]>
…725)

Independent review of the merged head killed 11 of 15 mutants and found no
logic defect, but the M14 mutant - deleting the input comparison from
`isRepeatedFailureStep` - survived all 42 tests. Every existing streak case
either varies the tool name (a different tool) or keeps `lookup`'s input
identical, so name-only matching was still consistent with all of them.

P4 probe: six consecutive steps whose single `lookup` call fails every time,
with inputs `same, same, different, same, same, same`. The one differing
input is inside the two-step window of every call up to the fifth send, so
nothing may ask; the sixth send is the first whose two predecessors are the
identical call. The test therefore fails if the guard compares names only
(it asks on the third send) and proves both the name and the input must match
for a step to count as a repetition.

Mutation control on this tree: with the input comparison deleted,
`bun test -t "doom loop"` goes red on exactly this test (3 unexpected asks,
`Expected length: 0` at the fifth-send assertion) while all 12 pre-existing
doom tests still pass; reverting restores 43/43.

Full file: 43 pass, 0 fail, 205 expect() calls.

Co-authored-by: arena-agent <[email protected]>
@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants