Skip to content

fix(agents): keep retained plugin completions working after reload - #161908

Open
roboclaw-bot wants to merge 2 commits into
mainfrom
openclaw/fix-completion-generation-replacement
Open

roboclaw-bot wants to merge 2 commits into
mainfrom
openclaw/fix-completion-generation-replacement

Conversation

@roboclaw-bot

@roboclaw-bot roboclaw-bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Fixes: context engines and other retained plugins lose new model completions after another plugin reloads, or select stale model metadata while a reload is completing.

Closes #156026. Replaces #156053, which its contributor closed; that PR and its fork branch remain untouched.

User Impact

Retained plugin consumers can request new completions after reload. The admitted model must still satisfy host and operator policy before provider dispatch. No configuration, schema, migration, or operator action is required.

Why This Change Was Made

The existing prepared-runtime lease now derives each new completion's selection after pending replacement finishes. Selection and admitted config stay together; execution receives the selected metadata view, not the entire planning inventory. Existing prepared completions retain their original ownership. Caller authority, cancellation, drainage, and retirement guards are preserved.

Direct completion policy checks the admitted canonical target before model/auth preparation and before dispatch, without applying aliases twice. Current provider normalization and isolated-runtime behavior remain supported. Main integration preserves TTS responding-agent routing and the separate provider-stream transport path.

The requested rebase adopts current main’s SQLite launch owner unchanged, including Peter’s upstream fix 8e303782bb5677edbb27c77c222b568fb692dbbf. All incidental SQLite production and test changes have been removed from this PR. The separate updater PR #161916 remains untouched; this PR makes no independent cwd fallback, canonical-auth, update, or storage decision.

Original implementation and contributor credit: @wangmiao0668000666. Reproduction, follow-up repair, and this maintainer-owned replacement were requested by @jalehman. The original human-authored completion patch is replayed with its author preserved; the reviewed maintainer repairs embedded in earlier merge commits are retained in a separate completion-repair commit. The former head remains recoverable.

Work sessions

Evidence

  • Rebased candidate: 51aa2cd2eaf71b8a98bc063f5c57e86e8173e790; tree f49117cab5188d1a4955e922424d7eadc911c8c2, pinned main d4ecb67706fa64d6eb1a8b94196f4526c7ed6e34. All 15 remaining completion source/test blobs are byte-identical to prior head 83e4fc9aab02b6a217cde7762e26c2cb170b581a; all SQLite paths and the archive fixture match pinned main exactly. No merge or auto-merge is requested or enabled.
  • New-base scoped proof: sanitized AWS Crabbox run completed with exit 0 on the exact composed tree above. Eleven focused completion/alias/TTS/worker-transport files passed all 162 cases (128.46s summed shard wall); all selected changed gates, production types, all 27 test-type graphs, formatting, lint (0 warnings/errors), and import-cycle scan (0 cycles) passed. Full pnpm build passed in 9m37s, including runtime and SDK declarations. Bootstrap verified the public/no-IAM boundary (IMDS 404), exact source SHA/tree and pinned toolchain in fresh HOME; no contributor code ran on the host. New-head CI run attached automatically and is in progress; no current-head green CI is claimed. Proof lease cbx_edbc69a60d5f is released; broker readback reports cleanup complete, provisioningResourceMayExist:false, and no owned resources in provider inventory.
  • Prior-head GitHub CI passed on 83e4fc9aab02b6a217cde7762e26c2cb170b581a. It is not new-head CI. The initial updater failure and the former branch’s SQLite experiments are historical evidence only; that authored repair and its regression were dropped in favor of current main. Upstream 8e303782 records its own 492 passing tests and an inherited Windows SIGINT failure; neither that failure nor its proof is relabeled as this PR’s result.
  • Original-head regressions reproduced in secretless AWS Crabbox: alias/normalizer RED and pending-replacement RED. No retirement guard was relaxed.
  • Pre-integration candidate: 634 focused cases passed, plus 55 command cases rerun after fixture consolidation; private-QA build, production types, all 27 test-type graphs, and all 31 changed gates passed. This is candidate proof, not new-head GitHub CI.
  • Prior integration review against pinned main 60b0421: scoped-clean at P0–P2, exit 0. Reused for this patch-identical completion rebase: stable patch ID 036bd4df56dd678c496e6df007d1e3d11536950f, all 15 source/test blobs equal, and base-input review confirms completion owners, generation scope, caller authority, provider transport, and dependency pins unchanged. The current maintainer workflow does not require another review for a patch-identical rebase. Earlier rejected private-helper/shorthand findings were checked against actual callers and admitted selection ordering, not silently counted as clean.
  • Earlier integration proof on main 60b0421: 162 cases across 11 affected-sibling files passed (123.36s summed shard wall), including real TTS responding-agent selection, worker transport construction exactly once, scoped metadata, retirement, alias remapping, and runtime policy. All selected changed gates, production types and all 27 test-type graphs passed on the same tree; formatting/lint reported zero errors and import-cycle scan found zero cycles. The requested post-CI real Gateway reload proof is now attached below. No merge is requested or enabled.
  • Prior-head integration timing: retired-inventory regression 187ms; five alias/admission cases 835ms (summed case time, not standalone file wall). TTS responding-agent sibling: 25.02s file wall; worker transport sibling: 20.85s file wall. Prior command fixture: 55 cases, 36.86s file wall. These exercise real model acquisition, plugin lifecycle, and loopback transport rather than private predicates; import/build overhead is separate. Prior-head CI completed successfully; the isolated Gateway scenario took 37.138s command wall after a 9m8.1s full build.
  • Authored delta against pinned main: 5 production files +295/−320 (net −25); 10 test files +611/−115 (net +496). Zero authored SQLite paths. No generated proof artifacts are committed.

SQLite review reconciliation: the prior review’s four overlapping owner/upgrade items and optional Rank-up move concerned this PR’s now-removed SQLite delta. Current main supplies the canonical behavior unchanged; no third fallback or copy of #161916 is introduced. A new published-updater × candidate cell is not claimed or added solely for removed changes. The remaining plugin contract is new completion admission during an already-running Gateway reload, not installation, stored-state migration, or the installed updater; its unchanged real Gateway proof and new-base focused completion/alias/TTS validation cover that contract.

Prior-head real Gateway reload proof — passed. Built the 83e4fc9aab02b dist-backed Gateway, ran an ordinary agent turn, changed another plugin and called actual plugins.reload, then ran a second turn in the same session. Observed 2 primary + 2 post-turn summary HTTP requests, expected model, unchanged context-engine registration UUID/session ID/Gateway PID, committed generation 3, and restartRequired:false. Both turns have no fallback/reroute; logs contain no context-engine degradation, quarantine, or retired-inventory error. The linked comment includes the public broker artifact manifest, actual commands, replies, logs, reload receipt and cleanup receipt (broker artifact links expire October 7, 2026). Synthetic loopback SSE inference is not live vendor-authentication proof.

Lifecycle clarification: ordinary durable Gateway turns in the prior-head proof use documented commitTurn + maintain, not the earlier plan’s afterTurn compatibility hook. The fixture follows that current contract and calls the host-supplied runtimeContext.llm.complete after each accepted turn. No direct retirement/generation helper or manually invoked host hook substitutes for the real flow. Harness-only corrections are recorded in the evidence; that proof’s product source and green CI head did not change. The subsequent rebase preserves all completion blobs, but this trace remains explicitly prior-head evidence. AWS lease cbx_c359814f0bed is released, cleanup complete, no resources remain; Gateway/provider stopped.

Named proof follow-ups: an 11-process-exit-listener warning appeared during reload, followed by clean shutdown; build’s UI-size diagnostic reported largest JS gzip 217.1 vs 215.0 KiB. The rebased full build also emitted the existing nonfatal UI-size diagnostic (largest JS gzip 216.6 vs 215.0 KiB and startup CSS advisory); no UI files are in this PR. These diagnostics remain visible in the evidence, with attribution uninvestigated. No unrelated source changes were made.

Session: https://team.openclaw.ai/chat/roboclaw/dashboard/bcef8911-1685-40e7-8c68-67e3e928150b

@clawsweeper

clawsweeper Bot commented Sep 30, 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 agents Agent runtime and tooling size: XL labels Sep 30, 2026
@roboclaw-bot
roboclaw-bot marked this pull request as ready for review September 30, 2026 13:55
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 30, 2026
@clawsweeper

clawsweeper Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 30, 2026, 2:26 PM ET / 18:26 UTC (Revision 7).

ClawSweeper review

What this changes

The branch moves new plugin and text-to-speech completion selection into the admitted runtime generation and checks the selected model against policy before provider use.

Merge readiness

✅ Ready for maintainer review

The reported failure remains possible on current main, and the earlier fix PR closed without merging. This branch remains a viable fix candidate. The previous SQLite concern no longer applies to its introduced or test-merge changes.

Priority: P1
Reviewed head: 51aa2cd2eaf71b8a98bc063f5c57e86e8173e790

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Real Gateway proof and focused boundary coverage support a substantial lifecycle repair, with no actionable introduced defect found.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (linked_artifact): The prior-head dist-backed Gateway trace exercises ordinary turns through an actual plugin reload in one session and records successful post-reload provider requests; GitHub tree checks match the central production blobs to this head. The current-head focused validation is supplemental. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (linked_artifact): The prior-head dist-backed Gateway trace exercises ordinary turns through an actual plugin reload in one session and records successful post-reload provider requests; GitHub tree checks match the central production blobs to this head. The current-head focused validation is supplemental. No stored-data contract changes.
Evidence reviewed 10 items Current-main defect path: Current main selects a tentative model and plugin metadata before acquiring the prepared runtime, so a retained callback can carry predecessor facts into a new completion.
Introduced admission change: The branch exits the inherited plugin generation and derives each new selection inside the lease admission callback.
Lease ownership: The lease waits for pending replacement before rebinding to the committed owner and deriving runtime plugin selections.
Findings None None.
Security None None.

How this fits together

The Gateway supplies plugins with model completion capabilities. A completion selects a model from the current plugin runtime, prepares its credentials and transport, then sends a request to the provider.

flowchart LR
  A[Plugin completion request] --> B[Current runtime admission]
  B --> C[Model selection]
  C --> D[Caller and model policy]
  D --> E[Model and credential preparation]
  E --> F[Provider request]
  F --> G[Completion result]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -25, Tests +496. Total +471 across 15 files.

View PR surface stats
Area Files Added Removed Net
Source 5 295 320 -25
Tests 10 611 115 +496
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 15 906 435 +471

Review metrics

None.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #156026
Summary: The open bug is the canonical report; this PR is its current candidate fix, and the earlier contributor PR closed unmerged.

Members:

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

Technical review

Best possible solution:

Use one host-owned admission path for new completions after reload, preserve already prepared work, and enforce current caller and model policy at provider dispatch.

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

Yes. Current main retains the pre-admission selection path, and the linked report records a retained-generation failure and fresh-admission control. I did not execute that reproduction in this read-only review.

Is this the best way to solve the issue?

Yes. Selection now occurs in the lease owner's post-replacement admission, and the admitted target is checked before provider dispatch.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against a83c49bf6374.

Labels

Label changes:

No label changes.

Label justifications:

  • P1: The linked production report describes failed post-reload plugin completions and degraded summarization.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (linked_artifact): The prior-head dist-backed Gateway trace exercises ordinary turns through an actual plugin reload in one session and records successful post-reload provider requests; GitHub tree checks match the central production blobs to this head. The current-head focused validation is supplemental. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The prior-head dist-backed Gateway trace exercises ordinary turns through an actual plugin reload in one session and records successful post-reload provider requests; GitHub tree checks match the central production blobs to this head. The current-head focused validation is supplemental. No stored-data contract changes.

Evidence

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Shakker: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • jalehman: 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 (6 earlier review cycles)
  • reviewed 2026-09-30T14:03:53.610Z sha e97b0b7 :: blocked before merge. :: none
  • reviewed 2026-09-30T14:25:41.218Z sha e97b0b7 :: blocked before merge. :: none
  • reviewed 2026-09-30T15:40:46.261Z sha 83e4fc9 :: blocked before merge. :: none
  • reviewed 2026-09-30T15:46:39.819Z sha 83e4fc9 :: blocked before merge. :: none
  • reviewed 2026-09-30T16:13:57.251Z sha 83e4fc9 :: blocked before merge. :: none
  • reviewed 2026-09-30T16:39:37.519Z sha 83e4fc9 :: blocked before merge. :: none

@clawsweeper clawsweeper Bot added the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Sep 30, 2026
@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

Real Gateway reload proof — passed

Verified on 83e4fc9aab02b6a217cde7762e26c2cb170b581a after exact-head CI succeeded. Public evidence manifest (broker links expire October 7, 2026) contains the sanitized Gateway log, actual commands, both agent replies, provider request counts, reload receipt, harness, SHA/tree, and cleanup receipt. AWS Crabbox run (portal may require login).

  • Built the candidate and launched its real dist-backed Gateway, with three synthetic plugins and loopback OpenAI-compatible SSE inference.
  • Ordinary agent turn → changed another plugin → actual plugins.reload RPC → second ordinary turn in the same session.
  • 2 primary + 2 post-turn summary HTTP requests, all for proof-model; visible replies PRIMARY_OK_1 / PRIMARY_OK_2, summaries SUMMARY_OK_1 / SUMMARY_OK_2.
  • Context-engine registration UUID and session ID stayed identical. Reload committed generation 3, activated target version 2, and returned restartRequired:false. Same Gateway process survived. No model fallback/reroute, context-engine degradation, quarantine, or retired-inventory error.
  • Successful focused command: 37.138s; full build: 9m8.1s. Secretless AWS lease cbx_c359814f0bed released; cleanup complete and no remaining provisioning resource. Gateway/provider stopped cleanly.

Contract clarification: the earlier plan called this afterTurn, but current durable Gateway turns deliberately use commitTurn + maintain. The proof uses that documented post-turn path and the host-supplied runtimeContext.llm.complete, not a manually invoked hook, private helper, or simulated generation retirement. See docs/concepts/context-engine.md:251-289 and src/agents/embedded-agent-runner/run/attempt-finalize.ts:202-247. Earlier attempts corrected fixture escaping, current lifecycle/startup declarations, fixture storage, and bootstrap-maintenance accounting; no product source changed and assertions were not relaxed. Synthetic inference is not live vendor-authentication proof.

This supplies the same-session Gateway trace requested by the two proof items and Rank-up move in the current ClawSweeper review. Named follow-ups retained in the public evidence: reload emitted an 11-exit-listener warning (shutdown still completed); build emitted a largest-JS gzip diagnostic (217.1 vs 215.0 KiB). Attribution is uninvestigated; neither is claimed repaired or caused by this PR. No merge or auto-merge enabled; old PR untouched.

@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. and removed merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Sep 30, 2026
wangmiao0668000666 and others added 2 commits September 30, 2026 17:48
A fresh direct completion running inside a retained context-engine scope inherits
that scope's plugin generation. After a plugin operation publishes a replacement
inventory and retires the predecessor cache, a new completion in the retained
scope selected the retired snapshot and failed in retainPluginCache before
reaching the provider.

Admit the completion against the committed inventory instead: select metadata and
prepare the generation outside the inherited frame, then re-enter the admitted
generation explicitly for model materialization. Caller authority, cancellation,
drainage, and the retirement guards are unchanged.

Because plugin generation replacement can also remap the requested model, the
plugin LLM caller now validates the model it actually admitted against the host
and operator completion policies, and against the override policies when the
caller requested a model, before provider I/O instead of only validating the
target it saw when the request started.

Fixes #156026

Co-authored-by: jalehman <[email protected]>
Replay the reviewed completion repair on main d4ecb67. Preserve the admitted selection/config recipe, selected metadata projection, canonical-target policy, TTS responding-agent routing, and separate provider-stream transport.

Retain the completion bytes from c22802f, 6655e8b, 0d0c5ba, and e97b0b7; all fifteen remaining paths match prior head 83e4fc9 exactly. The original contributor patch is the preceding human-authored commit; its alternate 4915264 form was reconciled in that replay.

Drop the incidental SQLite commit 83e4fc9. Current main already owns unavailable-cwd launch behavior through 8e30378. No SQLite or archive-fixture delta remains.

Original contribution: wangmiao0668000666 (PR #156053).

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

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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.

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

2 participants