Skip to content

fix(agents): plugin completions fail after another plugin reloads - #168916

Merged
jalehman merged 2 commits into
mainfrom
fix/retained-plugin-runtime
Oct 11, 2026
Merged

jalehman merged 2 commits into
mainfrom
fix/retained-plugin-runtime

Conversation

@jalehman

Copy link
Copy Markdown
Contributor

Closes #156026

What Problem This Solves

Fixes: an unchanged plugin's api.runtime.llm.complete fails with Plugin inventory has retired; begin a new plugin operation. after the Gateway hot-replaces a different plugin.

User Impact

Context engines such as lossless-claw keep summarizing after an unrelated plugin reload instead of failing until the Gateway restarts. No configuration or operator action is required.

Why This Change Was Made

Replacement keeps unchanged plugin instances and their original api; api.runtime.llm is not bound to an inventory. The failure comes from the ambient async context. A context engine restores the AsyncLocalStorage snapshot captured when its factory resources were created, which carries the earlier turn's plugin runtime generation. A new completion started from that context resolved metadata from the retired inventory, and retainPluginCache rejected it before reaching the provider.

Simple-completion acquisition now starts each new completion outside the inherited generation scope, the same boundary that #151232 applied to compaction admission. Caller authority, invocation scope, cancellation, drainage, and retirement checks are unchanged. Already-prepared completions keep their own lease. Because the fix is in the shared acquisition owner, it also covers the plugin SDK prepareSimpleCompletionModelForAgent, exec auto-review, TTS summaries, and approval intent.

This is a smaller replacement for #161908, which has gone stale against main. The docs now state that retained instances are not registered again and that plugin-wide runtime capabilities select the committed inventory per call.

Evidence

  • Live symptom (build 2026.9.9): Plugin replacement applied: knowledge at 08:44:41, then lossless-claw background compaction failed at 08:45:35 with the retired-inventory error from retainPluginCache.
  • New regression src/plugins/runtime/runtime-llm.retained-generation.test.ts loads a provider plugin through the real loader and publishes a Gateway inventory. It creates ContextEngineFactoryResources under an admitted turn generation, then publishes a replacement inventory and retires the old cache. Finally it calls the real createRuntimeLlm().complete() from the retained engine context against a loopback SSE provider.
    • Before the fix: fails with Plugin inventory has retired at retainPluginCache ← prepareWorkspaceBuildGroup ← buildSnapshotBatch, the same stack as the live failure.
    • After the fix: passes, with exactly one provider request.
    • Cost: about 1.1 s of test time; pnpm test <file> --maxWorkers=1 takes 35.8 s wall time, mostly transform. Expect a few CI seconds.
  • Focused siblings passed: simple-completion-runtime{,.generation,.plugin-scope,.selected-model,.selection}, runtime-llm.{runtime,prepared-owner,oauth-model.integration,operator-model-policy}, exec-auto-reviewer*, approval-intent*, tts-summary*, tts-core.summary-agent, plugins/commands, and compact.delegate-resources.
  • pnpm check:changed passed every ratchet. The first-party mock-export baseline shrank by two exact entries because the touched mocks now document their isolation. typecheck core and tsgo:core:test report only the inherited main error src/cli/gateway-cli/run-loop-startup.test-support.ts(380,13) from fix: restore channel startup after stopped Tailscale failures #162266; this branch adds no new type errors.
  • oxlint and oxfmt are clean on the changed files. format:docs:check and lint:docs pass.
  • Autoreview (codex, --mode branch --base origin/main --max-priority P2) is scoped-clean.
  • Gap: I did not reload a plugin on a real dist-backed Gateway. The regression drives the real loader, metadata publication, prepared-runtime refresh, and cache retirement owners, but not server-plugin-reload.ts itself.

@clawsweeper

clawsweeper Bot commented Oct 11, 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 commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR makes new model completions select the committed plugin inventory instead of inheriting a retired generation.

Example: A retained lossless-claw context engine requests a summary after the knowledge plugin reloads.

  • Before: Completion fails before provider dispatch with “Plugin inventory has retired; begin a new plugin operation.”
  • After: The new completion acquires the committed inventory and reaches the provider.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A useful, focused repair with no concrete introduced defect; confidence is limited to reported in-process regression results and source inspection.
Proof confidence 🦐 gold shrimp (3/6) The supplied host facts classify this as maintainer-authored, outside the ordinary contributor proof gate; the inspected new regression exercises real acquisition and HTTP transport owners but does not run the shipped Gateway reload entry point.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: An unchanged plugin stops completing summaries after another plugin reloads, despite a usable replacement runtime.
Reason: This restores an existing completion capability through a narrow shared-owner change, without new settings or public signatures.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: current main still supports the reported retired-inventory failure, and the focused shared-owner repair has no actionable introduced defect.

Priority: P1
Reviewed head: 96da463c39f29e3cfd3b9e8f78b74ccacc5f4883

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied regression reports the intended before/after failure, but this patch has no dist-backed Gateway trace exercising actual plugins.reload followed by a completion from the same retained engine.
Agent review details

How this fits together

The shared completion owner receives model-selection requests from plugins, SDK callers, TTS, and approval helpers, then acquires model, credential, and transport facts for provider execution.

flowchart LR
  A[Retained plugin context] --> B[New completion admission]
  B --> C[Committed plugin inventory]
  C --> D[Prepared model lease]
  D --> E[Caller and model authorization]
  E --> F[Provider request]
  F --> G[Completion result]
Loading

Technical review

Best possible solution:

Admit new completions against the committed inventory while preserving prepared leases, caller authority, cancellation, and retirement safeguards.

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

Current main supports the retained-context → immutable old metadata → retired-cache rejection path, matching the linked failure/control probe; this read-only review ran no target code.

Is this the best way to solve the issue?

The patch repairs fresh admission in the existing shared owner and preserves the prior generation-pinning and selected-model contracts, avoiding separate fixes in each consumer.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Prepared completion generation ownership keeps the original intent (3b3af11: Keep rematerialization, runtime authentication, and execution on one prepared generation across reloads.)
  • Shared model selection and acquisition keeps the original intent (bdb6116: Preserve the selected summary model and avoid applying aliases twice while sharing metadata capture and acquisition.)
  • Retained plugin instances across replacement keeps the original intent (b5134de: Apply plugin changes without Gateway restarts while retaining unaffected instances and their existing consumers.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit bdb6116 adds src/agents/simple-completion-runtime.ts:538 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: bdb61168c086; files: src/agents/simple-completion-runtime.ts)

PR surface

Source +21, Tests +157, Docs 0, Other -2. Total +176 across 6 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 1 31 10 +21
Tests 3 157 0 +157
Docs 1 1 1 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 0 2 -2
Total 6 189 13 +176

Review metrics

Metric Value Why it matters
Production versus test growth Production net +21 lines; tests +157 lines Production growth isolates one shared acquisition boundary; the test growth adds a distinct retained-context regression through real lifecycle and transport owners.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #156026
Summary: This PR is a focused candidate for the canonical retained-generation completion defect; a larger open PR addresses the same root cause.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

  • add P1: The linked production incident and current source show post-reload plugin summarization can fail before inference.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P1: The linked production incident and current source show post-reload plugin summarization can fail before inference.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Increase confidence with redacted logs from an actual Gateway plugin reload followed by successful completion from the same retained context engine.

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 need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

Reviewed October 11, 2026, 1:51 AM ET / 05:51 UTC.

@jalehman
jalehman merged commit f30bfc6 into main Oct 11, 2026
117 of 118 checks passed
@jalehman
jalehman deleted the fix/retained-plugin-runtime branch October 11, 2026 11:31
RomneyDa pushed a commit that referenced this pull request Oct 12, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 12, 2026
scribe-dandelion-cult added a commit to karmaterminal/openclaw that referenced this pull request Oct 19, 2026
First-parent upstream 75df19c..5ed6a30 (23 commits, including
openclaw#169005 infrastructure SQLite work and runtime-write offload, openclaw#169062,
openclaw#136677, openclaw#169070, openclaw#168857 plugin-sdk SQLite runtime writes into workers,
openclaw#169038, openclaw#168916, openclaw#169053, openclaw#169052 closed-turn transcript work in
workers, openclaw#168974, openclaw#168811, openclaw#169082, openclaw#169084, openclaw#166581 worker heap limits).

Conflicts:
- openclaw-state-worker-runtime.ts: upstream routes more update-run
  mutations to the worker; our continuation custody dispatch stays ahead
  of that branch.
- worker-access inventory: regenerated (632 files, 2429 calls).

server-restart-sentinel.ts auto-merged: upstream's awaited update-run
writes; our continuation restart delivery is unaffected.

Refs #1475

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: runtime.llm.complete inherits retired plugin inventory after hot reload

1 participant