Repository navigation
test(gateway): consolidate server-close.test.ts - #166014
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed October 6, 2026, 4:42 AM ET / 08:42 UTC (Revision 2). ClawSweeper reviewWhat this changesThis PR consolidates Gateway shutdown tests with local fixtures and parameterized cases while retaining cleanup, restart recovery, and transport assertions. Merge readiness✅ Ready for maintainer review Keep open: the consolidation remains distinct from current main, and inspection found no blocking coverage regression. The retained scenarios and reported mutation checks support preserving this useful maintainer-authored cleanup. Priority: P3 Review scores
Verification
How this fits togetherThe Gateway shutdown owner receives stop or restart requests, drains active work, and closes runtimes, listeners, and shared state. These tests protect the ordering, recovery, and failure handling of that process. flowchart TD
A[Stop or restart request] --> B[Gateway shutdown preparation]
B --> C[Drain work and record recovery]
C --> D[Close runtimes and listeners]
D --> E[Join cleanup and retire shared state]
E --> F[Completion or failure]
G[Consolidated shutdown tests] --> B
G --> F
Before mergeNone. Agent review detailsSecurityNone. PR surfaceTests -275. Total -275 across 1 file. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep shared shutdown setup concise while preserving distinct tests for cleanup joins, recovery ordering, process extinction, and transport completion. Do we have a high-confidence way to reproduce the issue? Not applicable: this PR consolidates existing tests rather than fixing a reported runtime defect; the captured body supplies focused before/after validation. Is this the best way to solve the issue? Yes: local fixture composition and parameterized cases reduce repetition without changing production APIs or discarding the distinct shutdown contracts inspected. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against d3c121c23788. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
|
Merged via squash.
|
What Problem This Solves
server-close.test.tsrepeats Gateway fixtures and assertions across related shutdown scenarios. Consolidate those cases while keeping the distinct lifecycle, persistence, and transport contracts visible.User Impact
No user-visible change. This is a test-only lane: production LOC delta is 0, as required by the campaign. No production files or shared support files change.
Why This Change Was Made
The file falls from 2,432 to 2,157 lines: -275 (-11.3%). The shared support file has other consumers and remains unchanged. Local factories now compose the existing close fixture, create typed controller records, and supply HTTP callback stubs. Outcome assertions replace duplicate warning strings; trace-format assertions and the recent restart count-format regression remain.
completes clean shutdown and clears the process-root registry and lifecycle state;records subsystem shutdown warnings without aborting later cleanup;uses caller-provided channel ids instead of the local channel registrycompletes %s teardown and clears registry and lifecycle state: clean, subsystem-failure, and explicit-channel rows retain exact warnings, stop order, state clearing, and registry lookup exclusion.drains active sessions for $reason (timed out: $timedOut);drains pending restart replies before emitting session-end hooksdrains active sessions after replies for %s (...): all three original drain inputs plus the original 123 ms restart/100 ms drain-budget ordering input.keeps post-terminal caller work in restart drain and recovery;preserves terminal recovery until persistence is settled (%s)preserves terminal recovery until persistence and caller work settle (%s): post-terminal, untracked, settled, and pending rows preserve their original IDs, flags, candidate contents, and cancellation assertions.starts bundle MCP and LSP runtime disposal concurrentlycontinues independent teardown while $label cleanup is pending, bundle-MCP row: LSP must start before the fake clock advances through MCP grace, while MCP is still blocked.forces lingering HTTP connections closed and records a timeout warning;attempts every listener and later cleanup before rejecting stuck HTTP close (multiple: %s)forces lingering HTTP close (settles: $settles, multiple: $multiple): forced success and stuck single/multiple-listener rows retain the force count, exact rejection, sibling attempt, timer cleanup, and later Tailscale cleanup.disposes Code Mode runs before agent and bundle runtimes during shutdownkeeps the exact ordered event array, which also detects missing or duplicate disposal.The 35% reduction target is not met. This uses the campaign's coverage-preserving escape hatch. Within the remaining
createGatewayCloseHandlerblock:The issue-numbered #112681 rows and the relevant #165574, #165670, and #165980 regressions remain. No new skipped tests, snapshots, production changes, or dependencies. The existing Windows exclusion on POSIX process-tree proof is unchanged. The validation scan found one unrelated unused production export,
OUTBOUND_GREETING_FALLBACK_MSinextensions/voice-call/src/webhook/realtime-call-session-control.ts. Its value is used internally; removing its export is outside this test-only lane.Evidence
Provider: blacksmith-testbox, profile openclaw-check, lease tbx_01m4836q24694xbvb19gv0m4yh (stopped after validation). Development checks ran on the lease, with synchronized source hashes checked before execution. Its initial
pnpm install --frozen-lockfilecompleted before baseline timing. No local suites, builds, or typechecks ran.pnpm test src/gateway/server-close.test.ts --maxWorkers=1passed 72 baseline / 71 consolidated cases. Three alternating warm pairs gave:Median wall time is down 0.43 s (2.5%); the sum of individual test timings also fell from 7.521 s to 7.388 s (medians). Individual pairs vary, so this is evidence of no aggregate cost growth, not a throughput claim. Initial cold baseline: 40.38 s, including 18.95 s of worker compilation. Initial warm baseline: 17.81 s; the earlier candidate: 19.14 s. The table above measures the candidate after its review repair; the only later edit adds lint-required braces to the HTTP fixture.
Validation results:
node scripts/run-vitest.mjs src/gateway/server-close.agent-databases.test.ts src/gateway/server-close.cleanup-scope.test.ts src/gateway/server-close.incognito-pending-history.test.ts src/gateway/server-close.queued-heartbeat.test.ts src/gateway/server-restart-heartbeat.test.ts— 5 files / 14 tests passed, 87.40 s runner wall time.node scripts/check-changed.mjs --dry-runselected the Gateway-server test graph and targeted lint.node scripts/check-changed.mjspassed its first 22 gates, including formatting, all ratchets, plugin boundaries, and Gateway-server typechecking (39.1 s), then failed at the unrelated existing dead-export scan forextensions/voice-call/src/webhook/realtime-call-session-control.ts: OUTBOUND_GREETING_FALLBACK_MS.58163bdb326f371bac41d98a45f68239e6add238on the same lease and rannode --import tsx scripts/check-deadcode-exports.mts. Both production and full-tree scans reproduced the identical unused export. The voice-call file has no lane diff; its bytes also match inspectedorigin/main. This gate remains red and is not claimed as passing.node scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.core.json src/gateway/server-close.test.tspassed separately: 0 warnings / 0 errors, 9.7 s. The first lint pass caught missing braces in the HTTP fixture; the final pass includes that mechanical correction.pnpm test src/gateway/server-close.test.ts --maxWorkers=1. Each produced exactly 1 failed / 70 passed; source bytes were restored and hashes verified after each.waits for in-flight stopPeriodicTasks cleanup before shared state closes(shared-store close called prematurely)preserves terminal recovery until persistence and caller work settle (settled)(unexpected recovery candidate)ERR_SERVER_NOT_RUNNINGas an HTTP close failureclassifies unbound HTTP listener close callbacks(unexpected warning)2466d6f64d32703554a6ba03cbdc61d3613a7dd8; all PR checks are passing or skipped. CI job wall times:checks-node-changed125 s,checks-node-changed-compact-small-8132 s, andchecks-node-changed-boundary112 s (job durations, not isolated test time).This PR is for lead review; do not merge or enable auto-merge from this lane.