Skip to content

refactor(gateway): deslop gateway shutdown - #165980

Merged
steipete merged 1 commit into
mainfrom
steipete/deslop-restart-shutdown-20261005
Oct 6, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/deslop-restart-shutdown-20261005

Conversation

@steipete

@steipete steipete commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Gateway shutdown maintenance carries duplicate adapters, copied fixture contracts, and repeated tests around the same cleanup owners.

User Impact

No user-visible behavior change. Restart/update behavior, shutdown budgets, required persistence joins, recovery marking, and current-owner checks are preserved. No config, schema, or persisted-shape changes.

Why This Change Was Made

  • Fold lifecycle-hook grace handling into the existing close owner. Runtime disposal captures that owner's scope, trace, and warning collection; five callers share their existing 5-second grace without repeating those arguments.
  • Inline the one-use chat-removal notification helper. Remove the unreachable already-accepting suspension branch: both callers synchronously require a non-accepting phase.
  • Derive run-loop fixture types from the actual fixture, removing the copied request-fixture module and repeated type inventories. Parameterize duplicate signal, supervisor-exit, expiry, history-agent, and tie-order cases.
  • Remove three redundant mocked close tests and the duplicate successful terminal-persistence test. The retained real SQLite lifecycle, actual SDK failure, model-acquisition, and fulfilled/rejected registration-removal tests cover those contracts. Pending-hook diagnostics from fix(gateway): identify blocked restart shutdown cleanup #165670 are preserved in the real SQLite hook cases. All real-process signal/deadline tests and issue-number regressions remain.

Measurement against the branch base: −699 net lines across 19 files: production −125; tests/support −574. No performance improvement is claimed.

The lane's −1,500 target uses the safety escape hatch. Further deletion would remove distinct cleanup/authority contracts in server-close.agent-databases.test.ts:80, server-close.board.test.ts:14, and server-close.auth-usage.test.ts:16; package helper IPC coverage in run-loop-package-lifecycle.test-support.ts:35; or actual process lifetime proof in run-loop.restart-liveness.process.test.ts:188. Removing the close-runtime barrel requires changing the non-owned architecture test server-import-boundary.test.ts:147. No out-of-scope files changed.

Evidence

Final head: 3c181dc8454209cf6e7eb9fab9b1c1f15219daa4. Rebased onto main immediately before publication; stable patch IDs matched before and after rebase. Independent Codex review is clean at P0–P2, and the diff-scoped deslop pass is complete.

Exact-head CI and openclaw/ci-gate passed. The 20 selected Node CI jobs consumed 3,932 job-seconds in total; this is the selected CI scope, not a per-test attribution. No inherited red jobs or gate exceptions remain.

All heavy local-proof commands ran on Blacksmith Testbox, provider blacksmith-testbox, profile openclaw-check:

Lease Command / result
tbx_01m47x8x6smxsshjv59ynfv0e9 Frozen dependency installation passed. Core typecheck passed after removing two unused fixture bindings identified by the first run.
Same lease 16 focused suites: 409 passed, one existing macOS-only watchdog test skipped on Linux; 172.40s runner wall time, 176.26s remote command time.
Same lease Five changed test files with --maxWorkers=1: 312 passed in 57.66s. Gateway files: 16.25s; the existing 167-case CLI lifecycle suite: 38.75s. The CLI suite exceeds 30s because it exercises distinct shutdown/update races through the run-loop entry point; this change adds no process boots.
tbx_01m47zr9pv6zpnreth98phrhqr Final-head node scripts/check-changed.mjs --base f70dff05e8c0b9eee8d17cf95474a3e45731b4d0: passed, 34m02.621s remote command time. Includes core and all 27 selected test typecheck graphs, zero unused-export entries, lint, import-cycle and ownership guards.

Source preflights verified the exact base/head, changed paths, and file-content hashes. The focused runs preceded restoring the existing CLI exit adapters; final CLI production changes are comments only, and the final-head gate and CI verify the published tree. The final lint run reported one non-failing existing max-lines warning in the untouched server-close.agent-databases.test.ts.

Initial preparation found and resolved two unused bindings and the executable-line ratchet rejecting CLI inlining. A formatted-diff checksum was replaced by a source-content manifest check. Two subsequent sync timeouts occurred before gate execution; that lease was stopped. A queued replacement was retired when the head changed, and final proof used a fresh lease. All three leases are stopped.

Focused Testbox commands
node scripts/run-tsgo.mjs -p tsconfig.core.json --incremental \
  --tsBuildInfoFile .artifacts/tsgo-cache/core.tsbuildinfo

node scripts/run-vitest.mjs \
  src/cli/gateway-cli/run-loop.test.ts \
  src/cli/gateway-cli/run-loop.launchd.test.ts \
  src/cli/gateway-cli/run-loop-shutdown-budget.test.ts \
  src/cli/gateway-cli/run-loop.direct-stop-active-work.process.test.ts \
  src/cli/gateway-cli/run-loop.forced-cron.process.test.ts \
  src/cli/gateway-cli/run-loop.model-acquisition.process.test.ts \
  src/cli/gateway-cli/run-loop.restart-liveness.process.test.ts \
  src/gateway/chat-abort.test.ts \
  src/gateway/chat-abort-lifecycle-internal.test.ts \
  src/gateway/chat-abort.history-budget.test.ts \
  src/process/gateway-work-admission.test.ts \
  src/process/gateway-work-admission.continuation.test.ts \
  src/gateway/server-close.test.ts \
  src/gateway/server-close.metadata.test.ts \
  src/gateway/server-close.model-acquisition.test.ts \
  src/gateway/server-close.agent-databases.test.ts

node scripts/run-vitest.mjs \
  src/cli/gateway-cli/run-loop.test.ts \
  src/gateway/chat-abort.test.ts \
  src/gateway/chat-abort-lifecycle-internal.test.ts \
  src/gateway/chat-abort.history-budget.test.ts \
  src/gateway/server-close.test.ts --maxWorkers=1

Ready for lead review and landing. This PR remains unmerged, with no auto-merge request.

Consolidate close-owner grace handling and fixture types, preserve shutdown diagnostics in stronger lifecycle tests, and remove redundant tests and unreachable suspension checks. Keep restart, persistence, and admission behavior unchanged.
@clawsweeper

clawsweeper Bot commented Oct 6, 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 gateway Gateway runtime cli CLI command changes size: XL labels Oct 6, 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 Oct 6, 2026
@clawsweeper

clawsweeper Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 6, 2026, 3:07 AM ET / 07:07 UTC (Revision 2).

ClawSweeper review

What this changes

Consolidates Gateway shutdown grace handling and simplifies chat cleanup and duplicated lifecycle test fixtures while preserving existing shutdown behavior.

Merge readiness

✅ Ready for maintainer review

Keep open: this remains useful cleanup absent from current main, and no introduced correctness or security defect was found. The prior review’s empty finding list remains consistent with the inspected head.

Priority: P3
Reviewed head: 3c181dc8454209cf6e7eb9fab9b1c1f15219daa4

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Focused, useful consolidation with retained lifecycle coverage and no blocking findings.
Proof confidence 🌊 off-meta tidepool Not applicable: The verified repository-admin author is exempt from the external-contributor proof gate. Close-owner tracking and suspension admission preserve existing contracts; the reported Testbox lifecycle runs are supplemental validation, and no stored-data model changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The verified repository-admin author is exempt from the external-contributor proof gate. Close-owner tracking and suspension admission preserve existing contracts; the reported Testbox lifecycle runs are supplemental validation, and no stored-data model changes.
Evidence reviewed 8 items Pinned introduced change: Read all introduced hunks from the verified merge base to the original PR head; unrelated worktree changes belong to base drift. Raw test-merge parents match the pinned base followed by the exact PR head.
Close-owner equivalence: Hook tracking retains identical diagnostic names, rejection handling, and timeout warnings. All five runtime disposal callers retain their existing 5-second grace; raw cleanup still joins before registry and database retirement.
Suspension caller invariant: Both invalidation callers synchronously require a non-accepting suspension phase. Removing the already-accepting branch preserves notifications and the independent restart-drain fence; no authority-bearing contract changes.
Findings None None.
Security None None.

How this fits together

The Gateway shutdown owner receives stop and restart requests, drains accepted work, and closes runtime resources. Its completion controls when shared databases and process state can safely retire.

flowchart TD
  A[Stop or restart request] --> B[Close work admission]
  B --> C[Shutdown hooks and reply drain]
  C --> D[Runtime cleanup with grace]
  D --> E[Join pending cleanup and persistence]
  E --> F[Retire shared resources]
  F --> G[Restart or process exit]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -125, Tests -574. Total -699 across 19 files.

View PR surface stats
Area Files Added Removed Net
Source 6 52 177 -125
Tests 13 171 745 -574
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 19 223 922 -699

Review metrics

None.

Technical review

Best possible solution:

Keep one shutdown owner responsible for grace, diagnostics, and cleanup settlement, with the retained lifecycle coverage protecting resource retirement.

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

Not applicable: this PR proposes behavior-preserving cleanup rather than a reported defect; source and retained tests support the stated equivalence.

Is this the best way to solve the issue?

Yes: folding the adapters into the existing close owner and deriving fixture types removes duplication without creating another lifecycle owner.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 48b40f4909f6.

Labels

Label changes:

No label changes.

Label justifications:

  • P3: This is internal maintenance with preserved behavior and no new configuration or stored-data contract.
  • 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: The verified repository-admin author is exempt from the external-contributor proof gate. Close-owner tracking and suspension admission preserve existing contracts; the reported Testbox lifecycle runs are supplemental validation, and no stored-data model changes.

Evidence

What I checked:

  • Pinned introduced change: Read all introduced hunks from the verified merge base to the original PR head; unrelated worktree changes belong to base drift. Raw test-merge parents match the pinned base followed by the exact PR head. (3c181dc84542)
  • Close-owner equivalence: Hook tracking retains identical diagnostic names, rejection handling, and timeout warnings. All five runtime disposal callers retain their existing 5-second grace; raw cleanup still joins before registry and database retirement. (src/gateway/server-close.ts:245, 3c181dc84542)
  • Suspension caller invariant: Both invalidation callers synchronously require a non-accepting suspension phase. Removing the already-accepting branch preserves notifications and the independent restart-drain fence; no authority-bearing contract changes. (src/process/gateway-work-admission.ts:189, 3c181dc84542)
  • Retained stronger lifecycle coverage: Inspected the retained actual-hook/SQLite grace cases, SDK disposal failure cases, model-acquisition shutdown path, and fulfilled/rejected registration-removal cases. Pending-hook inventory assertions move into the retained SQLite cases rather than disappearing. (src/gateway/server-close.test.ts:511, 3c181dc84542)
  • Current main still needs the cleanup: The fetched main retains the pre-refactor close helpers and suspension condition. Comparing the merge base with fetched main shows no changes to these two production paths; no merged replacement for this cleanup is established. (src/gateway/server-close.ts:80, 48b40f4909f6)
  • Merged shutdown history: Recent main history records steipete’s shutdown diagnostics, drain consolidation, and interrupted-restart work. The merged diagnostics change at fix(gateway): identify blocked restart shutdown cleanup #165670 supplies behavior this cleanup preserves, rather than superseding the cleanup. (src/gateway/server-close.ts, 516c2a3497f2)

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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-06T07:00:14.359Z sha 3c181dc :: needs maintainer review before merge. :: none

@steipete
steipete marked this pull request as ready for review October 6, 2026 07:03
@steipete
steipete merged commit 58163bd into main Oct 6, 2026
225 of 226 checks passed
@steipete
steipete deleted the steipete/deslop-restart-shutdown-20261005 branch October 6, 2026 07:48
@steipete

steipete commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 7, 2026
Consolidate close-owner grace handling and fixture types, preserve shutdown diagnostics in stronger lifecycle tests, and remove redundant tests and unreachable suspension checks. Keep restart, persistence, and admission behavior unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes gateway Gateway runtime P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL 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