Skip to content

fix(models): keep each prepared runtime's authored config source - #189192

Merged
obviyus merged 4 commits into
mainfrom
fix/runtime-owner-pins-config-source
Oct 31, 2026
Merged

obviyus merged 4 commits into
mainfrom
fix/runtime-owner-pins-config-source

Conversation

@obviyus

@obviyus obviyus commented Oct 31, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

After saving a provider key in the Control UI (models.authSetApiKey), a live Gateway logged [plugins] typesafe invalid config: apiKey: must be object once per prepared model runtime rebuild. The TypeSafe plugin's apiKey is a SecretRef object, and its manifest declares it as a secret input, so validation must compare against the authored source, not the resolved string.

Call chain:

  1. The auth mutation rebuilds existing prepared-runtime owners (prepared-model-runtime-auth-publication.ts → publishPreparedModelRuntimeOwnerBatch).
  2. Each owner rebuilds from the config it was admitted with, an older runtime generation (prepared-model-runtime.build.ts).
  3. projectConfigOntoRuntimeSourceSnapshot maps that old config onto the current source snapshot. The config write added a top-level meta key that the old config lacks, so the projection returns the resolved config as its own source.
  4. loadAgentRuntimePluginRegistryHandle passes that as activationSourceConfig, and plugin config validation sees the resolved string.

Fix

The runtime snapshot publisher (publishRuntimeConfigSnapshot) now records the authored source it publishes with each runtime config object, in a separate map next to the existing captures (recordPublishedRuntimeConfigSource). Every publication overwrites it (with the runtime itself when no source is published), so a source republished for the same runtime object (setRuntimeConfigSourceSnapshotIfCurrent) stays authoritative. projectConfigOntoRuntimeSourceSnapshot uses that record for configs that are not frozen captures, so an older runtime generation projects its own source instead of failing open against a newer one. The record is not a capture: the config keeps its identity, and captureRuntimeConfig still freezes an isolated runtime/source pair for rebuilds.

User impact

Saving a provider key no longer produces false invalid-config errors for plugins with secret inputs, and those plugins validate against their real authored config during rebuilds.

Proof

  • src/config/runtime-source-projection.test.ts:
    • "keeps an older runtime generation on its own published source": a held generation still projects its SecretRef after a newer generation adds meta, and captureRuntimeConfig still returns a frozen copy. Fails on main (projects the resolved string).
    • "follows a newer source republished for the same runtime object": republishing the same runtime object with a new source wins, also after the next generation. Fails on the previous head of this PR.
  • An isolated Gateway reproduction (TypeSafe with an env SecretRef, bundled plugins on, then models.authSetApiKey for particle) logged typesafe invalid config before the fix and zero after, with models.list succeeding. The scratch harness is not committed: it needs a 15 s wait.
  • Projection, runtime snapshot, owner, inbound-registry, sources and loader-shared suites pass. pnpm check:changed passes. pnpm check:madge-import-cycles reports 0 cycles.

Known remaining: plugins/loader-load-context.ts (context-engine owner capture) and decisions/registry-adoption.ts use the same projection on held configs. They produced no warnings in the reproduction after this fix.

No overlap with Pash/Sarah changes.

Merge danger

Two-way door: a revert fully undoes it. No state, config or contract change. Blast radius: prepared model runtime rebuilds after config writes.

@clawsweeper

clawsweeper Bot commented Oct 31, 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: S labels Oct 31, 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. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. 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. labels Oct 31, 2026
@clawsweeper

clawsweeper Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR retains each published runtime config object's authored source for later model-runtime rebuilds.

Example: Save a provider key while an older prepared runtime holds a plugin SecretRef named PLUGIN_KEY.

  • Before: A newer config adds meta, and rebuilding the older runtime validates resolved-key instead of its authored SecretRef.
  • After: The older runtime retrieves its own published SecretRef, while subsequent captures remain isolated and frozen.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused implementation resolves the prior defects, with confidence limited by reported-only runtime evidence and unresolved CI attribution.
Proof confidence 🦐 gold shrimp (3/6) This collaborator-authored PR is outside the ordinary contributor proof gate; its body reports an isolated Gateway using TypeSafe with an env SecretRef, models.authSetApiKey, disappearance of validation warnings, and successful models.list, without attached runtime output.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Saving a provider key can produce false invalid-config errors for plugins whose secret inputs are authored as SecretRefs.
Reason: The collaborator-authored direction restores a documented validation contract without introducing settings or changing public APIs.

Merge readiness

✅ Ready for maintainer review

This PR repairs a current source-generation mismatch and addresses all prior findings; no remaining introduced defect was found, but required CI still fails.

Priority: P2
Reviewed head: 03be19396147aead334fcd7d3b7dcfb451659510

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The reported Gateway before/after result has no attached runtime trace or artifact to inspect.
Agent review details

How this fits together

The config publisher pairs resolved runtime values with authored configuration, which model preparation captures and supplies to plugin validation.

flowchart LR
  A[Authored config] --> C[Runtime publisher]
  B[Resolved config] --> C
  C --> D[Published source association]
  D --> E[Immutable runtime capture]
  E --> F[Prepared model runtime]
  F --> G[Plugin validation]
Loading

Technical review

Best possible solution:

Keep source associations with the existing publisher and preserve immutable captures, including authoritative source replacement and removal.

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

Current-main source exposes the older-generation fallback directly, and the PR reports an isolated Gateway reproduction; this review executed no target code.

Is this the best way to solve the issue?

The publisher-owned association is a small, complete repair that preserves existing capture isolation and avoids caller-specific workarounds.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Runtime/source pairing and immutable captures keeps the original intent (75d29a7: Capture one isolated runtime/authored pair per preparation generation so later publications cannot mix their values.)
  • Asynchronous captured reads keeps the original intent (aa6d12c: Retain selected runtime, authored source, and environment together before asynchronous callers resume.)
  • Same-object source replacement keeps the original intent (cedc5ae: Meaningful authored policy changes must reach fresh consumers even when resolved runtime values remain unchanged.)
  • Publication-time capture keeps the original intent (f4e0d47: Reuse an isolated capture per publication while preserving mutable live config and the SDK's opaque-value path.)

Testing

Proof path: unit tests only.

Security

None.

Evidence

What I checked:

PR surface

Source +27, Tests +38. Total +65 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 3 27 0 +27
Tests 1 38 0 +38
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 65 0 +65

Review metrics

Metric Value Why it matters
Production versus regression coverage Production +27/-0; tests +38/-0 The publication association must remain separate from frozen captures; the tests cover retained generations and replacement/removal of an authored source.

Labels

Label changes:

  • 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.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.
  • remove merge-risk: 🚨 auth-provider: Current PR review selected no merge-risk labels.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: The bug affects plugin SecretRef validation during auth-triggered model-runtime rebuilds under a specific configuration-generation mismatch.
  • 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.

  • Have the CI owner attribute the failing native-command shard before landing.

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 (3 earlier review cycles)
  • reviewed 2026-10-31T07:51:50.084Z sha fcfde8e :: needs changes before merge. :: [P2] Preserve immutable capture semantics when pinning an original config
  • reviewed 2026-10-31T08:38:17.786Z sha 8a6e99e :: needs changes before merge. :: [P2] Keep source republication authoritative over an older pin
  • reviewed 2026-10-31T09:46:26.177Z sha 5a2794b :: needs changes before merge. :: [P2] Replace the retained source on source-free republication

Reviewed October 31, 2026, 6:44 AM ET / 10:44 UTC (Revision 4).

@obviyus
obviyus force-pushed the fix/runtime-owner-pins-config-source branch from fcfde8e to 8a6e99e Compare October 31, 2026 08:06
@obviyus

obviyus commented Oct 31, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 31, 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. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. 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 31, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the agents Agent runtime and tooling label Oct 31, 2026
@obviyus

obviyus commented Oct 31, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 31, 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 31, 2026
@obviyus

obviyus commented Oct 31, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 31, 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: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. 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. labels Oct 31, 2026
@obviyus

obviyus commented Oct 31, 2026

Copy link
Copy Markdown
Collaborator Author

Maintainer override: the only failing required job on head 03be193 is checks-node-changed-compact-small-22, failing in src/auto-reply/reply/commands-plugin.channel-native.test.ts (expected [ Array(1) ] to deeply equal [ 'queued' ]). Earlier heads of this PR also failed src/gateway/x-publication-owner-composition.e2e.test.ts (Gateway SDK resource host is not bound).

Both fail identically on unmodified main: a clean checkout of origin/main at ad59635 reproduces 7 failures in commands-plugin.channel-native.test.ts and the x-publication-owner-composition.e2e.test.ts failure, with none of this PR's files. main CI does not select them; they run here only because changed-scope selection includes their import graph. This PR changes only src/config/runtime-config-capture-state.ts, runtime-snapshot.ts, runtime-source-projection.ts and its test.

@obviyus
obviyus merged commit 8ca9161 into main Oct 31, 2026
156 of 159 checks passed
@obviyus
obviyus deleted the fix/runtime-owner-pins-config-source branch October 31, 2026 10:46
@obviyus

obviyus commented Oct 31, 2026

Copy link
Copy Markdown
Collaborator Author

Landed as 8ca9161 under the maintainer override above. The snapshot publisher now records the authored source it publishes with each runtime config, so an older runtime generation validates plugin secret inputs against its own SecretRef instead of the resolved value. This removes the false invalid config: apiKey: must be object errors after saving a provider key. Thanks ClawSweeper for the three source-lifecycle catches.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 1, 2026
…nclaw#189192)

## Problem

After saving a provider key in the Control UI (`models.authSetApiKey`), a live Gateway logged `[plugins] typesafe invalid config: apiKey: must be object` once per prepared model runtime rebuild. The TypeSafe plugin's `apiKey` is a SecretRef object, and its manifest declares it as a secret input, so validation must compare against the authored source, not the resolved string.

Call chain:

1. The auth mutation rebuilds existing prepared-runtime owners (`prepared-model-runtime-auth-publication.ts` → `publishPreparedModelRuntimeOwnerBatch`).
2. Each owner rebuilds from the config it was admitted with, an older runtime generation (`prepared-model-runtime.build.ts`).
3. `projectConfigOntoRuntimeSourceSnapshot` maps that old config onto the current source snapshot. The config write added a top-level `meta` key that the old config lacks, so the projection returns the resolved config as its own source.
4. `loadAgentRuntimePluginRegistryHandle` passes that as `activationSourceConfig`, and plugin config validation sees the resolved string.

## Fix

The runtime snapshot publisher (`publishRuntimeConfigSnapshot`) now records the authored source it publishes with each runtime config object, in a separate map next to the existing captures (`recordPublishedRuntimeConfigSource`). Every publication overwrites it (with the runtime itself when no source is published), so a source republished for the same runtime object (`setRuntimeConfigSourceSnapshotIfCurrent`) stays authoritative. `projectConfigOntoRuntimeSourceSnapshot` uses that record for configs that are not frozen captures, so an older runtime generation projects its own source instead of failing open against a newer one. The record is not a capture: the config keeps its identity, and `captureRuntimeConfig` still freezes an isolated runtime/source pair for rebuilds.

## User impact

Saving a provider key no longer produces false invalid-config errors for plugins with secret inputs, and those plugins validate against their real authored config during rebuilds.

## Proof

- `src/config/runtime-source-projection.test.ts`:
  - "keeps an older runtime generation on its own published source": a held generation still projects its SecretRef after a newer generation adds `meta`, and `captureRuntimeConfig` still returns a frozen copy. Fails on `main` (projects the resolved string).
  - "follows a newer source republished for the same runtime object": republishing the same runtime object with a new source wins, also after the next generation. Fails on the previous head of this PR.
- An isolated Gateway reproduction (TypeSafe with an env SecretRef, bundled plugins on, then `models.authSetApiKey` for `particle`) logged `typesafe invalid config` before the fix and zero after, with `models.list` succeeding. The scratch harness is not committed: it needs a 15 s wait.
- Projection, runtime snapshot, owner, inbound-registry, sources and loader-shared suites pass. `pnpm check:changed` passes. `pnpm check:madge-import-cycles` reports 0 cycles.

Known remaining: `plugins/loader-load-context.ts` (context-engine owner capture) and `decisions/registry-adoption.ts` use the same projection on held configs. They produced no warnings in the reproduction after this fix.

No overlap with Pash/Sarah changes.

## Merge danger

Two-way door: a revert fully undoes it. No state, config or contract change. Blast radius: prepared model runtime rebuilds after config writes.

Co-authored-by: Ayaan Zaidi <[email protected]>
RomneyDa added a commit that referenced this pull request Nov 17, 2026
…9192)

## Problem

After saving a provider key in the Control UI (`models.authSetApiKey`), a live Gateway logged `[plugins] typesafe invalid config: apiKey: must be object` once per prepared model runtime rebuild. The TypeSafe plugin's `apiKey` is a SecretRef object, and its manifest declares it as a secret input, so validation must compare against the authored source, not the resolved string.

Call chain:

1. The auth mutation rebuilds existing prepared-runtime owners (`prepared-model-runtime-auth-publication.ts` → `publishPreparedModelRuntimeOwnerBatch`).
2. Each owner rebuilds from the config it was admitted with, an older runtime generation (`prepared-model-runtime.build.ts`).
3. `projectConfigOntoRuntimeSourceSnapshot` maps that old config onto the current source snapshot. The config write added a top-level `meta` key that the old config lacks, so the projection returns the resolved config as its own source.
4. `loadAgentRuntimePluginRegistryHandle` passes that as `activationSourceConfig`, and plugin config validation sees the resolved string.

## Fix

The runtime snapshot publisher (`publishRuntimeConfigSnapshot`) now records the authored source it publishes with each runtime config object, in a separate map next to the existing captures (`recordPublishedRuntimeConfigSource`). Every publication overwrites it (with the runtime itself when no source is published), so a source republished for the same runtime object (`setRuntimeConfigSourceSnapshotIfCurrent`) stays authoritative. `projectConfigOntoRuntimeSourceSnapshot` uses that record for configs that are not frozen captures, so an older runtime generation projects its own source instead of failing open against a newer one. The record is not a capture: the config keeps its identity, and `captureRuntimeConfig` still freezes an isolated runtime/source pair for rebuilds.

## User impact

Saving a provider key no longer produces false invalid-config errors for plugins with secret inputs, and those plugins validate against their real authored config during rebuilds.

## Proof

- `src/config/runtime-source-projection.test.ts`:
  - "keeps an older runtime generation on its own published source": a held generation still projects its SecretRef after a newer generation adds `meta`, and `captureRuntimeConfig` still returns a frozen copy. Fails on `main` (projects the resolved string).
  - "follows a newer source republished for the same runtime object": republishing the same runtime object with a new source wins, also after the next generation. Fails on the previous head of this PR.
- An isolated Gateway reproduction (TypeSafe with an env SecretRef, bundled plugins on, then `models.authSetApiKey` for `particle`) logged `typesafe invalid config` before the fix and zero after, with `models.list` succeeding. The scratch harness is not committed: it needs a 15 s wait.
- Projection, runtime snapshot, owner, inbound-registry, sources and loader-shared suites pass. `pnpm check:changed` passes. `pnpm check:madge-import-cycles` reports 0 cycles.

Known remaining: `plugins/loader-load-context.ts` (context-engine owner capture) and `decisions/registry-adoption.ts` use the same projection on held configs. They produced no warnings in the reproduction after this fix.

No overlap with Pash/Sarah changes.

## Merge danger

Two-way door: a revert fully undoes it. No state, config or contract change. Blast radius: prepared model runtime rebuilds after config writes.

Co-authored-by: Ayaan Zaidi <[email protected]>

Release adaptation: clean -x backport onto 82f1197; production and regression hunks unchanged. Add a separate 38-line test-budget allocation for the two upstream regression tests; shared scalar unchanged. Preserve baseline e13cf15 and audit pin bd692e9.

Companion dispositions at pinned audit:
- #193903 / b43ad0a: not-applicable; independent catalog/capture-memo optimization, no prerequisite for the source association.
- #196984 / b8980ca: present-equivalent; current reader already follows equivalent runtime copies.
- #199956 / ea69fcb: not-applicable; independent live-reader ownership retention; authored-source association unchanged.
- No later #189192 mention. Existing publication, capture, runtime-plugin, loader and decision consumers retain their interfaces; no generated/registry companion needed. Workflow optimizations excluded from this product-only scope.

Release proof: unmocked production publication/projection regression boundary fails on parent (2 failed, 4 passed) and passes after pick; projection plus snapshot suites 50 passed; retained-runtime plugin consumer suites 18 passed. Targeted type-aware lint (4 files), format and diff checks pass. Upstream live Gateway proof above is historical; this lane does not claim a fresh live Gateway/model run or full release qualification.

Self-review/pr-simplify: retain the minimal separate weak association because raw publication identity and frozen captures have distinct lifetimes. Delta: 27 production and 38 regression lines, plus the 3-line budget record.

(cherry picked from commit 8ca9161)

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit 7ddb9e2a14671b47081bec40224e1f6f7316690d)
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. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S 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