Skip to content

test(codex): await shared-client transport writes - #131300

Merged
steipete merged 1 commit into
mainfrom
perf/codex-shared-client-writes
Aug 28, 2026
Merged

steipete merged 1 commit into
mainfrom
perf/codex-shared-client-writes

Conversation

@steipete

@steipete steipete commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

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.

/usr/bin/time -v env   OPENCLAW_VITEST_FS_MODULE_CACHE_PATH=<unique-path-per-run>   OPENCLAW_VITEST_IMPORT_DURATIONS=1   OPENCLAW_VITEST_PRINT_IMPORT_BREAKDOWN=1   OPENCLAW_VITEST_MAX_WORKERS=1   pnpm test extensions/codex/src/app-server/shared-client.test.ts   --maxWorkers=1 --reporter=verbose

A task-local reporter additionally recorded Vitest module diagnostics; it did not alter tests.

Median Before After
Scoped wall 20.100 s 14.205 s
Vitest 16.275 s 10.590 s
Test bodies/hooks 7.631 s 1.888 s
Import 7.942 s 8.085 s
Max RSS 1,099,378 KiB 1,092,136 KiB
CPU user/system 14.185 / 1.600 s 13.840 / 1.610 s
CPU utilization 77.5% 107%
Passing tests 90 90

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.

Pair Order Before s After s Improvement
1 before/after 19.62 13.11 33.18%
2 after/before 20.26 13.99 30.95%
3 before/after 20.61 14.42 30.03%
4 after/before 19.55 14.90 23.79%
5 before/after 22.28 15.21 31.73%
6 after/before 21.35 15.70 26.46%
7 before/after 19.94 13.34 33.10%
8 after/before 19.49 13.43 31.09%

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:

  • Remove shared-client.ts's refresh-failure retirement callback: no replacement initialize frame arrives.
  • Keep the shared entry's active-lease count at one on release: old-client destruction assertion fails.
  • Serialize error code -32602 instead of -32603 in client.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 seeds 131187 and 8272026. Formatting and git diff --check passed. Deslop required no changes; fresh isolated Codex autoreview was clean (default P0 scope). The complete pnpm check:changed gate 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:

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/pr review/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 commit 91c66024c7784f8de2d8c8355bcccad40ab3c44d, including common.rs:1721-1724,2850-2871, v2/account.rs:271-307, complete external_auth.rs:1-98, outgoing_message.rs:281-360,383-463, and message_processor.rs:795-889 under 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 main e1a2f775733e28f362b1372e4e49ab9af0b04883 reproduces 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.

@clawsweeper

clawsweeper Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@steipete
steipete marked this pull request as ready for review August 28, 2026 00:12
@steipete

steipete commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor Author

Exact-head CI remains green for 12e5f811e92bbf46ce6d3800bad77f736e593936: CI run, including openclaw/ci-gate. The prior Linux benchmark and fault/test evidence were independently checked against the raw artifacts: baseline/candidate test files match their Git blobs exactly; all eight pairs qualify; all three actual-owner mutations fail both intended refresh cases; the restored owner hashes match this PR. The archived nine-file run passed 341 tests, both shuffled runs passed all 90 cases, and the complete changed gate passed. The task Testbox run is confirmed completed.

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 91c66024c7784f8de2d8c8355bcccad40ab3c44d: refresh protocol, complete refresh handling, and request-id cancellation/initialization lifecycle. Fresh isolated Codex autoreview exited clean at its default P0 scope; manual owner/caller/sibling review found no blockers. Production LOC remains +0/-0; combined tests/support +46/-14.

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 main e1a2f775733e28f362b1372e4e49ab9af0b04883 reproduces 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.

Native review used scripts/pr review-init 131300, scripts/pr review-artifacts-init 131300, main-baseline and PR-head checkout/guard steps, and completed land-ready artifacts. The native OPENCLAW_TESTBOX=1 scripts/pr prepare-run 131300 and scripts/pr merge-run 131300 steps completed without changing the head or rebasing. Landed commit: 4e33639bef29cc9fa45e8db8377d9eb7dba90283. Source branch, remote-tracking ref, native review/prepare/temp refs, worktree and operation lock are gone. No rebase is needed: current main has no app-server-scope changes since the benchmark base. At the final pre-merge check, the latest ClawSweeper comment was its current-head review-start notice; no findings or Rank-up moves: have been published. This is test-only protocol/lifecycle proof, not authenticated live-provider proof.

@steipete steipete self-assigned this Aug 28, 2026
@steipete
steipete merged commit 4e33639 into main Aug 28, 2026
193 checks passed
@steipete
steipete deleted the perf/codex-shared-client-writes branch August 28, 2026 00:37
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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