Repository navigation
refactor(gateway): schedule idle work and prewarm - #158666
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: blocked before merge. Reviewed September 26, 2026, 5:20 AM ET / 09:20 UTC (Revision 6). ClawSweeper reviewWhat this changesRoutes Gateway idle cleanup and post-ready handler prewarming through the process scheduler and updates clock-driven lifecycle tests. Merge readiness⛔ Blocked before merge - 2 items remain Current main still uses private timers for this work, so the PR remains useful. I found no definite introduced code defect, but the required installed-update lifecycle proof remains outstanding. Priority: P3 Review scores
Verification
How this fits togetherAfter Gateway startup, optional prewarming prepares common request paths and idle maintenance cleans up retained resources. The process scheduler controls their wakeups; work admission prioritizes requests, and shutdown joins accepted work. flowchart LR
A[Gateway startup] --> B[Process scheduler]
B --> C{Idle and open?}
C -->|yes| D[Handler prewarm]
C -->|yes| E[Maintenance cleanup]
C -->|busy| B
D --> F[First requests]
D --> G[Shutdown joins work]
E --> G
Before merge
Agent review detailsSecurityNone. PR surfaceSource +15, Tests +120. Total +135 across 10 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep one process-owned scheduler for idle maintenance and prewarming while preserving foreground priority, startup deadlines, and shutdown joins on upgraded installations. Do we have a high-confidence way to reproduce the issue? Not applicable: this is a scheduling refactor. Focused tests and a prior-head controlled-clock probe exercise its lifecycle behavior, but no installed-update run is supplied. Is this the best way to solve the issue? Yes: the existing process scheduler is the appropriate wakeup owner, and the patch keeps request admission and request-time loaders in their established owners. The required upgrade proof remains. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 5f3781df412c. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (5 earlier review cycles)
|
7ffc68a to
bb1dd3b
Compare
bb1dd3b to
622edd2
Compare
|
Additional shutdown regression proof for this existing PR, @steipete. Please continue its current native recovery and landing workflow; I have not changed this branch or submitted another merge request. The unchanged I reproduced that failure on fresh main The standalone file also passed on main, and Vitest scheduled the candidate's file earlier in the group. To separate the repair from test-order luck, I ran an identical controlled-clock probe against the real
Both controls ended with zero admitted root work and no warnings. This confirms that the scheduler cutover also fixes optional prewarming starting while shutdown is joining a canceled model reload. The real Gateway cases retain coverage for an active sibling and a closing sibling. This is Gateway/owner-boundary proof, not an installed-update test. Independent review raised a possible descendant-work join gap in the idle handle. A native probe using the actual Gateway sidecar owner falsified the proposed teardown race: the idle handle settled first, but the lifetime owner stayed pending until the scheduler-tracked child settled. The kernel already registers The current required CI blocker is separate: run 36223414976, job 108353386257 failed |
|
@steipete The separate fixture cleanup repair landed in #158730 as 4ec3b0cd4d08d3d3071b88fcefce4969cbd5b5b4 at 09:11 UTC. Canonical ancestry and the exact changed-file blob were verified on main The two-line repair awaits the existing The unchanged canonical lifecycle probe deterministically found an open native SQLite handle at removal; the identical candidate probe found it closed. The intermittent All ten completion cases and three cleanup-helper cases passed, the entire touched test file and cleanup helper were audited, and configured API review found no actionable issues. Exact published-head CI passed, and authenticated ClawSweeper review completed. Raw red/green evidence, commands, audit, and limitations remain linked in #158730. Native landing reused completed proof; no tests or builds were repeated for publisher recovery. No branch change or merge request was made against #158666. |
|
@steipete Please resume the existing scheduler worker for this PR's remaining installed-update proof and landing. I checked the current head, The two remaining items can progress separately:
Please first recheck the live head and existing evidence, then use your existing isolated environment where valid to complete that lifecycle proof. Our unchanged 95-file Gateway group and controlled-clock close comparison are already documented above; no repeat is needed unless a relevant source or environment assumption changes. Keep fixture state private, settle owned resources, and preserve meaningful failure assertions without sleeps, retries, or broader timeouts to hide a failure. Once the fixture repair is available, assess canonical movement, refresh the candidate as needed, and continue your existing native recovery/landing workflow only with the required exact-head checks passing. Remove consumed generated environments and proof staging through their owning tools, retaining one compact record with verified published evidence links. Please acknowledge which existing worker has accepted this continuation, or identify the exact owner/session availability blocker. I have not created another scheduler owner, changed this branch, or submitted another merge intent. |
622edd2 to
f293bd2
Compare
|
Merged via squash.
|
What Problem This Solves
Idle maintenance and startup prewarm own timeouts outside the Gateway scheduler.
User Impact
Idle work keeps its existing foreground-priority, admission, retry and shutdown behavior. Existing installs need no migration or operator action; stores, configuration, ports, RPC and public SDK contracts are unchanged.
Why This Change Was Made
Require the kernel scheduler and stable IDs for idle jobs; thread it through the surviving handler-prewarm and post-attach startup owners. Delete the private timeout/clearTimeout path. Preserve main's consolidated prewarm sequence, current-config reads, startup-relative delays and outgoing-handler joins. The context-cache prewarm module retired by #158555 stays deleted.
One scheduler instance per Gateway process, enforced by types. No private constructor or standalone entry point is introduced. This slice adds no database access, schema or transaction changes. Independent worker liveness timers and per-operation timeouts remain outside this migration.
Production +50/-35/net +15; tests/support +175/-55/net +120; docs +0/-0/net 0. Required dependency/registration plumbing accounts for growth.
Evidence
The prior head
622edd22febed3fbcdc99c1886c15c2ecfa5c550had an unrelated teardown failure insrc/infra/outbound/delivery-completion.test.ts(ENOTEMPTYremoving its temporary SQLite root), originating job. Other red shards were fail-fast cancellations. On the same Testbox lease, the complete recorded job groups passed on clean main837fad120fbab0c0df0dd7bc7009dd90decfbd38in 538.101s, and the failing file passed alone in 15.525s. The fixture removes its directory without retiring its SQLite/maintenance resources; the exact competing writer remains unproven. Twelve relevant test/storage/cleanup source files are identical between this head and clean main, and the failing test does not boot Gateway. This remains an unreproduced failure; the later green run does not establish a fix. No unrelated fixture change or blind CI rerun has been added.Current head
f293bd28576e8e5a30b79e23c5718a040a4669a9is rebased onto main2d5c68187a38db0c3bbe4cc18be77c12b0f54727because main advanced, with an identical reviewed patch. Exact-head CI run 36230141296 and the enforced CI gate are green.The refreshed focused Testbox attempt did not reach test execution: source-capsule preparation on the overloaded local host outlasted lease
tbx_01m3edhed3b3gy7qhr2ke2rkxp(run 36230115499); it was interrupted after the lease completed. No new focused pass is claimed. The following focused proof belongs to the prior head622edd22febed3fbcdc99c1886c15c2ecfa5c550. All 276 cases in 6 focused suites passed on blacksmith-testbox leasetbx_01m3e2nta4ngefyyk0dsf55cr4, run 36220641511. Commands:pnpm install --frozen-lockfile, thenpnpm test <file> --maxWorkers=1; exact commit and clean source verified before and after.src/gateway/server-idle-task.test.tssrc/gateway/server-idle-task.lifecycle.test.tssrc/gateway/server-startup-handler-prewarm.test.tssrc/gateway/server-runtime-services.test.tssrc/gateway/server-startup-post-attach.test.tssrc/gateway/server-plugin-reload.recovery.test.tsThe earlier CI failure came from an unrelated chained assertion in server-chat-progress-snapshot.ts. The exact lint command reproduced on clean old main (exit1,22.357s) and passed on clean current main (exit0,24.004s), which contains the owning fix
66b812f26e725cd709e08860d2cb46ba496cd308. No unrelated fix was added here. The accepted auto-merge request was retired through native recovery before replacing the head; replacement admission must use the retained native outcome and refreshed preparation. Exact-head CI is now complete; no new merge request has been submitted.Earlier focused and review evidence
Head
bb1dd3bd690f1c585c69ac37ad85a2a8a059b2d1has the exact reviewed and Testbox-proven tree2fd43c92f8fffd1c743dada364fcc5b11c7c3e83, based on mainbed7385166380136b880e21f58232416d5375ebf. On blacksmith-testbox leasetbx_01m3e2nta4ngefyyk0dsf55cr4, run 36220641511, frozen install and all six focused files / 276 cases passed. Baseline SHA, patch bytes, full tree and unchanged source after tests were verified.Commands:
pnpm install --frozen-lockfile, thenpnpm test <file> --maxWorkers=1.src/gateway/server-idle-task.test.tssrc/gateway/server-idle-task.lifecycle.test.tssrc/gateway/server-startup-handler-prewarm.test.tssrc/gateway/server-runtime-services.test.tssrc/gateway/server-startup-post-attach.test.tssrc/gateway/server-plugin-reload.recovery.test.tsThe new manual-clock regression advances six seconds in earlier startup work and verifies a later five-second deadline adds no extra delay. The negative control with the old Date clock reads failed for the intended reason (5000ms instead of zero); the corrected owner passed. Existing lifecycle coverage exercises busy admission, restart/suspend fences, stop-before-start and shutdown initiated by a warning callback. No new per-test Gateway boot, sleep or polling was added.
Deslop, full cross-shard caller census and whitespace checks passed. Fresh Codex review of the upstream-adapted slice is clean through P2, following the original clean review. The full-source tree matches the isolated review candidate exactly. Earlier baseline costs remain in PR history; no performance improvement is claimed. GitHub's enforced CI gate supplies changed-file validation. Final merged-main maintenance/cron/suspend/restart/shutdown live proof follows the last stack slice.
Stack