Skip to content

fix(diagnostics): preserve graceful Gateway shutdown in install E2E - #139247

Merged
steipete merged 1 commit into
mainfrom
codex/prometheus-shutdown-main-followup
Sep 5, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/prometheus-shutdown-main-followup

Conversation

@steipete

@steipete steipete commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Related: #138249

What Problem This Solves

The Prometheus managed-install E2E sometimes killed a healthy Gateway while it drained startup work, then failed its graceful-exit assertion. Its cleanup helper escalates to SIGKILL after five seconds; that emergency cleanup deadline is not the Gateway's graceful-shutdown contract.

Why This Change Was Made

Pre-arm the child close observer, bind it to Vitest's existing test timeout/cancellation signal, and send SIGTERM directly for the graceful-shutdown proof. Keep the exact exit-code-zero and null-signal assertions, all install/metrics checks, and the existing five-second forced reaper in afterEach.

Shutdown failures now include the captured exit code, signal, and bounded post-stop Gateway logs before fixture cleanup removes them. No test timeout, Gateway policy, or Control UI configuration changes.

User Impact

Maintainers retain meaningful graceful-shutdown coverage without racing an emergency reaper against legitimate startup work. Production behavior is unchanged. This main-only follow-up is separate from the frozen release candidate.

Evidence

  • Natural main reproduction captured SIGTERM followed by the cleanup helper's SIGKILL at 5,002ms, with actual exit null/SIGKILL while the Gateway drained startup work.
  • A separately labeled, non-qualifying cold-assets observation identified the exact owner as startup:sidecars.control-ui-assets. The owner released naturally after its build, then the Gateway exited zero with no signal. This was not a product deadlock or a retrospective explanation of the original release-CI event.
  • Node 24.19 process-level checks passed for normal close, retained early close, abort listener cleanup, and abort/exit races using the existing forced-cleanup helper.
  • Independent managed review through P2 found no actionable findings.
  • Qualifying cold-assets E2E passed with the real Gateway, unchanged startup configuration, and no signal mutation: SIGTERM to exit zero/null signal in 4,883ms. All managed-install and metrics assertions passed.
  • Deliberately injected SIGKILL failed the unchanged clean-exit contract as expected and retained the signal plus post-stop Gateway logs. This negative diagnostic check is distinct from the natural reproduction.
  • Full classified changed gate passed on the unchanged patch, including extension-test typecheck, lint, formatter, boundaries, and dead-code scans. Exact-head CI passed for a3726dbf12396eb058dce8a2a37c102a73f5dfdf.
  • One test file: +22/−4; production and tooling unchanged.

Fresh ClawSweeper review found no actionable defects or before-merge actions. The real-flow evidence above was executed independently; ClawSweeper reviewed source and reported evidence without rerunning it.

Observe process close under the existing test lifetime instead of invoking the
five-second forced reaper as the graceful-shutdown assertion path. Keep exact
exit and signal assertions, forced teardown, and install/metrics coverage.
Retain termination state and post-stop Gateway logs on failure.

Follow up the graceful-shutdown coverage added in #138249.
@clawsweeper

clawsweeper Bot commented Sep 5, 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.

@steipete
steipete marked this pull request as ready for review September 5, 2026 17:35
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 5, 2026
@clawsweeper

clawsweeper Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 5, 2026, 2:20 PM ET / 18:20 UTC.

ClawSweeper review

What this changes

Updates the Prometheus installation test to await graceful Gateway shutdown within the existing test deadline and include termination details and logs on failure.

Merge readiness

✅ Ready for maintainer review

No actionable findings. This remains a useful, focused repair: current main still races graceful shutdown against forced cleanup, and the supplied evidence covers successful shutdown and rejection of SIGKILL.

Priority: P2
Reviewed head: a3726dbf12396eb058dce8a2a37c102a73f5dfdf

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Focused lifecycle repair with preserved assertions, relevant reported real-Gateway validation, and no actionable defects.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The supplied body reports the changed installation E2E exercising a real Gateway with cold assets: SIGTERM completed with exit 0/null, while injected SIGKILL still failed and retained diagnostics; this review inspected source and reported results without rerunning them.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The supplied body reports the changed installation E2E exercising a real Gateway with cold assets: SIGTERM completed with exit 0/null, while injected SIGKILL still failed and retained diagnostics; this review inspected source and reported results without rerunning them.
Evidence reviewed 8 items Introduced change and cleanup ownership: Read the complete test. The close observer is registered immediately after spawn; graceful shutdown sends SIGTERM and retains exitCode 0 and signalCode null assertions. afterEach retains forced cleanup. The pinned introduction contains only this test change; the host-verified test merge likewise changes only this file.
Current main still needs the repair: The fetched main revision still invokes stopChildProcess(gateway, 5_000) immediately before asserting clean exit. The shared helper deliberately escalates SIGTERM to SIGKILL after its deadline; the SDK exports that same helper. The adjacent Ollama E2E uses it for cleanup rather than a clean-exit assertion.
Gateway shutdown contract: The Gateway run loop allows substantially more than five seconds for graceful stop, drains active work, and awaits accepted startup operations before server close. Changing this test's cleanup use preserves that production lifecycle rather than changing Gateway policy.
Findings None None.
Security None None.

How this fits together

The Prometheus installation test installs a packaged plugin, starts a real Gateway, and checks authenticated metrics. Its shutdown assertion verifies clean termination before fixture cleanup removes child processes and temporary files.

flowchart TD
  A[Packaged Prometheus plugin] --> B[Managed installation]
  B --> C[Real Gateway]
  C --> D[Authenticated metrics checks]
  D --> E[SIGTERM and close observer]
  E --> F[Clean exit assertion]
  E --> G[Failure details and logs]
  F --> H[Forced cleanup if needed]
  G --> H
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Tests +18. Total +18 across 1 file.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 1 22 4 +18
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 1 22 4 +18

Review metrics

Metric Value Why it matters
Production versus test growth Production net 0; tests net +18 All growth supports lifecycle observation and failure diagnostics without adding production behavior or a new test case.

Technical review

Best possible solution:

Keep graceful-exit verification separate from emergency cleanup, with cancellation bounded by the existing test lifetime and production shutdown policy unchanged.

Do we have a high-confidence way to reproduce the issue?

Yes, from source: a Gateway draining longer than five seconds is forcibly killed by the existing assertion path. The supplied body reports that failure; this review did not execute it.

Is this the best way to solve the issue?

Yes. Correcting the test's use of the emergency reaper addresses the owning mistake; enlarging the shared cleanup timeout or changing Gateway startup policy would affect unrelated behavior.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 64c543a78b7f.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The supplied body reports the changed installation E2E exercising a real Gateway with cold assets: SIGTERM completed with exit 0/null, while injected SIGKILL still failed and retained diagnostics; this review inspected source and reported results without rerunning them.

Label justifications:

  • P2: Repairs a concrete installation-test false failure with limited impact on maintainer validation.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The supplied body reports the changed installation E2E exercising a real Gateway with cold assets: SIGTERM completed with exit 0/null, while injected SIGKILL still failed and retained diagnostics; this review inspected source and reported results without rerunning them.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied body reports the changed installation E2E exercising a real Gateway with cold assets: SIGTERM completed with exit 0/null, while injected SIGKILL still failed and retained diagnostics; this review inspected source and reported results without rerunning them.

Evidence

What I checked:

  • Introduced change and cleanup ownership: Read the complete test. The close observer is registered immediately after spawn; graceful shutdown sends SIGTERM and retains exitCode 0 and signalCode null assertions. afterEach retains forced cleanup. The pinned introduction contains only this test change; the host-verified test merge likewise changes only this file. (extensions/diagnostics-prometheus/src/install-runtime.e2e.test.ts:361, a3726dbf1239)
  • Current main still needs the repair: The fetched main revision still invokes stopChildProcess(gateway, 5_000) immediately before asserting clean exit. The shared helper deliberately escalates SIGTERM to SIGKILL after its deadline; the SDK exports that same helper. The adjacent Ollama E2E uses it for cleanup rather than a clean-exit assertion. (extensions/diagnostics-prometheus/src/install-runtime.e2e.test.ts:442, 64c543a78b7f)
  • Gateway shutdown contract: The Gateway run loop allows substantially more than five seconds for graceful stop, drains active work, and awaits accepted startup operations before server close. Changing this test's cleanup use preserves that production lifecycle rather than changing Gateway policy. (src/cli/gateway-cli/run-loop.ts:554, a3726dbf1239)
  • Node event-wait dependency contract: The added node:events import establishes the dependency signal. Direct inspection of Node 24.19 events.once confirms immediate listener registration, retained promise resolution, error rejection, and removal of event/error listeners on abort. (lib/events.js:923)
  • Vitest cancellation contract: The new test-context signal establishes the dependency signal. The repository pins Vitest 4.1.11; its context implementation aborts the context signal on timeout. Official documentation also specifies cancellation. No changed behavior depends on the Codex runtime or protocol. (packages/runner/src/context.ts:130)
  • Reported real-flow validation: The complete supplied PR body reports natural pre-fix SIGKILL escalation at 5,002 ms, an after-fix cold-assets managed-install run exiting 0/null after SIGTERM in 4,883 ms, and injected SIGKILL correctly failing with shutdown diagnostics. Install and metrics assertions passed. These are contributor-reported observations, not reviewer executions; sourceRevision is 56c5889b67684a888561c18257eb79c066b1dd240218792740fc16c02fb21dfb. (a3726dbf1239)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Vincent Koc: 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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-09-05T17:41:18.268Z sha a3726db :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Sep 5, 2026
@steipete
steipete merged commit 7989510 into main Sep 5, 2026
171 checks passed
@steipete
steipete deleted the codex/prometheus-shutdown-main-followup branch September 5, 2026 18:22
@steipete

steipete commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Sep 5, 2026
* commit '911d7d5b0c107f7274f2415ca9655dcc6105f0e8': (867 commits)
  fix(skills): deliver pending Workshop approval controls (#139248)
  fix(gateway): deliver loopback ask_user prompts to the originating channel (#138831)
  docs: keep root agent instructions focused on repository policy (#139258)
  fix(matrix): exclude archived state roots from scans and selection (#112329)
  perf(agents): prepare exact tool names once per catalog batch (#139267)
  fix: preserve Swarm progress and simplify owner plumbing (#139269)
  fix(tailscale): release claims after gateway process-group exit (#139261)
  refactor(cli): simplify lazy command registration (#139108)
  test(ui): retain synthetic widget failure evidence (#139229)
  fix(buzz): keep implicit replies at thread root (#138879)
  test(diagnostics): await graceful Gateway shutdown before cleanup (#139247)
  fix(ci): unblock releases with different tooling package managers (#139259)
  feat(ui): add social preview links for private sessions (#139250)
  fix(codex): retain failed conversations for guarded continuation (#139246)
  chore(ui): refresh control ui locales (#139200)
  fix(ci): run browser checks for real-gateway inputs (#139256)
  fix(llama-cpp): reconcile managed router state before requests (#136363)
  chore(i18n): refresh native locales (#139237)
  refactor(worker): unify inference payload handling (#139245)
  refactor(terminal): replay wrapped prefixes in one pass (#139240)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 6, 2026
…enclaw#139247)

Observe process close under the existing test lifetime instead of invoking the
five-second forced reaper as the graceful-shutdown assertion path. Keep exact
exit and signal assertions, forced teardown, and install/metrics coverage.
Retain termination state and post-stop Gateway logs on failure.

Follow up the graceful-shutdown coverage added in openclaw#138249.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: diagnostics-prometheus maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS 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