Skip to content

fix(test): dag-node-supervision long-running tests time out under bare bun test (no --timeout flag) #384

Description

@LeXwDeX

Problem

Three tests in packages/opencode/test/dag/dag-node-supervision.test.ts need 15-30s wall time by design (2s deadline × escalation windows + dispose + sweep passes), but they declare no per-test timeout. bun's default per-test timeout is 5s, so any bare focused invocation (bun test test/dag/dag-node-supervision.test.ts) red-fails them even though they are green under the package's canonical runner (bun test --timeout 30000, packages/opencode/package.json:10) and in CI (Unit Tests (linux) green on #382/#383).

The file even documents the trap in a comment (lines 242-243): "bun's default per-test timeout is 5s; several bodies here need 8-40s at a 2s deadline — run this file with --timeout 30000" — a comment-only contract that direct invocation bypasses.

User Impact

Developer/agent footgun with real cost already paid once: a focused test run shows 3 failures that look like regressions, triggering wasted triage (up to and including stash-cycles to "verify on clean main") and risking an agent "fixing" non-bugs. False red signal on the exact file that guards the production-incident supervision invariants.

Evidence

  • Failing under bare invocation (default 5000ms):
    • dispose-instance: instance teardown mid-run freezes durable supervision (~15s needed: escalate poll + 4s settle sleep + sweep loop)
    • cancel-defect: a dying cancel seam ... never blocks the settle (~15s needed)
    • freeze window: a live watcher is never swept (~12s needed: escalate + 4 × 2.3s spaced sweep passes)
  • bun test test/dag/dag-node-supervision.test.ts → 8 pass / 3 fail, each failure "timed out after 5000ms"
  • bun test --timeout 30000 test/dag/dag-node-supervision.test.ts → 11 pass / 0 fail (30.7s)
  • packages/opencode/package.json:10: "test": "bun test --timeout 30000 --only-failures" — the canonical entry CI uses
  • Test file comment packages/opencode/test/dag/dag-node-supervision.test.ts:242-243 admits the flag dependency
  • The shorter siblings (healthy, stream-hang) pass bare because their polls succeed at ~2-3s — masking the trap until one of the three long tests runs

Fix Requirements

  1. Declare the timeout on the tests themselves: pass the third timeoutMs argument to it(...) (bun:test per-test timeout, long-supported) with a value of 30000 for the three long tests (dispose-instance, cancel-defect, freeze window).
  2. Alternative shape (implementer's choice if verified against bun 1.3.x): a describe-level setTimeout for the incident describe block — but per-test third-arg is the safest documented form.
  3. Keep the comment at lines 242-243 in sync (or reduce it to point at the declared timeouts).
  4. No test-logic, poll-budget, or assertion changes.

Non-goals

  • No repo-wide test-timeout policy change, no bunfig.toml default bump (a global default change would silently extend genuinely-hung tests everywhere).
  • No changes to the canonical test script or CI invocation.
  • No supervision-sweep/spawn production-code changes — the runtime is healthy; this is purely test-invocation ergonomics.

Acceptance Criteria

  • bun test test/dag/dag-node-supervision.test.ts (no flags) → 11 pass / 0 fail.
  • bun run test (canonical, with --timeout 30000 --only-failures) → still green for this file.
  • The three tests carry an explicit per-test timeout visible in the diff.

Likely Code Locations

  • packages/opencode/test/dag/dag-node-supervision.test.ts (the three it(...) blocks at ~lines 301, 364, 408)

Verification

cd packages/opencode
bun test test/dag/dag-node-supervision.test.ts                  # bare: must be 11 pass / 0 fail
bun test --timeout 30000 test/dag/dag-node-supervision.test.ts  # canonical: unchanged green

Metadata

Metadata

Assignees

No one assigned

    Labels

    ready-for-agentFully specified and ready for an agent

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions