Repository navigation
feat(gateway): report active drain counts and shutdown phases - #138379
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 September 4, 2026, 12:04 PM ET / 16:04 UTC. ClawSweeper reviewWhat this changesThe PR adds privacy-preserving active-work drain counts and opt-in shutdown phase timing to Gateway stop and restart logs, with focused tests and CLI documentation. Merge readiness✅ Ready for maintainer review This maintainer-authored PR remains necessary: fetched current main lacks the proposed stop-drain diagnostics, and the reviewed change has no introduced blocking defect. Priority: P3 Review scores
Verification
How this fits togetherThe Gateway process loop receives stop or restart signals, drains admitted work, and then invokes the server shutdown owners. This change adds operator-visible progress diagnostics at those lifecycle boundaries without changing the shutdown actions. flowchart LR
Signal[Stop or restart signal] --> Loop[Gateway process loop]
Loop --> Drain[Active-work drain]
Drain --> Counts[Category-count diagnostics]
Drain --> Close[Server close]
Close --> Phases[Shutdown phase tracing]
Phases --> Logs[Operator logs]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +22, Tests +196, Docs +7. Total +225 across 8 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Land the shared count-only reporter and begin-before-await phase instrumentation after the exact-head checks complete, retaining the existing trace opt-in and lifecycle ordering. Do we have a high-confidence way to reproduce the issue? Not applicable: this PR adds Gateway diagnostics rather than repairing a separately reported broken behavior. The changed process and held-phase tests define concrete validation scenarios. Is this the best way to solve the issue? Yes. The implementation records counts at the canonical drain owner and phase markers at the ordered shutdown owners, avoiding duplicate inventories or changes to shutdown semantics. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against b90cc020cada. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Landing review completed for commit 51cd036e0a92237d069cf9dbd390c9f9e24a1078. The latest ClawSweeper review has no findings or before-merge actions. The canonical drain callback now reports the existing thirteen nonzero numeric categories without task or request identities. Ordinary stops start the existing opt-in trace, and entered-phase marks precede the same ordered cleanup calls. This supplies missing diagnostic milestones; it does not change drain deadlines, admission, aborts, or cleanup policy. Production is +55/-33 (net +22), tests +303/-107, docs +8/-1. The growth is the missing progress and entered-phase recording, shared with restart rather than a second inventory or timer. Verified the preserved pre-fix failures, 145 focused passing cases, final five shutdown/process cases, and actual producer-to-collector preservation of six phase records. Both real OS SIGTERM variants retain the 400 ms work release, 45-second readiness deadline, and 60-second case deadline, complete work before close, and exit cleanly. The full changed-file gate is evidence for the earlier version; final local phase-token and stdout-close refinements have separate affected tests, typed lint, formatting and independent P0–P2 review. The archived source and final PR files match byte-for-byte. Current-main owner inspection retains the same three production preimages. The neighboring reload-helper relocation and matching test mock remain intact. Exact-head CI run 33892436475, attempt 2, is successful after retrying jobs that never acquired a runner. The original infrastructure failures remain recorded. Fresh landing review found no actionable P0–P2 findings. Commands represented by the proof: Limits: counts overlap and timings are elapsed time. This does not itself repair a stalled shutdown or measure each nested cleanup operation. Further stall attribution remains a separate measured investigation. |
|
Merged via squash.
|
What Problem This Solves
Ordinary SIGTERM/SIGINT stops could wait for active work without reporting what remained or whether teardown had begun. Existing close traces appeared only after a phase settled, leaving an in-progress phase unnamed.
Why This Change Was Made
Share the existing active-work snapshot reporter between stop and restart. It reports nonzero counts from the thirteen canonical categories, omitting task identities and request-origin descriptions. Add entered-phase marks at the existing ordered shutdown and coarse close owners.
The trace collector requires a single-token phase name. A direct producer/parser check caught multiword shutdown labels being discarded; normalizing whitespace preserves their timings while retaining the original human-readable error labels. The net production increase is 22 lines, adding missing milestones while removing duplicate blocker-description formatting.
User Impact
Default logs report initial active-work counts, pending progress at the existing 30-second interval, and the ordinary-stop boundary between draining and server close. The existing
OPENCLAW_GATEWAY_RESTART_TRACE=1opt-in also starts a fresh stop trace and emits.beginmarks before named shutdown steps and coarse close phases await completion.Drain budgets, supervisor deadlines, admission, abort/force behavior, and cleanup ordering remain unchanged. No new setting, dependency, inventory read, or timer is added. Counts can overlap; durations measure elapsed time rather than CPU, and nested cleanup operations are not all individually timed. These diagnostics help locate stalls; they do not fix a shutdown stall themselves.
Evidence
close, all five affected shutdown/process cases passed. Both real SIGTERM variants preserved the original 400 ms work release, 45-second readiness deadline, and 60-second test deadline; work completed before close without aborting, and the child exited cleanly.collectTraceLineretained all six entered/settled phase records after normalization, with failure text and later cleanup preserved. Final typed lint, formatting, diff checks, and fresh P0–P2 review passed.The full gate predates those final local string/test refinements; its unchanged type/dependency-graph coverage is retained alongside the final affected checks, rather than represented as a full rerun. Read-only comparison with main at
a66263c372c214166d8b33094090f5c00184ae86found unchanged production preimages and a clean three-way textual fit, retaining main's one-line test mock relocation. That comparison was not runtime validation on the newer main.