Repository navigation
test(codex): await shared-client transport writes - #131300
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Exact-head CI remains green for Correction to the earlier blocker: the implementation-worktree restriction does not prohibit the required temporary native landing worktree. That worktree is explicitly authorized. The acting maintainer personally inspected fresh sibling Codex source at Supplemental local proof: the same nine-file command passed 340 tests, including all eight non-process files and all 90 shared-client cases. One unchanged process-containment assertion failed ( Native review used |
|
Merged via squash.
|
What Problem This Solves
Codex shared-client lifecycle tests spend several seconds waiting for the next 50 ms polling tick after their in-memory transport has already written a request or response. This slows focused development and CI without adding lifecycle coverage.
Why This Change Was Made
Observe recorded transport writes directly in the existing test harness, with the same one-second readiness deadline and explicit timer/listener cleanup. Initialization and model-list helpers await their actual outgoing frame. Replacement-start assertions remain, but no longer need a separate poll before the initialize frame. Refresh-failure tests wait for the real JSON-RPC error response and now check its exact code and distinct failure/workspace-change message, then verify both old-lease drainage and replacement cleanup.
The production shared-client owner, JSON-RPC client, transport lifecycle, timeouts, fake-timer tests, and real WebSocket/process tests are unchanged. Lower polling intervals, fake time, awaited refresh mocks, or mocked initialization would not preserve the same boundary as clearly.
User Impact
No runtime behavior change. The project-routed shared-client file is about six seconds faster on the measured Linux host, with all 90 tests retained and stronger refresh-response/cleanup assertions. This is a maintainer-requested, AI-assisted test-performance change.
Production LOC: +0/-0. Tests: +22/-14. Test support: +24/-0. No dependency, configuration, protocol, persistence, package, or public API change.
Evidence
Benchmark base:
1d097044e9d109fdd83f1b997fde0291da87af98. One Blacksmith Testbox run, Linux x86_64, Node 24.19.0, pnpm 11.22.0. Baseline and candidate warmups excluded; eight order-balanced pairs, one worker, a distinct empty Vitest filesystem module cache per run, import diagnostics and/usr/bin/time -v. The measured scope is the whole changed file, because its initialization helper is shared across cases.A task-local reporter additionally recorded Vitest module diagnostics; it did not alter tests.
Median wall reduction: 5.895 s; median paired improvement: 31.02%. 8/8 pairs clear both 0.5 s and 3%; the minimum is 4.65 s / 23.79%. Imports and RSS remain effectively unchanged.
Separate reversible count probes, excluded from timing, matched before/after: 2,726 Vite module-graph entries, 110 in-memory client objects, 109 in-memory initialize writes, and two real WebSocket connections. The shared-client file intentionally owns no real stdio child processes. Its sibling process-lifecycle tests remain real and passed. Vitest's printed top-ten import list is not misreported as a total module count.
Three reversible mutations against the actual production owners each made both optimized refresh cases fail:
shared-client.ts's refresh-failure retirement callback: no replacement initialize frame arrives.-32602instead of-32603inclient.ts: exact response assertions fail.Each owner file was restored byte-for-byte and SHA-256 verified; the restored focused run passed both cases. No mutation is included in this PR.
Validation: 341 tests across nine focused/sibling files passed (
shared-client,client-runtime,client,auth-bridge,auth-binding,models,request,session-retirement,transport.process). Shuffled full-file runs passed all 90 tests with seeds131187and8272026. Formatting andgit diff --checkpassed. Deslop required no changes; fresh isolated Codex autoreview was clean (default P0 scope). The completepnpm check:changedgate passed in Testbox (exit 0, 8m1s), including both extension type-check lanes, lint, formatting, all three dead-export scans and runtime guards. Its shallow remote checkout skipped only the env-budget base comparison; that exact comparison separately passed locally against the frozen benchmark base (OPENCLAW_* count 501/501). Build/API/package checks are not needed for this test-only surface.Test-audit: the retained test specifically connects failed token refresh to retirement, fresh acquisition and old-lease drainage; generic retirement tests do not cover that producer. Missing retirement, leaked/early destruction, wrong replacement and wrong/missing wire response are credible failures. No new test-only production seam was added.
Upstream contract was personally checked in the actual sibling Codex repository, including freshly fetched commit
2d929eb7c39a612b84e0987f2af4a4c2282249e2:unauthorizedandpreviousAccountId.This proves the in-memory OpenClaw protocol/lifecycle boundary, not authenticated live-provider behavior. Production behavior is unchanged.
Landing continuation: the earlier worktree blocker was a mistaken interpretation. The restriction applies to a separate implementation worktree; the temporary repository-native
scripts/prreview/prepare worktree is explicitly authorized. Native review, prepare and merge completed on the unchanged head, landing as 4e33639bef29cc9fa45e8db8377d9eb7dba90283. The native worktree/refs/lock and source branch are cleaned up; the visible checkout is clean main. The acting maintainer independently matched all benchmark baseline/candidate files to Git blobs, recomputed the eight raw timing pairs, checked actual-owner fault and sibling logs, and obtained a fresh clean isolated Codex autoreview (default P0 scope). The current upstream refresh and lifecycle contracts were personally rechecked at Codex commit91c66024c7784f8de2d8c8355bcccad40ab3c44d, includingcommon.rs:1721-1724,2850-2871,v2/account.rs:271-307, completeexternal_auth.rs:1-98,outgoing_message.rs:281-360,383-463, andmessage_processor.rs:795-889under the same paths linked above. Exact-head CI remains green. Supplemental local proof: the same nine-file command passed 340 tests, including all eight non-process files and all 90 shared-client cases. One unchanged process-containment assertion failed (transport.process.test.ts:423, sentinel survival). Running that process file alone on current maine1a2f775733e28f362b1372e4e49ab9af0b04883reproduces the identical failure (1 passed / 1 failed). Its test and transport/containment owners are byte-identical between main and this PR; it does not import the changed test harness. Host load exceeded 340 and containment has a two-second inspection budget; load sensitivity is a hypothesis, not a proven root cause. Named follow-up: investigate the macOS process-containment fixture under heavy scheduling pressure without weakening identity checks or deadlines. This unrelated current-main failure is not counted as a pass; the archived Linux 341-test run and exact-head CI remain passing. No source edits or rebase were needed.