Skip to content

test(memory): explain worker verify failures - #2172

Merged
justinhelmer merged 1 commit into
mainfrom
plan/fix-issue-2119-by-instru-9c412d/u1
Sep 21, 2026
Merged

justinhelmer merged 1 commit into
mainfrom
plan/fix-issue-2119-by-instru-9c412d/u1

Conversation

@coreplane-switchboard

@coreplane-switchboard coreplane-switchboard Bot commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Memory Worker tests now record per-case timing, pool identity, unfinished work, and async escapes. CI always uploads the diagnostic table so the next failure identifies its source instead of a random victim.

Why: Issue #2119 kept timing out different tests after two real leaks were fixed, so another guessed fix would hide evidence. This instrumentation-first change distinguishes shared-pool contention from unfinished work without raising the timeout.

Where to look

  1. Unhandled-rejection attribution Installs one suite-wide rejection trap that names the test active when an escaped promise rejects. ⚠ A missed runtime event surface would leave rejections unattributed.
  2. Per-test async boundary Snapshots pool identity, task promises, and timers into metadata, then fails and clears unfinished work at its owner. ⚠ Over-broad timer tracking could false-fail valid Worker tests.
  3. Diagnostic artifact reporter Collects every result into the JSON table and writes it when the run ends green, red, or interrupted. ⚠ If run-end handling fails, CI has no artifact to upload.
  4. Always-run CI upload Uploads memory diagnostics after success or failure and retains retry attempts under distinct artifact names.
  5. Secure fixture workspace Creates each nested Vitest workspace atomically so temporary paths cannot be pre-created or redirected.
  6. Green reporter fixture Runs a nested Vitest fixture and proves the artifact row and slowest-test summary are emitted.
  7. Memory pool contract Binds the artifact, traps, originating guards, and ten-run receipt to the release-and-deploy specification.

Feedback wanted: Check whether task metadata survives every workerd failure mode and whether the table distinguishes serial-pool contention from unfinished operations.

Risk: This is 522 changed lines; splitting reporter, traps, and fixtures was considered, but CI upload and proof need to land atomically. A bad trap can false-fail only memory Worker tests; revert the commit to roll back.

Verified: Focused suites and scoped gates passed. Fresh CodeQL and memory Worker CI verify passed; the ten-main-run receipt remains human-gated.

Decisions (4)
  • Instrument before changing pool isolation. Four different victims remained after two real leak fixes. The evidence does not justify per-file pool isolation or another awaited call, so the shared serial pool stays until a red artifact identifies contention or unfinished work.
  • Transport diagnostics through test metadata. Vitest 4's Cloudflare runner rejects context.annotate from afterEach because the result is already complete. Custom task metadata is designed for reporters and was proven to survive the workerd boundary.
  • Retain every retry attempt. A green retry must not overwrite the first red evidence. The artifact name includes github.run_attempt, preserving each attempt within the workflow run.
  • Fail timers at their owner. Allowing an open timer to fire later would blame a neighbour. The boundary records and clears it after failing the owner, while the callback trap still names both owner and active test if one escapes.
Validation (11 criteria)
Criterion Proof
Reporter, timer, and rejection traps work through nested Vitest fixtures npx vitest run deploy/cloudflare-memory/backgroundTasks.test.ts src/ciWorkflow.test.ts src/memoryWorkerDiagnostics.test.ts → 2 root files, 110 tests passed; exit 0.
The workerd background-task guard reports registrations and pending promises npm test -w deploy/cloudflare-memory -- backgroundTasks.test.ts → 1 file, 1 test passed; diagnostic slowest line emitted; exit 0.
Root TypeScript accepts the workflow and fixture tests NODE_OPTIONS=--max-old-space-size=6144 npx tsc --noEmit -p tsconfig.json → exit 0.
Memory Worker TypeScript accepts reporter, protocol, and trap code NODE_OPTIONS=--max-old-space-size=6144 npx tsc --noEmit -p deploy/cloudflare-memory/tsconfig.json → exit 0.
Changed files match repository formatting npx prettier --check <13 changed supported files> → all matched files use Prettier code style; exit 0.
The secure temporary-workspace fix passes lint and CodeQL npx eslint src/memoryWorkerDiagnostics.test.ts passed; CodeQL check 106541457918 completed successfully.
Public-tree hygiene stays at its ratchet npm run hygiene:check → 9 files and 37 listed hits accepted; exit 0.
Every spec proof resolves npm run specs:check → 51 specs and 5,661 proof references checked; exit 0.
Changed paths remain covered without removing verification npm run specs:coverage -- --changed origin/main...HEAD --test-guard → all paths covered; test-guard passed; exit 0.
Memory Worker CI verify remains green with diagnostics enabled ci / workers / verify deploy/cloudflare-memory check 106541445542 completed successfully at pushed head.
PR title satisfies the changelog gate npm run check:pr-title -- "test(memory): explain worker verify failures" → passed; exit 0.
For agents

Rebased cleanly onto origin/main and force-pushed one coherent commit at 10135fb. The CodeQL review fix replaces predictable temp-path creation with atomic mkdtempSync; all four alerts originated from that helper, and the fresh CodeQL check passed. No leak or pool-isolation change is included: the first red artifact must decide that seam. The CI artifact is memory-test-diagnostics-${github.run_attempt}.
Requested by @justinhelmer in slack:C0BRRHKFLCB

🤖 Generated with Claude Code

Comment thread src/memoryWorkerDiagnostics.test.ts Fixed
Comment thread src/memoryWorkerDiagnostics.test.ts Fixed
Comment thread src/memoryWorkerDiagnostics.test.ts Fixed
Comment thread src/memoryWorkerDiagnostics.test.ts Fixed

@coreplane-switchboard coreplane-switchboard Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

LGTM: The instrumentation, always-uploaded artifact, async traps, tests, and spec row satisfy the unit without weakening existing guards.

Note

Approved · head af78d82 · no findings

Full review

No findings. The change satisfies the instrumentation-first contract and preserves existing guards.

@github-actions github-actions 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.

Auto-approved: coreplane-switchboard[bot] reviewed this PR and posted an LGTM verdict (see its review). This repository opted in through its REVIEW_BOT_LOGIN and REVIEW_BOT_ID variables.

Co-Authored-By: coreplane-switchboard[bot] <318072483+coreplane-switchboard[bot]@users.noreply.github.com>
@coreplane-switchboard
coreplane-switchboard Bot force-pushed the plan/fix-issue-2119-by-instru-9c412d/u1 branch from af78d82 to 10135fb Compare September 21, 2026 22:26

@coreplane-switchboard coreplane-switchboard Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

LGTM: The CodeQL finding is resolved by atomic temporary-directory creation, with no unresolved or new findings.

Note

Approved · head 10135fb · no findings

Full review

The prior CodeQL finding is resolved by atomic mkdtempSync directory creation; no findings remain.

@github-actions github-actions 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.

Auto-approved: coreplane-switchboard[bot] reviewed this PR and posted an LGTM verdict (see its review). This repository opted in through its REVIEW_BOT_LOGIN and REVIEW_BOT_ID variables.

@coreplane-switchboard coreplane-switchboard Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

LGTM: The diagnostics, CI artifact upload, regression coverage, and spec update are consistent and no blocking issue remains.

Note

Approved · head 10135fb · no findings

Full review

No findings. The diagnostics, CI artifact upload, regression coverage, and spec update are consistent.

@github-actions github-actions 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.

Auto-approved: coreplane-switchboard[bot] reviewed this PR and posted an LGTM verdict (see its review). This repository opted in through its REVIEW_BOT_LOGIN and REVIEW_BOT_ID variables.

@justinhelmer
justinhelmer merged commit 4bf464f into main Sep 21, 2026
31 checks passed
@justinhelmer
justinhelmer deleted the plan/fix-issue-2119-by-instru-9c412d/u1 branch September 21, 2026 22:38
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.

2 participants