Skip to content

Conversation

@ammar-agent
Copy link
Collaborator

Fixed flaky test should persist init state to disk for replay across page reloads.

Root Cause

Race condition in InitStateManager.endInit():

  1. In-memory state was updated (exitCode) synchronously
  2. Then persist() was awaited to write to disk
  3. But logComplete() called endInit() with void (fire-and-forget)

If replay happened while persist() was still running, it would see exitCode !== null but the file wouldn't exist yet.

Fix

Persist state BEFORE updating in-memory exitCode, ensuring the invariant: if init-end is visible (live or replay), the file MUST exist.

Validation

  • Test passes consistently (5 consecutive runs)
  • All init tests pass
  • Full static-check passes

Generated with mux

@chatgpt-codex-connector
Copy link

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

Fixed flaky test 'should persist init state to disk for replay across page reloads'.

Root cause: endInit() updated in-memory state (exitCode) before persist completed.
When called with void (fire-and-forget), replay could see exitCode !== null but
file didn't exist yet.

Fix: Persist state BEFORE updating in-memory exitCode, ensuring the invariant
that if init-end is visible (live or replay), the file MUST exist.

Also added AGENTS.md guideline about void async calls hiding race conditions.
@ammario ammario merged commit 5111e24 into main Dec 10, 2025
20 checks passed
@ammario ammario deleted the fix-init-state-persist-flake branch December 10, 2025 02:14
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