Skip to content

fix(gateway): Gateway rescans plugin files after sign-in, sign-out or config changes - #174860

Merged
obviyus merged 3 commits into
mainfrom
perf/lease-post-commit-scope
Oct 17, 2026
Merged

obviyus merged 3 commits into
mainfrom
perf/lease-post-commit-scope

Conversation

@obviyus

@obviyus obviyus commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #173626, #169562

What Problem This Solves

Fixes: after a config change, sign-in, sign-out or key removal, Gateway work that runs after the change is applied reloads plugin metadata from disk instead of using the inventory the Gateway just published.

User Impact

User impact: config reloads no longer rescan plugin files for cron reconciliation, model-runtime refresh, skills discovery or channels started by the reload. This keeps the Gateway event loop free for models.list and other requests during these events. No behavior change for plugin install, update or doctor flows.

Why This Change Was Made

Config hot reload runs inside withPluginLifecycleLease. The lease carries a fresh operation PluginCache through AsyncLocalStorage, so management reads see commits from other processes. Everything after the runtime commit inherited that cache too. getGatewayPluginMetadataSnapshot() only answers for the process cache, so post-commit readers (resolveProviderIdForAuth from cron job loading, model-id normalization, skills discovery capture, channel owners started by the reload) found no snapshot and reloaded metadata from disk. Long-lived owners started there also held a cache that the lease retires on release.

#173626 fixed the two hottest readers by passing the published snapshot explicitly (the #169562 pattern). This change fixes the owner: runAfterPluginLifecycleCommit (in plugin-lifecycle-lease.ts) leaves the lease's cache scope at each transaction owner's commit edge, after the new metadata is published:

  • config-reload.ts: onRuntimeConfigCommitted, onConfigApplied, and notifyCommitted (config.changed broadcast, skills discovery refresh).
  • server-reload-hot.ts: the cron drain, reconcile and start after commit, and the rest of the hot reload after commit (prepared model runtime refresh, MCP disposal, Gmail watcher, channel restarts, context windows).
  • server-reload-managed-secrets.ts: committed runtime policy reconcile.
  • server-plugin-reload.ts: the post-publication tail (memory and sidecar resume, lifecycle hooks, startPublishedChannels).

Work before the commit keeps the operation cache: config validation, install records, secrets preparation and plugin preflight still see other processes' commits. No management read runs after the commit. The cache-boundary docs gain one sentence.

Evidence

  • New regression test server-reload-hot.published-plugin-metadata.test.ts: real lifecycle lease, a published Gateway snapshot with a provider auth alias, and cron reconcileSystemJobs calling resolveProviderIdForAuth after the commit. It asserts the commit still runs in the operation cache, the alias resolves from the published snapshot, and loadPluginMetadataSnapshot is not called. Without the fix it fails: the reader loads empty metadata from disk and returns fixture-alias.
  • Focused local suites (config reload, lease retry, reload handlers, operator model policy, plugin reload, lifecycle lease): 400 pass. 7 cases in server-plugin-reload.recovery.test.ts fail locally; the identical set fails on the base head without this change.
  • Packaged-layout Gateway bench (sign-in, sign-out, key removal, plugin reload, settings change), with load tracing: the 19 post-commit skills-root rescans on the base drop to 0. The remaining loads are config-write validation before the commit (management, unchanged).
  • Main-thread CPU profiles, 4 interleaved runs: fix runs show no post-commit metadata loads. One base run spent 0.57 s there (model-id normalization and cron describeCronInferenceMigration → resolveProviderIdForAuth). Lag numbers were too noisy on the loaded host to report.

Simplification: one helper owned by the lease module and applied at four commit edges; no new state. #173626's explicit snapshot inputs stay; they are harmless explicit parameters and can be removed separately. Production delta: +50/-8 lines ignoring re-indentation; one test file.

@clawsweeper

clawsweeper Bot commented Oct 16, 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 size: L labels Oct 16, 2026
Base automatically changed from perf/plugin-inventory-reuse to main October 17, 2026 00:07
@openclaw-barnacle openclaw-barnacle Bot added the agents Agent runtime and tooling label Oct 17, 2026
@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. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. 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. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 17, 2026
@clawsweeper

clawsweeper Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR makes Gateway reload work use the published plugin inventory after committing configuration or plugin changes.

Example: A sign-out triggers configuration reload and cron reconciliation.

  • Before: Post-commit readers inherit the temporary management cache and rescan plugin files; the reported packaged Gateway benchmark recorded 19 skills-root rescans.
  • After: Those readers use the published inventory; the same reported benchmark recorded zero post-commit skills-root rescans.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused ownership fix with a meaningful regression, reported packaged Gateway profiling, passing production CI gate, and no actionable findings; scanner failures are independently corroborated infrastructure failures.
Proof confidence 🐚 platinum hermit (4/6) This maintainer-authored PR is outside the ordinary contributor proof gate; its body nevertheless reports packaged Gateway tracing across authentication and settings changes with zero post-commit rescans, supported by a focused real-lease regression.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Gateway requests can stall after sign-in, sign-out, or settings changes because committed runtime work rescans unchanged plugin packages.
Reason: The maintainer-authored direction restores the documented retained-inventory contract with one internal cache boundary and no new configuration or public API.

Merge readiness

✅ Ready for maintainer review

Keep open: this PR fixes a remaining post-commit metadata rescan on current main, preserves management isolation, and has no actionable code findings.

Priority: P2
Reviewed head: 1b316d2e27cff613177d554c8f09db618fa2d95a

Before merge

None.

Findings

None.

Agent review details

How this fits together

The plugin lifecycle lease gives management operations fresh metadata; Gateway publication selects the runtime inventory consumed by cron, model, skills, and channel owners.

flowchart TD
  A[Configuration or plugin change] --> B[Lifecycle lease]
  B --> C[Fresh management cache]
  C --> D[Runtime commit and inventory publication]
  D --> E[Leave temporary cache scope]
  E --> F[Published plugin inventory]
  F --> G[Cron models skills and channels]
Loading

Technical review

Best possible solution:

Land the focused cache-scope fix through normal merge gates while retaining fresh pre-commit management reads.

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

Source confirms that the lifecycle lease installs an operation cache which prevents post-commit readers from selecting Gateway metadata; the supplied regression and packaged Gateway report match that path, but no target code was executed during this read-only review.

Is this the best way to solve the issue?

The change fixes cache ownership at existing commit boundaries instead of threading snapshot arguments through every reader, while preserving lease authority and preparation isolation.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Lifecycle operation-cache isolation keeps the original intent (c6c2268: Management operations acquire fresh facts after lease ownership so they observe other processes' commits; runtime readers retain the published inventory.)
  • Post-publication plugin and hot-reload activation keeps the original intent (b5134de: One Gateway-owned prepare, drain, publish, and retire lifecycle applies plugin changes without restarting the Gateway.)
  • Configuration commit notifications keeps the original intent (c35b657: Apply Gateway config writes without waiting for file events and notify consumers after acceptance; the patch preserves notification ordering and changes their metadata read context.)
  • Committed runtime security-policy reconciliation keeps the original intent (8b7a1bb: Hot-reload auth limits and discovery policy; the patch retains policy commitment, reconciliation, and stale-client disconnection ordering.)
  • Plugin cache documentation keeps the original intent (54a9860: Remove obsolete Gateway restart guidance after live plugin lifecycle support; the added sentence clarifies the existing runtime-versus-management boundary.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +36, Tests +100, Docs +2, Other -1. Total +137 across 9 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 5 219 183 +36
Tests 2 102 2 +100
Docs 1 3 1 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 1 0 1 -1
Total 9 324 187 +137

Labels

Label changes:

  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove proof: sufficient: Current real behavior proof status is not_applicable, not sufficient.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: Repeated metadata scans delay Gateway requests after routine configuration and authentication changes, with bounded performance impact.
  • 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.

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 (1 earlier review cycle)
  • reviewed 2026-10-17T00:23:25.010Z sha f67343640282e860b09c7073625653e87f3d9ad0 :: needs changes before merge. :: none

Reviewed October 16, 2026, 11:23 PM ET / October 17, 2026, 03:23 UTC (Revision 2).

…ventory

Config hot reload holds the plugin lifecycle lease, which carries a fresh
operation plugin cache so management reads see other processes' commits.
Gateway runtime work after the commit inherited that cache through
AsyncLocalStorage: commit listeners, cron reconciliation, the prepared
model runtime refresh, skills discovery and channel owners started by
the reload could not see the published inventory and reloaded plugin
metadata from disk.

runAfterPluginLifecycleCommit leaves the lease's cache scope at each
transaction owner's commit edge, after the new metadata is published.
Work before the commit keeps the operation cache.
@obviyus
obviyus force-pushed the perf/lease-post-commit-scope branch from f673436 to 8253dec Compare October 17, 2026 01:12
@obviyus
obviyus marked this pull request as ready for review October 17, 2026 01:12
@obviyus obviyus changed the title perf(gateway): post-commit reload work rescans plugin metadata after config changes fix(gateway): Gateway rescans plugin files after sign-in, sign-out or config changes Oct 17, 2026
@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: 1b316d2e27cff613177d554c8f09db618fa2d95a
  • Maintainer: @obviyus
  • Repository role: admin

These security sensitive changes were made:

  • src/gateway/server-reload-managed-secrets.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.

Carefully review these changes before merging.

@openclaw-barnacle openclaw-barnacle Bot removed the agents Agent runtime and tooling label Oct 17, 2026
@obviyus

obviyus commented Oct 17, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added the clawsweeper:intake:bug Preliminary submission classification; full source review pending. label Oct 17, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 17, 2026
@obviyus
obviyus merged commit a5dee9e into main Oct 17, 2026
131 of 138 checks passed
@obviyus
obviyus deleted the perf/lease-post-commit-scope branch October 17, 2026 03:27
@obviyus

obviyus commented Oct 17, 2026

Copy link
Copy Markdown
Collaborator Author

Landed in a5dee9e.

Bug: config reload runs inside the plugin lifecycle lease, whose fresh operation cache leaked into work after the commit. Cron, model-runtime refresh, skills discovery and channels started by the reload could not see the published plugin inventory and reloaded plugin metadata from disk.

Fix: runAfterPluginLifecycleCommit leaves the lease's cache scope at each reload owner's commit edge. Work before the commit still reads fresh facts from other processes.

Proof: new regression test (real lease, cron auth-alias reader after commit, no metadata load; fails without the fix), packaged-Gateway trace (19 post-commit skills-root rescans to 0), green CI and ClawSweeper ready on the exact head.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 17, 2026
… config changes (openclaw#174860)

Related: openclaw#173626, openclaw#169562

## What Problem This Solves

Fixes: after a config change, sign-in, sign-out or key removal, Gateway work that runs after the change is applied reloads plugin metadata from disk instead of using the inventory the Gateway just published.

## User Impact

User impact: config reloads no longer rescan plugin files for cron reconciliation, model-runtime refresh, skills discovery or channels started by the reload. This keeps the Gateway event loop free for `models.list` and other requests during these events. No behavior change for plugin install, update or doctor flows.

## Why This Change Was Made

Config hot reload runs inside `withPluginLifecycleLease`. The lease carries a fresh operation `PluginCache` through AsyncLocalStorage, so management reads see commits from other processes. Everything after the runtime commit inherited that cache too. `getGatewayPluginMetadataSnapshot()` only answers for the process cache, so post-commit readers (`resolveProviderIdForAuth` from cron job loading, model-id normalization, skills discovery capture, channel owners started by the reload) found no snapshot and reloaded metadata from disk. Long-lived owners started there also held a cache that the lease retires on release.

openclaw#173626 fixed the two hottest readers by passing the published snapshot explicitly (the openclaw#169562 pattern). This change fixes the owner: `runAfterPluginLifecycleCommit` (in `plugin-lifecycle-lease.ts`) leaves the lease's cache scope at each transaction owner's commit edge, after the new metadata is published:

- `config-reload.ts`: `onRuntimeConfigCommitted`, `onConfigApplied`, and `notifyCommitted` (config.changed broadcast, skills discovery refresh).
- `server-reload-hot.ts`: the cron drain, reconcile and start after commit, and the rest of the hot reload after commit (prepared model runtime refresh, MCP disposal, Gmail watcher, channel restarts, context windows).
- `server-reload-managed-secrets.ts`: committed runtime policy reconcile.
- `server-plugin-reload.ts`: the post-publication tail (memory and sidecar resume, lifecycle hooks, `startPublishedChannels`).

Work before the commit keeps the operation cache: config validation, install records, secrets preparation and plugin preflight still see other processes' commits. No management read runs after the commit. The cache-boundary docs gain one sentence.

## Evidence

- New regression test `server-reload-hot.published-plugin-metadata.test.ts`: real lifecycle lease, a published Gateway snapshot with a provider auth alias, and cron `reconcileSystemJobs` calling `resolveProviderIdForAuth` after the commit. It asserts the commit still runs in the operation cache, the alias resolves from the published snapshot, and `loadPluginMetadataSnapshot` is not called. Without the fix it fails: the reader loads empty metadata from disk and returns `fixture-alias`.
- Focused local suites (config reload, lease retry, reload handlers, operator model policy, plugin reload, lifecycle lease): 400 pass. 7 cases in `server-plugin-reload.recovery.test.ts` fail locally; the identical set fails on the base head without this change.
- Packaged-layout Gateway bench (sign-in, sign-out, key removal, plugin reload, settings change), with load tracing: the 19 post-commit skills-root rescans on the base drop to 0. The remaining loads are config-write validation before the commit (management, unchanged).
- Main-thread CPU profiles, 4 interleaved runs: fix runs show no post-commit metadata loads. One base run spent 0.57 s there (model-id normalization and cron `describeCronInferenceMigration` → `resolveProviderIdForAuth`). Lag numbers were too noisy on the loaded host to report.

Simplification: one helper owned by the lease module and applied at four commit edges; no new state. openclaw#173626's explicit snapshot inputs stay; they are harmless explicit parameters and can be removed separately. Production delta: +50/-8 lines ignoring re-indentation; one test file.

Co-authored-by: Ayaan Zaidi <[email protected]>
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 P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. security-sensitive-changed size: L 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