Skip to content

feat(gateway): report active drain counts and shutdown phases - #138379

Merged
steipete merged 1 commit into
mainfrom
codex/team-stop-diagnostics-20260904
Sep 4, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/team-stop-diagnostics-20260904

Conversation

@steipete

@steipete steipete commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

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=1 opt-in also starts a fresh stop trace and emits .begin marks 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

  • Captured pre-fix failures for missing OS SIGTERM progress, the ordinary-stop snapshot callback, and held-phase begin marks. The 145-case focused suite and complete changed-file gate passed on the first validated version.
  • After the final phase-token refinement and changing the process test to await complete stdout via ChildProcess 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.
  • The actual trace producer and collectTraceLine retained 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 a66263c372c214166d8b33094090f5c00184ae86 found 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.

@clawsweeper

clawsweeper Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime cli CLI command changes size: M maintainer Maintainer-authored PR labels Sep 4, 2026
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 4, 2026
@clawsweeper

clawsweeper Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 4, 2026, 12:04 PM ET / 16:04 UTC.

ClawSweeper review

What this changes

The 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
Reviewed head: 51cd036e0a92237d069cf9dbd390c9f9e24a1078

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The implementation is a focused, well-covered diagnostic improvement with no blocking issue found in the reviewed owner paths.
Proof confidence 🌊 off-meta tidepool Not applicable: Repository state identifies the author as a MEMBER, so the external-contributor proof gate does not apply. The PR body describes a real child-process SIGTERM run, but no attached runtime artifact was independently inspectable in this read-only, offline review.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Repository state identifies the author as a MEMBER, so the external-contributor proof gate does not apply. The PR body describes a real child-process SIGTERM run, but no attached runtime artifact was independently inspectable in this read-only, offline review.
Evidence reviewed 6 items Drain owner and privacy boundary: The introduced reporter logs only positive canonical count fields, excluding the aggregate and identity-bearing blocker descriptions; direct stops pass it to the existing active-work wait and announce the server-close boundary afterward.
Canonical active-work contract: The inventory separates category counts from blocker messages, which may contain root-holder names and task details; its wait loop invokes the supplied snapshot callback before evaluating idle or timeout.
Trace and parser compatibility: Tracing remains gated by the existing environment variable; the benchmark parser accepts one no-space phase token, matching the introduced whitespace normalization for human-readable shutdown step names.
Findings None None.
Security None None.

How this fits together

The 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]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +22, Tests +196, Docs +7. Total +225 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 3 55 33 +22
Tests 4 303 107 +196
Docs 1 8 1 +7
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 366 141 +225

Review metrics

Metric Value Why it matters
Production versus test delta production +55/-33 (net +22); tests +303/-107; docs +8/-1 The modest production growth adds missing lifecycle diagnostics while replacing identifier-bearing blocker formatting; tests cover distinct process and held-phase boundaries.

Technical review

Best 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.

Labels

Label changes:

  • add P3: This is a bounded operator-observability improvement with no demonstrated user-facing outage or compatibility change.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Repository state identifies the author as a MEMBER, so the external-contributor proof gate does not apply. The PR body describes a real child-process SIGTERM run, but no attached runtime artifact was independently inspectable in this read-only, offline review.

Label justifications:

  • P3: This is a bounded operator-observability improvement with no demonstrated user-facing outage or compatibility change.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Repository state identifies the author as a MEMBER, so the external-contributor proof gate does not apply. The PR body describes a real child-process SIGTERM run, but no attached runtime artifact was independently inspectable in this read-only, offline review.

Evidence

What I checked:

  • Drain owner and privacy boundary: The introduced reporter logs only positive canonical count fields, excluding the aggregate and identity-bearing blocker descriptions; direct stops pass it to the existing active-work wait and announce the server-close boundary afterward. (src/cli/gateway-cli/run-loop.ts:675, 51cd036e0a92)
  • Canonical active-work contract: The inventory separates category counts from blocker messages, which may contain root-holder names and task details; its wait loop invokes the supplied snapshot callback before evaluating idle or timeout. (src/infra/gateway-active-work.ts:111, 51cd036e0a92)
  • Trace and parser compatibility: Tracing remains gated by the existing environment variable; the benchmark parser accepts one no-space phase token, matching the introduced whitespace normalization for human-readable shutdown step names. (src/gateway/restart-trace.ts:107, 51cd036e0a92)
  • Focused boundary coverage: The changed tests cover a real child-process SIGTERM path, trace enabled/disabled behavior, count-only redaction, 30-second pending reporting, and held shutdown/close phases while preserving teardown order. (src/cli/gateway-cli/run-loop.direct-stop-active-work.process.test.ts:133, 51cd036e0a92)
  • Current-main comparison: The introduced production hunks are absent from fetched main, so the central diagnostics behavior is not already implemented there. (src/cli/gateway-cli/run-loop.ts:675, b90cc020cada)
  • Documentation validation limitation: The changed documentation was reviewed directly; the required docs-list command could not run because Corepack attempted to create a cache in the read-only reviewer environment. Public docs: docs/cli/gateway.md. (docs/cli/gateway.md:231, 51cd036e0a92)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete

steipete commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

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: node scripts/run-vitest.mjs src/cli/gateway-cli/run-loop.test.ts src/cli/gateway-cli/run-loop.direct-stop-active-work.process.test.ts src/infra/gateway-active-work.test.ts src/gateway/server-shutdown.test.ts src/gateway/server-close.test.ts src/gateway/restart-trace.test.ts; final affected check: node scripts/run-vitest.mjs src/gateway/server-shutdown.test.ts src/cli/gateway-cli/run-loop.direct-stop-active-work.process.test.ts; changed-file gate: node scripts/check-changed.mjs --base cf349c0ccdfe3d338c376db5ee54c76667c0be6e -- docs/cli/gateway.md src/cli/gateway-cli/run-loop.ts src/cli/gateway-cli/run-loop.test.ts src/cli/gateway-cli/run-loop.direct-stop-active-work.process.test.ts src/gateway/server-shutdown.ts src/gateway/server-shutdown.test.ts src/gateway/server-close.ts src/gateway/server-close.test.ts.

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.

@steipete
steipete merged commit 606d9ab into main Sep 4, 2026
310 of 314 checks passed
@steipete
steipete deleted the codex/team-stop-diagnostics-20260904 branch September 4, 2026 17:46
@steipete

steipete commented Sep 4, 2026

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

cli CLI command changes docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant