Skip to content

test(codex): de-flake attempt turn-watch timing tests - #115258

Merged
steipete merged 1 commit into
mainfrom
steipete/festive-gould-dceb42
Jul 28, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/festive-gould-dceb42

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Three timing tests in extensions/codex/src/app-server/run-attempt.turn-watches.test.ts race a real wall-clock progress source against a short watchdog budget. This is the same flake class fixed for the OpenAI transport in #115196.

The headline case is "keeps a progressing active turn alive beyond the original attempt timeout". It set params.timeoutMs = 100 — which is the attempt idle watchdog, floored at 100ms by run-attempt-turn-state.ts:99 — and paced two rawResponseItem/completed notifications with real 60ms sleeps.

The static margin looks like 40ms per gap, but it is much thinner than that. The attempt watch is armed at turn:start inside the attempt (run-attempt-active-turn.ts:117-118), tens of ms before await harness.waitForMethod("turn/start") returns, so the test's 60ms sleep is measured from a point the watchdog clock has already passed. Instrumenting the test showed the first gap consuming 66-77ms of the 100ms budget as measured by the test, while the controller reported idleMs of 101-130 against timeoutMs: 100.

Why This Change Was Made

The behavior under test is worth keeping, so all three tests are hardened rather than deleted or loosened.

:764 progressing turn — attemptIdleTimeoutMs 100 -> 1000 and the progress interval 60ms -> 50ms, moving the gap/budget ratio from ~1.7x to 20x. The fixed reasoningChunkCount-style pair of notifications becomes a wall-clock loop that emits progress until the phase exceeds the watchdog, so "the turn outlived the original attempt timeout" holds by construction on a slow runner instead of being an implicit product of two constants. The exact-count assertion is preserved as toHaveLength(sentProgressNotifications) — still one progress reason per notification, just no longer pinned to a hardcoded 2.

:1164 pending user input — this one was both fragile and nearly vacuous: it asserted no interrupt at roughly t=200ms against a 250ms budget, so a correct-but-slow run failed while a broken one could pass. Reading run-attempt-server-requests.ts showed a pending item/tool/requestUserInput records attempt progress but never suppresses the attempt watch, so the provable property is that the turn outlives the deadline turn:start alone would have set. That needs preRequestIdleMs + pendingHoldMs > attemptIdleTimeoutMs > pendingHoldMs, and both bounds are now asserted explicitly, so load cannot silently make it vacuous in either direction.

:168 reschedule-on-shortened-timeout — this one drives createCodexAttemptTurnWatchController directly with no attempt runtime, so vi.useFakeTimers() transfers cleanly from the sibling attempt-turn-watches.test.ts. The vi.waitFor(..., { timeout: 120 }) race against a 40ms deadline is replaced with advanceTimersByTimeAsync, making it fully deterministic.

Evaluated and deliberately left alone: :1016 (timeoutMs = 500 vs a 60ms sleep, ~8x margin) and :1096 (turnCompletionIdleTimeoutMs: 15 exceeded by design, which is already the robust construction). Neither showed risk, and churning them would add diff without removing a failure mode.

User Impact

None. Test-only change; no production code is touched.

Evidence

Codex protocol gate. Verified the surfaces these tests exercise against sibling ../codex at 899539c03a (harness pinned to @openai/codex 0.145.0):

  • rawResponseItem/completed notification — codex-rs/app-server-protocol/src/protocol/common.rs:1682
  • item/tool/requestUserInput server->client request (has both params and response, so the app-server blocks on our answer) — codex-rs/app-server-protocol/src/protocol/common.rs:1513-1516, sent at codex-rs/app-server-client/src/lib.rs:1866
  • isSecret question field — codex-rs/protocol/src/request_user_input.rs:23-26
  • turn/interrupt client->server request — codex-rs/app-server-protocol/src/protocol/common.rs:843

Reproduction. Clean on an idle machine (5/5 green), so the flake was provoked with 2x CPU saturation (32 busy loops on 16 cores). Before the fix, -t "keeps a progressing active turn alive" failed 5 of 6 runs, every failure identical:

codex app-server turn idle timed out waiting for progress
{"idleMs":101,"timeoutMs":100,"lastActivityReason":"turn:start"}
methods=["thread/start","turn/start","turn/interrupt","thread/unsubscribe"]

After the fix, the same filter under the same 2x saturation: 6 of 6 green.

Mutation proofs that each test still catches the regression it guards:

Test Mutation Result
:764 attemptProgress: true -> false at attempt-notification-state.ts:114 FAILS
:1164 remove attempt progress from both run-attempt-server-requests.ts:81 and :339 FAILS
:168 drop scheduleAttemptIdleWatch() from recordAttemptProgress FAILS

One honest limitation, recorded in an inline comment rather than glossed over: mutating :start or :response alone for :1164 still passes. The two resets land ~20ms apart because finally runs when return is evaluated, not when the bridge promise settles, so this test guards the pair rather than attributing survival to the pending-request reset specifically. That was true before this change too; it is now written down.

Other proof:

  • node scripts/run-vitest.mjs extensions/codex/src/app-server/run-attempt.turn-watches.test.ts -> 94 passed
  • node scripts/run-vitest.mjs extensions/codex/src/app-server/attempt-turn-watches.test.ts -> 29 passed
  • node scripts/check-changed.mjs -> exit 0 (lint + typecheck, delegated to Blacksmith Testbox tbx_01kymk7fersgkvx3dvq73e7p14)
  • oxfmt --check clean, git diff --check clean
  • autoreview --mode uncommitted (codex / gpt-5.6-sol / xhigh) -> autoreview clean: no accepted/actionable findings reported

@steipete
steipete marked this pull request as ready for review July 28, 2026 15:16
@steipete
steipete force-pushed the steipete/festive-gould-dceb42 branch from 9a60d67 to 7e35d0d Compare July 28, 2026 15:27
@steipete
steipete merged commit d23ce05 into main Jul 28, 2026
85 checks passed
@steipete
steipete deleted the steipete/festive-gould-dceb42 branch July 28, 2026 15:33
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Jul 28, 2026
* origin/main:
  test(codex): de-flake attempt turn-watch timing tests (#115258)
  fix: preserve retryable ACPX lease ownership (#115247)
  fix: serialize ACPX lease ownership transitions
  fix: retain ACPX leases across wrapper reconnects
  refactor: parse ACPX lease command identity
  fix: preserve OpenClaw profile env in macOS launch-at-login plist (#99752)
  refactor(config): retire compaction truncateAfterCompaction gate (#115206)
  improve(ui): reduce duplicate chat startup work (#114743)
  fix(ui): keep reconnects, browser tabs, and localized search consistent (#115221)
  perf(pr): cache complete small file lists (#115199)
  perf(sqlite): skip no-op automatic schema repair (#115193)
  docs(browser): correct Docker sandbox setup (#115254)
  fix(ui): avoid duplicate session refreshes during startup (#114764)

# Conflicts:
#	ui/src/pages/agents/panels-tools-skills.browser.test.ts
vincentkoc added a commit that referenced this pull request Jul 28, 2026
* origin/main:
  test(codex): de-flake attempt turn-watch timing tests (#115258)
  fix: preserve retryable ACPX lease ownership (#115247)
  fix: serialize ACPX lease ownership transitions
  fix: retain ACPX leases across wrapper reconnects
  refactor: parse ACPX lease command identity
  fix: preserve OpenClaw profile env in macOS launch-at-login plist (#99752)
  refactor(config): retire compaction truncateAfterCompaction gate (#115206)
  improve(ui): reduce duplicate chat startup work (#114743)
  fix(ui): keep reconnects, browser tabs, and localized search consistent (#115221)
  perf(pr): cache complete small file lists (#115199)
  perf(sqlite): skip no-op automatic schema repair (#115193)
  docs(browser): correct Docker sandbox setup (#115254)
  fix(ui): avoid duplicate session refreshes during startup (#114764)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant