Skip to content

fix(models): preserve first chats during catalog updates - #167492

Merged
steipete merged 2 commits into
mainfrom
ci/fix1-prepared-first-turn
Oct 9, 2026
Merged

steipete merged 2 commits into
mainfrom
ci/fix1-prepared-first-turn

Conversation

@steipete

@steipete steipete commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes first chats and Telegram introductions being refused before inference when a Gateway adopts a hosted model catalog newer than its installed build.

User Impact

A turn that has admitted a model generation retains it through preparation and inference; later turns use the replacement generation. Native observations from an admitted turn cannot overwrite the newer publication. Closed leases, run revocation, cancellation, shutdown, and stale unborrowed readers remain fenced.

Why This Change Was Made

This revision removes all three new production modules from the earlier patch. Retention stays in the existing published owner, borrowing/close handling is shared by the existing generation-scope owner, and native observation stays in catalog access. Existing inventory selection moved into the existing catalog-source owner to satisfy the unchanged 700-line limit. The separate test-support module is also removed.

Comparison against the same current base (674275e3808e):

Measure Previous implementation Reduced implementation
Changed files 24 25
Production files 15 13
Production added/deleted lines +354 / −107 +334 / −148
Net production growth +247 +186
New production modules 3 0
New test modules 1 0

The reduction removes 61 lines of production growth. The reduced implementation had 24 changed files; the typed-error follow-up adds one assertion in an existing registry-borrow test, bringing it to 25. Two existing tests now live in their existing entrypoint files: the line-growth guard rejected adding their lease expectations to already oversized helpers. Their bodies are byte-identical and use the same reset hook. The original published head on its older base measured +354/−106 production lines.

The remaining pieces protect these contracts:

Contract / retained piece Regression that requires it
Retain the published generation before preparation crosses an await; capture its catalog facts delivers the first reply when catalog adoption retires its captured dispatch publication
Close borrowing before asynchronous disposal; carry the initial lease through direct and deferred Gateway admission retains runtime custody and emits session creation with %s preparation (both cases)
Carry canonical admitted config through Cron, preserving agent overrides and releasing preparation ownership carries the admitted config into execution while preserving agent overrides; admits the published generation and keeps it active through embedded execution; releases the prepared lease when continuation initialization fails
Allow native observations under the exact live lease, including prompt-project projections, without publishing over a replacement keeps native selection bound to its admitted lease (before/during retirement, closed lease, revoked run, shutdown); stale unborrowed and replacement-publication assertions remain
Keep readiness reentrancy and retained native inventory identity checks rejects native readiness that retires its owner; renews native observations without retaining harness-only host projections
Recognize an accepted catalog replacement as progress in existing admission does not reuse a dynamic build captured before a remote publication

Historical comparison isolates the live-adoption trigger in #158000: parent f3f02417f117 passes the unchanged Telegram case and defers the downloaded catalog until restart; child 504d2905d69c applies the same eligible catalog and refuses the introduction. The earlier unleased handoff predates that trigger.

Evidence

  • Qualified unchanged-main reproduction retained: 5/10 failed with an installed build older than the hosted catalog; a fresh build passed 10/10 because it ignored the older catalog. Historical parent/child cells used identical catalog bytes.
  • Reduced implementation: 362/362 focused owner/sibling tests across 14 files, plus 407/407 across all three shared Gateway-fixture importers. The two dispatch entrypoints passed 213/213 after the test moves.
  • Reduced implementation: three consecutive original E2E pair replays passed (30/30), with the installed-build timestamp older than the hosted catalog. All 20 pressured runs passed (140 selected cases; 24 background CPU workers). The final production/UI build passed in 322 seconds.
  • The complete check-changed plan passed across the initial run and its continuation: production types, all 27 test-type graphs, formatting, guards, Knip with zero unused exports, lint, and boundary lint. The initial line-growth and duplicate-import failures were corrected; successful type/deadcode checks were reused. The final import-only cleanup preserves module evaluation order and passed all 75 lifecycle cases.
  • Whole architecture and source-contracts passed on the reduced production code. The later test moves add no runtime edges; their assertions and fixture setup are unchanged.
  • Direct-API P2 review: reduced production scoped-clean (0.82); final candidate including test placement scoped-clean (0.86).

No new modules, retries, longer timeouts, weaker assertions, suppressions, dependency changes, or CI jobs were added. The mock-export baseline shrinks by two obsolete exceptions. The moved-test replay took 36.58 seconds through the repository wrapper (34.98 seconds Vitest); test count and file selection are unchanged. Linux proof uses Testbox, with the unfinished pressure/build work continued on the authorized AWS fallback. Completed runs were preserved. The existing qualified baseline and historical evidence were reused; changed implementation inputs received fresh proof.

Typed supersession follow-up

The stale explicit-generation guard now preserves PreparedModelRuntimePublicationSupersededError, including admissionBlocked: false, when cancelled initial registry inspection settles. The catalog-progress tuple allowed cancelled construction to reach this guard, where the broader owner-not-published superclass had replaced the expected subclass. The production correction changes one constructor; the existing test retains every assertion and additionally checks the admission flag. Admission, replay, custody, cancellation, and disposal behavior are unchanged.

The registry-borrow file failed 1/4 before and passes 4/4 after, including its Linux execution in the whole infra config. The original quota-reset and Telegram-introduction E2E pair passes 10/10 with the build timestamp older than the hosted catalog. The three other CI-selected E2E invocations also pass.

The requested broad proof is complete:

Whole config Passed Skipped Failures
infra (all 1,905 files, eight native shards) 27,046 85 One base-proven fixture lock race
agents-core 6,901 18 One base-proven fractional timer assertion
unit-fast 15,788 16 None
unit-fast-isolated 1,541 0 None

All 24 additional CI-selected rows were replayed (72 plans): all 66 Node invocations passed. Six Bun selections passed; one failed from the base-proven heartbeat issue below. All 35 unique check-changed steps passed across the original invocation and continuation, including production types, all 27 selected test-type graphs, lint, boundary lint, formatting, and deadcode. Direct-API P2 review of the exact follow-up is scoped-clean (0.96). Prior architecture, source-contract, build, pressure, and reduction evidence remains valid for unchanged inputs.

Three unrelated failures were reproduced on clean base 674275e3808e, without weakening assertions or changing unrelated source:

  • src/agents/compaction-planning-worker.test.ts:458: base 29 passed / 1 failed; the elapsed timeout is fractional (2146999999.995321) while the assertion requires integer 2147000000. Command: node scripts/run-vitest.mjs src/agents/compaction-planning-worker.test.ts.
  • src/gateway/server-methods/chat-send-global-identity.test.ts, Bun 1.4.2: candidate 14 passed / 9 failed; clean base 11 passed / 12 failed, with the same state-ownership refusal and heartbeat expiry. process.hrtime.bigint() has different parent/Worker origins in Bun, so a new heartbeat Worker in an older process appears stale. The heartbeat producer is 99fccf43358c (fix: preserve Gateway ownership with separate Docker CLI containers #164236). The corresponding Linux Node clock probe is coherent. This separate supported-Bun production defect needs a follow-up.
  • src/hooks/bundled/session-memory/capture.test.ts: clean base reproduces the exact oversized-conversation case in its first normal run (41.96s, no pressure). Its raw corruption UPDATE at line 53 races the reconcile owner's later orphan-sweep write after projection readiness; the fixture producer is d94fe35027e7 (refactor(sessions): move transcript reads to retained history owner #166293).

No follow-up test or source edit occurred after the successful review. Auto-merge remains coordinator-armed; this update does not request a manual merge or CI rerun.

@clawsweeper

clawsweeper Bot commented Oct 8, 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 agents Agent runtime and tooling size: XL labels Oct 8, 2026
@clawsweeper

clawsweeper Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

The branch retains admitted model generations through chat, scheduled-task, and Gateway preparation while isolating older native observations from newer catalog publications.

Example: A user sends hello while catalog 300 replaces catalog 200

  • Before: The reply can fail before inference with “prepared model runtime plugin generation was superseded.”
  • After: The admitted reply keeps remote-200 and delivers “first reply completed” while later turns use catalog 300.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A worthwhile owner-level repair with reported real Gateway before/after coverage and no actionable introduced findings.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The fully read body reports successful after-fix Linux Gateway replays under the relevant older-build/newer-hosted-catalog condition, including the original E2E pair after the final error-type correction. Inspected regressions additionally cover native retirement, closed leases, revoked runs, shutdown, and replacement isolation. Execution results are contributor-reported; no stored-data contract changes were found.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A first conversation can fail before the model receives its message when the Gateway adopts a newer hosted catalog.
Reason: Keeping admitted turns on their captured generation is an established product contract. The repair stays within existing owners and adds no settings or public capability.

Merge readiness

✅ Ready for maintainer review

This PR remains necessary: current main still exposes the preparation race, and the related open repair does not supersede its broader coverage. No actionable introduced defect was found.

Priority: P1
Reviewed head: 1279eb4782def2a910535b6e4d92a2db21fde345

Before merge

None.

Findings

None.

Agent review details

How this fits together

The Gateway publishes model choices, credentials, and plugin registrations for conversations and scheduled tasks. A retained runtime lease keeps those admitted facts available until preparation and execution finish.

flowchart TD
  A[Chat or scheduled task] --> B[Published model generation]
  B --> C[Retain admitted generation]
  D[Hosted catalog update] --> B
  C --> E[Prepare selected model]
  E --> F{Lease and run remain active}
  F -->|Yes| G[Execute with admitted facts]
  F -->|No| H[Reject and release resources]
  G --> H
Loading

Technical review

Best possible solution:

Keep preparation custody in the existing publication and scope owners while preserving independent run authorization and isolation from replacement publications.

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

Yes: capture dispatch on catalog 200, publish catalog 300, then acquire the selected-runtime lease using the captured generation. Current-main source establishes the rejection window, and the body reports matching failing Gateway runs; this review did not execute it.

Is this the best way to solve the issue?

Yes: synchronous retention repairs the ownership gap without rebinding admitted turns, adding retries, or weakening exact-snapshot borrowing.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Current-main necessity: Fetched main still returns the dispatch publication without retaining its generation. Its later run-lease acquisition therefore remains exposed to catalog replacement during preparation. (src/agents/prepared-reply-dispatch-runtime.ts:163, 62355575c041)
  • Atomic retention and cleanup: The publication owner retains the matching configured snapshot before returning it, captures its catalog, and releases the lease if the receiving callback fails. The scope owner disables borrowing synchronously before asynchronous disposal. (src/agents/prepared-reply-dispatch-runtime.ts:184, 1279eb4782de)
  • Native observation boundaries: Retired-owner native discovery requires the exact live borrowed snapshot and process lifetime, returns observations before shared publication, and is followed by run-authority checks in model setup. Regression cases cover publication before and during discovery, closed leases, revoked runs, and shutdown. (src/agents/prepared-model-runtime.catalog-access.ts:454, 1279eb4782de)
  • Exact follow-up: Compared with the previously reviewed head, the final commit changes only the stale-generation error constructor to PreparedModelRuntimePublicationSupersededError and adds an admissionBlocked:false assertion to the existing regression. (src/agents/prepared-model-runtime-lease.ts:266, 1279eb4782de)
  • Reported shipped-entrypoint proof: The fully supplied body, captured as sourceRevision 0dfa6b9c99cb80877c645fe323add3f1a1c6398ee8d8be0e2b991a627f9c2549, reports qualified main failures with an older installed build and newer hosted catalog, 30/30 reduced-implementation E2E replays, and 10/10 original quota-reset/Telegram-introduction replays after the final typed-error correction. The inspected Telegram scenario starts an isolated Gateway and checks provider traffic and native delivery. These are contributor-reported executions; this review ran no target code. (test/e2e/qa-lab/runtime/telegram-join-intro-gateway.e2e.test.ts:114, 1279eb4782de)
  • Established generation contract: Merged fix(models): apply downloaded catalogs without a Gateway restart #158000 requires admitted turns to retain their catalog rows and prices while subsequent turns use the replacement; this repair preserves live adoption and extends custody to preparation. Public docs: docs/concepts/models.md. (docs/concepts/models.md:470, 504d2905d69c)

Likely related people:

  • Peter Steinberger: Raw commit 11d36eb adds src/agents/prepared-model-runtime.catalog-access.ts:308 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 11d36ebc2583; files: src/agents/prepared-model-runtime.catalog-access.ts)
  • Vincent Koc: Raw commit 47e06b8 adds src/gateway/agent-turn/agent-run-admission-phase.ts:377 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 47e06b824924; files: src/gateway/agent-turn/agent-run-admission-phase.ts)

PR surface

Source +186, Tests +439, Docs +4, Other -2. Total +627 across 25 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 13 334 148 +186
Tests 10 678 239 +439
Docs 1 6 2 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 1 0 2 -2
Total 25 1018 391 +627

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #167573
Summary: This PR addresses the reported dispatch-to-lease race across additional preparation paths; another open candidate overlaps the reply-dispatch portion.

Members:

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

Labels

Label changes:

No label changes.

Label justifications:

  • P1: Normal hosted catalog adoption can refuse initial conversation turns before inference, supported by source and reported Gateway failures.
  • 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.
  • 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 need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-08T22:29:08.118Z sha e7019bfcbd6f9508eaf0368069064b43d8511800 :: needs changes before merge. :: none
  • reviewed 2026-10-09T00:40:54.887Z sha 9940f0f :: needs maintainer review before merge. :: none

Reviewed October 9, 2026, 12:27 AM ET / 04:27 UTC (Revision 3).

Retain admitted generations across reply, cron, and Gateway preparation.
Let selected native observations finish under their live turn lease without
publishing over a replacement catalog, while preserving revocation fences.

Keep the repair in existing runtime owners and preserve the first-turn,
canonical-config, cleanup, and native-observation regressions.

Refs #167492.
@steipete
steipete force-pushed the ci/fix1-prepared-first-turn branch from e7019bf to 9940f0f Compare October 9, 2026 00:31
@clawsweeper clawsweeper Bot added 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. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 9, 2026
@steipete
steipete enabled auto-merge (squash) October 9, 2026 00:42
@steipete
steipete merged commit ec7c8bb into main Oct 9, 2026
130 checks passed
@steipete
steipete deleted the ci/fix1-prepared-first-turn branch October 9, 2026 04:30
RomneyDa pushed a commit that referenced this pull request Oct 9, 2026
Retain the published dispatch generation before asynchronous reply, cron,
and Gateway workspace preparation. Allow selected native discovery to finish
under the live run lease without publishing over a replacement catalog;
preserve closed-lease, revocation, and shutdown fences.

Selected release adaptation of #167492. Preserve the release's configured
provider eligibility, admission API, and existing session preparation owner.
Carry the coherent catalog-source extraction and test-owner relocations.

(cherry picked from commit ec7c8bb)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 10, 2026
…7492)

* fix(models): preserve first turns during catalog updates

Retain admitted generations across reply, cron, and Gateway preparation.
Let selected native observations finish under their live turn lease without
publishing over a replacement catalog, while preserving revocation fences.

Keep the repair in existing runtime owners and preserve the first-turn,
canonical-config, cleanup, and native-observation regressions.

Refs openclaw#167492.

* fix(models): preserve typed runtime supersession errors
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 gateway Gateway runtime 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.

1 participant