Skip to content

fix(plugins): keep plugin instance cleanup budget on the monotonic clock - #181675

Merged
steipete merged 2 commits into
openclaw:mainfrom
SunnyShu0925:fix/plugin-instance-cleanup-deadline-monotonic-129
Oct 25, 2026
Merged

steipete merged 2 commits into
openclaw:mainfrom
SunnyShu0925:fix/plugin-instance-cleanup-deadline-monotonic-129

Conversation

@SunnyShu0925

@SunnyShu0925 SunnyShu0925 commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: plugin disposal can report a false cleanup timeout, or extend its cleanup wait, when the host wall clock changes during shutdown.

User Impact

A healthy plugin receives the existing five-second elapsed-time cleanup budget even when the system clock jumps. Physical cleanup and ownership remain unchanged.

Why This Change Was Made

The instance cleanup owner creates and consumes its deadline with performance.now(). The regression steps the wall clock inside an ordinary cleanup callback and checks the disposal result. It replaces clock-call instrumentation and nested fake-timer advancement with one outcome test.

Production: +8/-4 (net +4), consisting of two clock substitutions and the formatter's expanded call layout; no meaningful nearby deletion was justified. Tests: +15. Thanks to @SunnyShu0925 for the fix and original regression.

Evidence

  • At main 397807c7374c41ffe434215e1e091edba2997474, both the fake-time regression and temporary real-timer probe failed: healthy cleanup was reported as unsettled. The real callback completed in 1502 ms with one error.

  • Fixed full file: 36/36 passed, including the temporary probe (removed afterward). The same real callback completed in 1502 ms with zero errors. The retained regression took 5 ms and adds no real wait.

  • Command: TMPDIR=/private/tmp/oc-ct-monoA pnpm test src/plugins/plugin-instance.test.ts --maxWorkers=1; red selected -t 'wall clock jumps forward'. Red wrapper 167.35 s, green wrapper 220.21 s, dominated by cold worker preparation; green Vitest duration 166.84 s.

  • Independent diff review found no actionable P0–P2 findings. A later lint-only Promise-executor brace correction preserves the reviewed behavior. Targeted type-aware oxlint, oxfmt, and git diff --check passed. Full Gateway shutdown was not independently live-tested in this revision; the local real-timer proof reaches PluginInstance.dispose, while the contributor's Gateway trace is retained below.

  • Exact-head CI run 40143661603 failed only checks-node-changed-compact-large-11 and its aggregate gate. This is inherited: scheduled-main run 40142877272, job checks-node-compact-large-27 has the same 15 failed session-catalog-progress.test.ts cases and client?.connect.scopes TypeError. The relevant visibility owner and test fixtures are byte-identical between both heads. No unrelated repair or CI rerun was performed.

Contributor-supplied Gateway proof

The original contributor supplied this shutdown comparison at 88211c9b2402c695f32dfbac6dc76dce63e29791. The traces were inspected, not independently rerun during this revision. The production fix is unchanged.

Real shipped-entry Gateway run (startGatewayServer) plus a real PluginInstance whose onDispose registers a cleanup that consumes 3.5s of real time then settles (physical settlement). The plugin is loaded into the Gateway's own active plugin registry (the registryOwner singleton server.close() retires), and retirement is driven by the shipped shutdown path: server.close() → closePluginRegistry → pluginRegistryOwner.close() → clearActivePluginRegistry() → disposePluginRegistryInstances() → createPluginHostRegistryRetirement → instance.dispose() → runDisposalCleanup → raceWithTimeout. A wall-clock step is injected into Date.now between the deadline seed and the remaining-budget read (pre-fix only — fixed code reads performance.now() and never arms the injection). Observed outcome: the raceWithTimeout budget and the shutdown log's "did not settle" failures (the failures the shipped shutdown path reports).

Post-fix — all clock states keep a stable monotonic budget, 0 shutdown failures:

step=0      budgets: 5000, 4999ms   shutdown failures=0  settled ✓
step=+3000  budgets: 5000, 4999ms   shutdown failures=0  settled ✓
step=-3000  budgets: 5000, 4999ms   shutdown failures=0  settled ✓

Pre-fix (source reverted to Date.now()) — a forward jump collapses the budget and the shipped shutdown path reports mis-kill failures:

step=+3000  budgets: 5000, 1999ms   shutdown failures=2  settled ✓  → MIS-KILLED
step=0      budgets: 5000, 4999ms   shutdown failures=0  settled ✓
step=-3000  budgets: 5000, 7999ms   shutdown failures=0  settled ✓  (budget inflated)

settled ✓ in every run — physical settlement is always preserved. The bug: a forward wall-clock jump shrinks the pre-fix budget to ~1999ms, so the healthy 3.5s cleanup is reported by the shipped shutdown path as a "did not settle" failure (2 failures in the shutdown log) even though it settles; post-fix the budget stays on the monotonic clock (~5000ms) and the same cleanup settles with 0 shutdown failures in every clock state.

Before / After

Clock state Before (Date.now()) After (performance.now())
normal clock 4999ms budget, 0 failures 4999ms budget, 0 failures
clock rewind −3000ms 7999ms budget (inflated) 4999ms budget, 0 failures
clock jump +3000ms 1999ms budget → healthy cleanup mis-killed (2 failures) 4999ms budget, 0 failures

@clawsweeper

clawsweeper Bot commented Oct 23, 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.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 23, 2026
@SunnyShu0925
SunnyShu0925 force-pushed the fix/plugin-instance-cleanup-deadline-monotonic-129 branch from e59dc54 to 217d4d7 Compare October 23, 2026 14:13
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 23, 2026
@clawsweeper

clawsweeper Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR measures plugin-instance cleanup deadlines with a monotonic clock so system-clock adjustments cannot distort the cleanup budget.

Example: The system clock advances 3000 ms before a plugin's 3500 ms cleanup completes.

  • Before: The remaining budget shrinks to about 2000 ms and shutdown reports false cleanup failures.
  • After: The budget remains about 5000 ms and cleanup completes without shutdown failures.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A minimal owner-level correction with a meaningful outcome regression and applicable shipped shutdown evidence.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (logs): Contributor-supplied Gateway server.close() traces exercise the active registry's real PluginInstance cleanup with a 3500 ms callback and forward/backward clock steps, showing stable budgets and zero false failures after the fix; the current production patch is unchanged, and the revised regression also has recorded red/green real-timer support.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A healthy plugin can be reported as failing cleanup when the system clock advances during shutdown.
Reason: The patch restores the existing elapsed-time budget with no new option, state, or public API.

Merge readiness

✅ Ready for maintainer review

This PR fixes a current-main cleanup timing bug with a focused patch and applicable Gateway shutdown proof; no actionable findings remain, and exact-head CI is pending.

Priority: P2
Reviewed head: 10ca908ffd9d34971b94b45046e557fc67fc33ad

Before merge

None.

Findings

None.

Agent review details

How this fits together

Gateway registry retirement invokes PluginInstance disposal, which runs registered cleanup callbacks and returns cleanup failures while retaining ownership until physical settlement.

flowchart TD
  A[Gateway shutdown] --> B[Registry retirement]
  B --> C[PluginInstance disposal]
  C --> D[Monotonic cleanup deadline]
  D --> E[Registered cleanup callbacks]
  E --> F[Physical settlement and failure report]
Loading

Technical review

Best possible solution:

Keep deadline creation and remaining-budget calculation on performance.now() within the existing cleanup owner.

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

Current-main source exposes the clock-domain mismatch, supported by supplied red-base regression and Gateway shutdown traces; no target code was executed during this read-only review.

Is this the best way to solve the issue?

The two clock substitutions restore elapsed-time accounting without adding machinery or changing cleanup ownership, public contracts, or timeout values.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Plugin-instance cleanup deadline and timeout observation keeps the original intent (05a2844: Retain plugin work and resources through retirement; the later ab4d26a refactor centralized observation-only timeouts while preserving owner settlement.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +4, Tests +15. Total +19 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 8 4 +4
Tests 1 15 0 +15
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 23 4 +19

Labels

Label changes:

No label changes.

Label justifications:

  • P2: System-clock adjustments can produce false plugin cleanup failures, with limited shutdown impact and physical settlement preserved.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (4 earlier review cycles)
  • reviewed 2026-10-23T14:31:25.736Z sha 217d4d7a04056a5e77bca597e3cb695094b1f0fd :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-23T16:36:32.073Z sha c290f643cfba2729bf0b7ff8e2b94fba9bd7cd6a :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-24T00:23:34.219Z sha 3360279a4dcb72d43baff9bf4024f15eb89ee75f :: needs real behavior proof before merge. :: [P3] Remove the unused retry-module mock
  • reviewed 2026-10-24T04:30:22.052Z sha 88211c9 :: needs maintainer review before merge. :: none

Reviewed October 24, 2026, 7:45 PM ET / 23:45 UTC (Revision 5).

@SunnyShu0925
SunnyShu0925 force-pushed the fix/plugin-instance-cleanup-deadline-monotonic-129 branch from 217d4d7 to c290f64 Compare October 23, 2026 16:28
@clawsweeper

clawsweeper Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 23, 2026
@SunnyShu0925
SunnyShu0925 force-pushed the fix/plugin-instance-cleanup-deadline-monotonic-129 branch from c290f64 to 3360279 Compare October 23, 2026 19:13
@clawsweeper

clawsweeper Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 24, 2026
@clawsweeper

clawsweeper Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 24, 2026
Keep deadline creation and consumption on the same monotonic clock.
Replace clock-call instrumentation with a single disposal outcome regression.

Co-authored-by: SunnyShu <0668000539@local>
@steipete

Copy link
Copy Markdown
Contributor

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 24, 2026
@steipete
steipete merged commit 096041e into openclaw:main Oct 25, 2026
148 of 154 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 26, 2026
…ock (openclaw#181675)

Measure plugin cleanup observation with a monotonic clock. A wall-clock jump during an ordinary cleanup callback no longer creates a false cleanup timeout.

Focused regression tests and a real-timer PluginInstance probe pass. Cleanup ownership and callback behavior are preserved.

Co-authored-by: SunnyShu <[email protected]>
RomneyDa added a commit that referenced this pull request Oct 28, 2026
…ock (#181675)

Measure plugin cleanup observation with a monotonic clock. A wall-clock jump during an ordinary cleanup callback no longer creates a false cleanup timeout.

Focused regression tests and a real-timer PluginInstance probe pass. Cleanup ownership and callback behavior are preserved.

Co-authored-by: SunnyShu <[email protected]>

(cherry picked from commit 096041e)
Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit 0073aad4972dbf1c4494293d76d5072cbecef182)
RomneyDa added a commit that referenced this pull request Oct 29, 2026
…nd realign npm override fixture (#187562)

* fix(plugins): restore non-blocking setup artifact retirement on release

Revert the stray plugin-instance.ts hunk carried into the release
backport of #183606 (an auto-reply-only change on main), which tracked
module release in the caller's work scope and made setup cache
retirement wait on artifact removal. Realign the matching release-only
owner-drain assertion added with #181675 to the main test.

* test(plugins): expect nested npm form for exact-parent overrides

#187293 intentionally maps pnpm exact-parent selectors ([email protected]>child)
to npm's nested override form on this train. Realign the npm-spec
selector fixture to that behavior; the npm-alias retry still drops it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor 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.

2 participants