Skip to content

refactor(agents): share one Gateway inventory rule between admission and catalog reads - #197276

Merged
obviyus merged 2 commits into
mainfrom
openclaw/catalog-runtime-rows
Nov 11, 2026
Merged

obviyus merged 2 commits into
mainfrom
openclaw/catalog-runtime-rows

Conversation

@obviyus

@obviyus obviyus commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator

Problem

After #197238, two places encoded the same rule, "Gateway inventory belongs to the configured agent; the session cwd only controls execution":

  • Run admission (prepared-model-runtime-lease.ts, from fix: resolve plugin-discovered models outside the agent workspace #169539) built inventoryInput inline from context.getGatewayLifecycleActive().
  • Read-only catalog lookups (prepared-model-catalog.ts) built their own inventory candidate from a separate lifecycle-flag module (prepared-model-runtime-gateway-lifecycle.ts).

Change

  • resolveInventoryInput(input, configuredOwner?) in prepared-model-runtime.owner.ts now owns the rule. Admission and read-only catalog lookups both call it.
  • The Gateway lifecycle flag moves into the same owner module. prepared-model-runtime-gateway-lifecycle.ts is deleted.
  • Production: 24 insertions, 27 deletions (vs 8ae6b38). No behavior change.

Why the shared published-owner resolver does not absorb the rule

I first moved the rule into resolvePublishedOwner, so every published lookup would ignore the session cwd under a Gateway. Two contracts failed, so I reverted that:

  • prepared-model-runtime.inbound-registry.test.ts: "Historical workspaces and changed policy cannot borrow the current publication". Subagent cleanup must not reuse another workspace's inbound plugin registry.
  • prepared-model-runtime.owner-selection.test.ts, "matches the configured owner for workspace": execution owners stay workspace-scoped.

So inventory (catalog rows) and execution (plugin registries) need different owner rules. Only inventory goes through resolveInventoryInput.

Caller map (read-only catalog entry points, non-test)

  • getPreparedModelCatalogOwnerSnapshot: gateway/server-model-catalog, auto-reply/commands-system-prompt, status/status-text, agents/cli-runner/prompt-context
  • getPublishedPreparedModelCatalogOwnerSnapshot: gateway/server-model-catalog, gateway/server-methods/{models, chat-metadata-facts, requester-model-catalog}, agents/{utility-model, model-runtime-choice, model-catalog-view, context}
  • withPreparedModelCatalogOwner: tui/embedded-backend, commands/models/list.list-command, agents/model-runtime-choice (sessions_spawn)
  • loadPreparedModelCatalogSnapshot: tui/embedded-backend, commands/sessions, auto-reply/{model-selection-directive, model-selection}, commands/models/list.status-command, wizard/setup.finalize, agents/model-catalog-view
  • readPreparedModelCatalog: media-understanding/runner, tui/embedded-backend, plugin-sdk/agent-runtime, cli/capability-cli/model, auto-reply/{get-reply-native-slash-fast-path, session-reset-model}, flows/doctor-tool-schema-frames, commands/{doctor-hooks-model, models/list.probe}
  • loadPublishedPreparedModelCatalogOwnerSnapshot: agents/model-runtime-choice, auto-reply/commands-models-catalog
  • loadProviderScopedThinkingCatalog: cron/isolated-agent/model-selection, auto-reply/{agent-runner-utils, agent-runner-run-params, model-runtime-normalization, model-selection}, agents/command/{model-selection, run-embedded-attempt}
  • getPreparedModelCatalogSnapshot: extensions/discord native-command options, status/summary.runtime, system-agent/tui-backend, auto-reply/commands-context-report
  • refreshExpiredPreparedModelCatalog: plugin-sdk/agent-runtime

All of them resolve owners through resolveInputs in prepared-model-catalog.ts.

Removed vs retained

  • Removed: the lifecycle-flag module, the inline admission ternary and the inline catalog ternary. They were duplicate encodings of one rule.
  • Retained: the inventory candidate (now one line, resolveInventoryInput(full)). It is how read-only lookups reach the configured owner, and the shared resolver cannot do that without breaking the execution contracts above. Outside a Gateway lifecycle it equals full, and new Set dedupes it.
  • Retained: activationFull and activationExact. Standalone commands publish one owner keyed by the agent's resolved workspace (activateStandalonePreparedModelRuntime(activationExact)). Later workspace-free reads in the same process (for example status-text) need that key. exact/activationExact also match read-only standalone activations, which are keyed with readOnly: true.
  • Retained: the read-only temporary build (acquireReadOnlyPreparedModelRuntime(activationExact)).
    • It serves standalone CLI reads such as openclaw models list without a Gateway. ClawSweeper's first review of fix(agents): read published catalog for project-session model lookups #197238 noted that the embedded TUI host publishes configured-provenance owners without a Gateway lifecycle; those reads keep workspace-scoped discovery.
    • Under a Gateway it is now reached only when the agent has no configured owner. Configured agents resolve the published owner first, and the regression test confirms this: no extra discovery runs and the discovered rows are present.
    • Deleting the Gateway case would mean adding a new error path for unconfigured agents. That is a behavior change, not a cutover.

Evidence

  • src/agents/prepared-model-catalog.outside-workspace.test.ts: both cases pass. Replacing resolveInventoryInput(full) with full makes the Gateway case fail again.
  • 60 owning test files run locally in 4 batches: prepared-model-runtime*, prepared-model-catalog*, model-runtime-choice*, openclaw-tools.subagents.sessions-spawn*, tui/embedded-backend, and the embedded-runner model tests. 723 of 724 pass. The one failure, prepared-model-runtime.startup-registry.test.ts, needs --expose-gc, which the direct run does not pass. It does not touch this code.
  • Isolated Gateway on this head (scratch state, clean env -i environment, plugins install, stand-in plugin with OAuth and discovery: runtime). A real agent turn in a project session called sessions_spawn:
    • The discovered row and the manifest row were both accepted, and the child sessions replied on those models.
    • It still works after openclaw plugins reload.
    • Discovery ran once, at startup.

obviyus and others added 2 commits November 11, 2026 21:08
…and catalog reads

Run admission (#169539) and read-only catalog lookups (#197238) each encoded
"Gateway inventory belongs to the configured agent; the session cwd only
controls execution". Move that rule, and the Gateway lifecycle flag it reads,
into the owner layer as resolveInventoryInput, and use it from both callers.
Delete the separate lifecycle-flag module.

Execution owners (plugin registries, inbound cleanup) stay workspace-scoped,
so the shared published-owner resolver keeps its exact workspace match.

Co-authored-by: obviyus <[email protected]>
…and catalog reads

OpenClaw-Publication: a75ca303-613b-4901-a870-c4f97925ac16
@clawsweeper

clawsweeper Bot commented Nov 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.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Nov 11, 2026
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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. labels Nov 11, 2026
@clawsweeper

clawsweeper Bot commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR shares the Gateway inventory-selection rule between run admission and catalog reads and moves its lifecycle flag into the existing runtime owner.

Example: A Gateway session runs in /tmp/project-checkout and selects runtime-demo/discovered-row.

  • Before: Admission and catalog reads independently select the configured agent’s inventory while preserving the execution folder.
  • After: Both paths use the same owner-held rule, with the same user-visible result.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A correct, narrowly scoped consolidation with successful exact-head gates; independently inspectable behavioral evidence remains harness-based.
Proof confidence 🦐 gold shrimp (3/6) This collaborator-authored PR is outside the ordinary contributor proof gate; its body reports an isolated Gateway accepting manifest and discovered models through sessions_spawn before and after plugin reload, while inspectable source coverage exercises the real publication and catalog owners with mocked discovery.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Refactor · Worth it: Yes · Fix scope: Complete
User problem: Separate inventory rules could drift and make project-session model checks disagree with turn admission.
Reason: The collaborator-authored direction reduces duplicate policy without changing public contracts, defaults, discovery behavior, or execution isolation.

Merge readiness

✅ Ready for maintainer review

This PR is a focused, behavior-preserving consolidation with no actionable findings; exact-head CI has passed, and collaborator authorship also protects it from cleanup closure.

Priority: P3
Reviewed head: 49209567247cefe352622369f3fc53cfdeb3fd8c

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The reported Gateway project-session spawn and plugin-reload run has no attached terminal trace or artifact independently demonstrating it on this head.
Agent review details

How this fits together

The prepared-model runtime receives agent, config, environment, and workspace inputs and supplies published catalog facts and leased execution generations to model consumers.

flowchart TD
  A[Session inputs] --> B[Run admission]
  A --> C[Catalog reads]
  B --> D[Inventory input owner]
  C --> D
  D --> E[Configured agent inventory]
  B --> F[Workspace scoped execution]
Loading

Technical review

Best possible solution:

Keep the inventory projection in the existing runtime owner while retaining exact workspace matching for execution registries.

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

This PR addresses duplicated policy rather than a new functional defect; source comparison confirms both existing paths express the same Gateway inventory rule.

Is this the best way to solve the issue?

The extraction is the smallest complete consolidation: it uses the existing owner, removes the former flag module, and leaves execution-owner matching unchanged.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Admission inventory projection keeps the original intent (52885d9: Gateway inventory follows the configured agent while the session retains its execution cwd.)
  • Catalog inventory projection and lifecycle flag keeps the original intent (8ae6b38: Project-session passive reads reuse published Gateway inventory while standalone discovery remains workspace-scoped.)
  • Published-owner and execution selection keeps the original intent (06f5f73: Lifecycle-owned generations provide coherent model and auth facts without repeated request-time discovery.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source -3. Total -3 across 5 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 5 24 27 -3
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 24 27 -3

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add P3: This is a small internal refactor preserving established behavior, without a new user-facing failure or urgent regression.
  • 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:

  • P3: This is a small internal refactor preserving established behavior, without a new user-facing failure or urgent regression.
  • 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.

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.

Reviewed November 11, 2026, 11:05 AM ET / 16:05 UTC.

@obviyus
obviyus merged commit 6c5b239 into main Nov 11, 2026
133 checks passed
@obviyus
obviyus deleted the openclaw/catalog-runtime-rows branch November 11, 2026 16:08
@obviyus

obviyus commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 12, 2026
…and catalog reads (openclaw#197276)

* refactor(agents): share one Gateway inventory rule between admission and catalog reads

Run admission (openclaw#169539) and read-only catalog lookups (openclaw#197238) each encoded
"Gateway inventory belongs to the configured agent; the session cwd only
controls execution". Move that rule, and the Gateway lifecycle flag it reads,
into the owner layer as resolveInventoryInput, and use it from both callers.
Delete the separate lifecycle-flag module.

Execution owners (plugin registries, inbound cleanup) stay workspace-scoped,
so the shared published-owner resolver keeps its exact workspace match.

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

* refactor(agents): share one Gateway inventory rule between admission and catalog reads

OpenClaw-Publication: a75ca303-613b-4901-a870-c4f97925ac16

---------

Co-authored-by: obviyus <[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 P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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