Skip to content

Fix flaky partial merge shutdown test: wait for its own request - #63

Merged
mchwang merged 1 commit into
mainfrom
fix/partial-request-shutdown-flake
Sep 27, 2026
Merged

mchwang merged 1 commit into
mainfrom
fix/partial-request-shutdown-flake

Conversation

@mchwang

@mchwang mchwang commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Problem

blocks a partially received merge request when shutdown starts failed about 1 in 5 runs on main. The errors were connect ECONNRESET 127.0.0.1:<port>, then Server is not running.

Cause

The test was wrong; the server is correct. requestAdmitted() resolved on the server's first 'request' event from any client. When another client reached the port first, the test called close() before the server had accepted its own partial merge request. Examples of another client: a polling tab, or a pooled connection to a reused ephemeral port.

  • The listener closed while the test's connection was still in the accept queue. The client saw connect ECONNRESET (the connect syscall shows that the server never accepted the connection).
  • Server is not running is a side effect. The test threw before its last line restarts the server, so afterEach closed an already-closed server.

close() in web/server.ts works as designed: it blocks new work, bounds the drain, and aborts active requests.

Fix

This PR changes only test/browser/review.spec.ts.

  • requestAdmitted() now returns a unique x-codeboost-test-request header. It resolves only when the server parses the headers of the request that carries that header. The three partial-request shutdown tests use it.
  • Regression: before its partial request, the merge test sends a complete request from another client (GET /api/settings).

Evidence

Results on head a2328a0:

Check Result
Regression with the old helper Fails every run with connect ECONNREFUSED (or ECONNRESET), then Server is not running
Regression with the new helper Passes
Mutation: disable the shutdown merge guard at web/server.ts:58 The test fails (expected 503, received 409), so the guard is still covered
Flaky test, --repeat-each 20 20/20 pass
Full Playwright suite 58/58 pass
npm run typecheck Clean
Vitest 3 failures, all in test/agent-supervisor.test.ts: Docker container tests that time out at 60 s on the local host. Vitest includes only test/*.test.ts, so it does not load the changed file.

I could not reproduce the original flake naturally. It did not occur in 40 Playwright runs under CPU load or in 320 standalone harness runs. The deterministic regression reproduces the same failure signature.

Review-lesson audit

Covered by the existing rule in AGENTS.md "Required race regressions": A request is partially received, then shutdown starts, then the request completes. This PR adds no new rule.

Review rounds

  • Round 1 (Copilot, head a2328a0): no findings; Copilot recommended approval. Nothing changed and nothing was declined.

🤖 Generated with Claude Code

requestAdmitted() resolved on the server's first 'request' event from any
client. When another client reached the port first (a polling tab or a
reused ephemeral port), the test started shutdown before the server had
accepted its own partial merge request. The listener then closed with that
connection still queued, so the client saw "connect ECONNRESET", and
afterEach reported "Server is not running."

The helper now tags each partial request with a unique header and resolves
only when that request's headers are parsed. The merge test sends a foreign
request first as a deterministic regression: it fails with the old helper
and passes with the new one. The 503 and zero-merge assertions are
unchanged; disabling the server's shutdown merge guard still fails the test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings September 26, 2026 19:28

Copilot AI 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.

Copilot review overview

🟢 Approval recommended

No unresolved review issues remain.

Review effort: Lite
Findings: None

What changed in this PR

Fixes flaky shutdown tests by ensuring they wait for admission of their own marked request.

Changes:

  • Adds unique request markers to requestAdmitted().
  • Applies markers to partial-request shutdown tests.
  • Adds a competing request regression scenario.
File Description
test/​browser/​review.spec.ts Makes shutdown request-admission tests deterministic.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@mchwang
mchwang merged commit 27802ef into main Sep 27, 2026
2 checks passed
@mchwang
mchwang deleted the fix/partial-request-shutdown-flake branch September 27, 2026 03:00
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