Skip to content

fix(plugins): retain service cleanup through late startup - #140132

Merged
steipete merged 2 commits into
mainfrom
codex/plugin-service-startup-settlement
Sep 6, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/plugin-service-startup-settlement

Conversation

@steipete

@steipete steipete commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Strict plugin-service shutdown could call and memoize stop() while startup was still pending. If startup later acquired native listeners, final shutdown reused the completed cleanup and left those listeners registered. Failed partial reloads could also lose an unstarted sibling or reverse the next retry's startup order.

Keep each issued startup attempt and its one cleanup operation owned independently of caller deadlines. Healthy services clean up without waiting for unrelated startup; exporters follow actual producer cleanup and the bounded diagnostic drain. Replacements occupy the prior registration's slot, preserving retry order. Existing ordinary versus strict error handling and separate one-shot drain/flush windows remain intact.

Validated with causal failures followed by 66 passing service checks, including actual native listeners, dependency-ordered retries, concurrent deadlines, and one-shot exporter flush windows. The full changed-file gate passed. Independent P2 review findings were reproduced and fixed where actionable. The remaining overlap finding was rejected after an isolated main/candidate comparison confirmed the same existing exporter-only reload boundary: an exporter can already stop before later shutdown events, with exactly one cleanup in both versions. The current trace implementation also has no yielding prelude before invoking startup.

Production: +13 lines after removing the global startup/reload wait and duplicate mutation path. Tests: +180 lines. Documentation clarifies retained cleanup and explicit reload retries.

Split from the restart-free plugin lifecycle work in #135599. This PR fixes existing service ownership; it does not introduce the Gateway reload interface.

CI follow-through corrected the Gateway caller test that still expected cleanup before its held startup completed. All 117 Gateway startup tests pass, including cleanup already queued before final stop. A separate profiler invalid-option test timed out in the initial CI run; the exact case and its full 34-case file passed unchanged locally, so no speculative timeout or code change was made.

Exact-head CI passed at 8f26125d1b13d2e1d565be8b86c070dd869c4b7a, including the corrected startup-order case and unchanged profiler tests.

@clawsweeper

clawsweeper Bot commented Sep 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 the docs Improvements or additions to documentation label Sep 6, 2026
@steipete steipete self-assigned this Sep 6, 2026
@openclaw-barnacle openclaw-barnacle Bot added size: M maintainer Maintainer-authored PR labels Sep 6, 2026
@steipete
steipete marked this pull request as ready for review September 6, 2026 13:21
@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 6, 2026
@clawsweeper

clawsweeper Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 6, 2026, 9:53 AM ET / 13:53 UTC.

ClawSweeper review

What this changes

The PR retains plugin service cleanup until startup settles, preserves retry order after failed reloads, and updates regression tests and lifecycle documentation.

Merge readiness

✅ Ready for maintainer review

This remains a useful, focused repair: current main still permits premature cleanup and loses pending restart registrations after a failed reload. No blocking introduced defect was found, and the latest Gateway test correction matches the repaired lifecycle.

Priority: P2
Reviewed head: 8f26125d1b13d2e1d565be8b86c070dd869c4b7a

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with meaningful regression coverage and no identified blocking defect.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied MEMBER association exempts this PR from the external-contributor proof gate. Its reported validation exercises the service owner with native listeners and Gateway cleanup ordering; these are test claims, not independently observed live execution.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied MEMBER association exempts this PR from the external-contributor proof gate. Its reported validation exercises the service owner with native listeners and Gateway cleanup ordering; these are test claims, not independently observed live execution.
Evidence reviewed 8 items Current main still needs the repair: Current main memoizes stop independently of pending startup after the global startup wait expires. Its reload path removes every selected registration before restarting them, allowing an early restart failure to discard later selections.
Cleanup remains owned across deadlines: Cleanup is memoized per service attempt, waits for raw startup settlement, and remains available to subsequent shutdown callers. Reload replaces registrations in their existing slots. Exporter cleanup follows actual producer cleanup.
Regression coverage exercises observable resources: Added cases cover initial startup and reload, listener removal after a strict deadline, dependency-ordered retries, and cleanup of an already-started sibling. Existing cases check concurrent deadlines and rejection of stale route registration and event emission. Tests were inspected, not executed during this read-only review.
Findings None None.
Security None None.

How this fits together

The Gateway starts background services registered by plugins and owns their reload and shutdown. This lifecycle coordinates resource cleanup, capability revocation, and diagnostic exporter shutdown.

flowchart TD
  A[Plugin registrations] --> B[Service startup]
  B --> C[Retained startup and cleanup owner]
  D[Reload or shutdown request] --> C
  C --> E[Caller deadline]
  E --> F[Timeout revokes capabilities]
  C --> G[Cleanup after startup settles]
  G --> H[Diagnostic drain and exporter stop]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +13, Tests +180, Docs 0. Total +193 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 1 67 54 +13
Tests 2 182 2 +180
Docs 1 1 1 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 250 57 +193

Review metrics

Metric Value Why it matters
Production versus regression coverage production +13 lines net; tests +180 lines net The production growth retains per-attempt lifecycle ownership, with regression coverage for leaked listeners, retry ordering, and Gateway cleanup.

Technical review

Best possible solution:

Keep one cleanup owner per startup attempt, preserve registration order across retries, and retain deadline-based capability fencing.

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

Yes, from source: hold service startup past a strict stop deadline, then acquire a listener before startup settles; main has already memoized cleanup. A failed first restart also leaves later selected registrations absent. This review did not execute either scenario.

Is this the best way to solve the issue?

Yes. Retaining settlement and cleanup at the service owner repairs both lifecycle failures without adding a parallel API, configuration option, or persistent state.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This repairs bounded plugin startup and reload cleanup failures without evidence of a widespread active outage.
  • 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 supplied MEMBER association exempts this PR from the external-contributor proof gate. Its reported validation exercises the service owner with native listeners and Gateway cleanup ordering; these are test claims, not independently observed live execution.

Evidence

What I checked:

  • Current main still needs the repair: Current main memoizes stop independently of pending startup after the global startup wait expires. Its reload path removes every selected registration before restarting them, allowing an early restart failure to discard later selections. (src/plugins/services.ts:252, ba457124711d)
  • Cleanup remains owned across deadlines: Cleanup is memoized per service attempt, waits for raw startup settlement, and remains available to subsequent shutdown callers. Reload replaces registrations in their existing slots. Exporter cleanup follows actual producer cleanup. (src/plugins/services.ts:262, 8f26125d1b13)
  • Regression coverage exercises observable resources: Added cases cover initial startup and reload, listener removal after a strict deadline, dependency-ordered retries, and cleanup of an already-started sibling. Existing cases check concurrent deadlines and rejection of stale route registration and event emission. Tests were inspected, not executed during this read-only review. (src/plugins/services.replacement.test.ts:68, 8f26125d1b13)
  • Gateway caller and re-review continuity: The prior completed review retained no findings. The only subsequent change moves the Gateway test's stop assertion until after startup settlement; the test still requires final shutdown to join the same pending cleanup. (src/gateway/server-startup-post-attach.test.ts:2672, 8f26125d1b13)
  • Revoked capabilities remain fenced: Service cleanup still revokes its lease after completion or timeout. HTTP registration checks inherited leases before adding routes, including continuations carrying an explicit registry. Delaying cleanup does not grant a replacement lease or bypass this check. (src/plugins/http-registry.ts:225, 8f26125d1b13)
  • Feature-history routing: Current-main history records Peter Steinberger's work on interrupted service cleanup, diagnostic reloads, and exporter flush windows. Historical parent blobs were unavailable, so this supports routing rather than source-line introduction attribution. (src/plugins/services.ts, 1de2ca25c3af)

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-09-06T13:26:53.874Z sha 8e6c69a :: needs maintainer review before merge. :: none

@openclaw-barnacle openclaw-barnacle Bot added the gateway Gateway runtime label Sep 6, 2026
@steipete
steipete merged commit ec46a50 into main Sep 6, 2026
186 of 187 checks passed
@steipete
steipete deleted the codex/plugin-service-startup-settlement branch September 6, 2026 14:09
@steipete

steipete commented Sep 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 Sep 7, 2026
…40132)

* fix(plugins): retain service cleanup through late startup

* test(gateway): assert deferred service cleanup ordering
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. 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