Skip to content

test(opencode): bound Miniflare worker startup and name its timeout - #178

Merged
ualtinok merged 2 commits into
cortexkit:mainfrom
iceteaSA:fix/miniflare-ready-bound
Sep 2, 2026
Merged

test(opencode): bound Miniflare worker startup and name its timeout#178
ualtinok merged 2 commits into
cortexkit:mainfrom
iceteaSA:fix/miniflare-ready-bound

Conversation

@iceteaSA

@iceteaSA iceteaSA commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Fixes #176.

relay-worker-miniflare.test.ts fails on shared runners with a 30s timeout and workerd ... Broken pipe, hitting a different test in the file each time — three CI hits on one branch today (runs 33495627135, 33508661808, 33509080794), while solo runs pass 4/0 in under a second every time. The websocket logic was never the problem: each of the four tests constructed and awaited its own Miniflare instance inside the per-test 30s budget, so worker startup contention under parallel suite load ate the timeout and misattributed the failure to whichever test ran.

Two changes, both from the issue:

  • One shared Miniflare instance per file, started in beforeAll with its own 90s hook timeout and disposed in afterAll. Startup no longer competes with (or bills against) any test's budget, and three of the four startups disappear entirely.
  • Every ready await goes through a bounded helper that throws Miniflare worker startup timed out under load (issue #176) — not a websocket-logic failure on expiry. If a runner is ever slow enough to blow a 90s startup budget, the failure now says what it is instead of masquerading as a websocket assertion.

The timer is cleared once the race settles, so the loser can't fire into a later test.

Verification: solo run 5/0 (the fifth is a new deterministic test driving the helper with a 1ms budget against a never-ready stub and asserting the named error). Full root suite 3/3 green post-fix with the miniflare file passing all three. Honest caveat: the load-dependent failure would not reproduce on demand in a pre-fix baseline (two runs) — it never does when you want it to — so acceptance rests on the deterministic named-error path plus the 3× green, not on a reproduced red.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Summary by cubic

Fixes #176. Makes relay-worker-miniflare.test.ts reliable on shared CI runners by sharing one Miniflare instance per file and bounding startup with a self-describing timeout. Previously, each test started its own worker inside the 30s test budget, so startup contention on parallel runners blew the timeout and got misattributed to whichever test ran.

  • Starts one Miniflare instance per file in beforeAll with a dedicated 90s hook timeout, then disposes it in afterAll; tests assert only the upstream bodies they added, since bodies accumulate on the shared instance.
  • Routes every ready await through a bounded helper that throws a named error on expiry instead of surfacing as a websocket assertion, and disposes timed-out workers so cleanup preserves that error.
  • Adds a deterministic test that drives the helper with a 1ms budget against a never-ready stub.

Written for commit cfab9a9. Summary will update on new commits.

Review in cubic

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 1 file

Architecture diagram
sequenceDiagram
    participant Runner as Test Runner
    participant Hooks as File Lifecycle Hooks
    participant Wait as Bounded Ready Helper
    participant MF as Shared Miniflare Worker
    participant Relay as Relay Worker
    participant Upstream as Upstream Stub

    Note over Runner,Upstream: Current-state relay-worker-miniflare test architecture

    Runner->>Hooks: beforeAll()
    Hooks->>MF: Create one worker instance
    MF->>MF: Start workerd process
    Hooks->>Wait: Await worker readiness with 90s budget
    Wait->>MF: Await ready
    MF-->>Wait: Worker URL
    Wait-->>Hooks: Ready
    Hooks-->>Runner: Test file initialized

    loop Each relay test
        Runner->>Wait: Await shared worker readiness
        Wait->>MF: Await ready with bounded timeout
        MF-->>Wait: Worker URL
        Wait-->>Runner: Ready URL

        alt HTTP relay path
            Runner->>Relay: sendViaRelay(HTTP, token, auth, affinity, body)
            Relay->>MF: HTTP request
            MF->>Upstream: Forward request and headers
            Upstream-->>MF: Response and quota headers
            MF-->>Relay: Relay response
            Relay-->>Runner: Response
        else WebSocket relay path
            Runner->>Relay: sendViaRelay(WebSocket, token, auth, affinity, body)
            Relay->>MF: Connect to worker WebSocket
            MF->>Upstream: Forward full_sync or patch request
            Upstream-->>MF: Response and quota headers
            MF-->>Relay: WebSocket control messages
            Relay-->>Runner: Reconstructed response
        end
    end

    alt Worker startup exceeds readiness budget
        Wait-->>Runner: Error: Miniflare worker startup timed out under load (issue #176) - not a websocket-logic failure
    else Deterministic never-ready check
        Runner->>Wait: Await never-ready stub with 1ms budget
        Wait-->>Runner: Named startup timeout error
    end

    Runner->>Hooks: afterAll()
    Hooks->>MF: Dispose shared worker
    MF->>MF: Stop workerd process
    Hooks-->>Runner: File resources released

    Note over Wait: Readiness timer is cleared when the race settles
Loading

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread packages/opencode/src/tests/relay-worker-miniflare.test.ts Outdated
@iceteaSA
iceteaSA force-pushed the fix/miniflare-ready-bound branch from 041d4ad to 4fc2bf8 Compare September 1, 2026 13:39

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 1 file (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread packages/opencode/src/tests/relay-worker-miniflare.test.ts Outdated
Comment thread packages/opencode/src/tests/relay-worker-miniflare.test.ts Outdated
Comment thread packages/opencode/src/tests/relay-worker-miniflare.test.ts Outdated
@iceteaSA
iceteaSA force-pushed the fix/miniflare-ready-bound branch from 7486921 to cfab9a9 Compare September 2, 2026 07:28
@ualtinok
ualtinok merged commit f83cf4a into cortexkit:main Sep 2, 2026
5 checks passed
rustybret pushed a commit to rustybret/anthropic-auth that referenced this pull request Sep 2, 2026
cb282b0 feat(core): publish per-field quota provenance in the header feed (cortexkit#172)
f83cf4a test(opencode): bound Miniflare worker startup and name its timeout (cortexkit#178)
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.

relay-worker-miniflare tests hang on unbounded mf.ready under suite load

2 participants