Skip to content

fix(cli): honor --agent for image description - #145171

Closed
RileyJJY wants to merge 1 commit into
openclaw:mainfrom
RileyJJY:sunlit/fix/issue-145119
Closed

RileyJJY wants to merge 1 commit into
openclaw:mainfrom
RileyJJY:sunlit/fix/issue-145119

Conversation

@RileyJJY

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where users running openclaw infer image describe or image describe-many with multiple configured agents would still receive AgentSelectionRequiredError even when they passed a valid --agent.

Closes #145119

Why This Change Was Made

Forward the resolved agent identity into both the configured-provider and explicit-model image description paths. The media runtime already uses that identity for ownership resolution, so the change preserves the existing agent-selection contract without changing provider routing.

User Impact

Explicit-agent image descriptions now reach the selected agent's saved provider configuration in multi-agent fleets.

Evidence

  • pnpm vitest run src/cli/capability-cli.test.ts — 249 tests passed.
  • Real production CLI proof used the same image, command, and loopback OpenAI-compatible provider on the pinned base and exact head:
$ pnpm openclaw infer image describe --agent beta --file apps/macos/Packaging/dmg-background-small.png --json
entrypoint: src/cli/capability-cli/image.ts:runImageDescribe
dependency-boundary: localhost OpenAI-compatible fixture
base b3ffe8760d734cf98a1567a323cfe2e02842ee0b: exit 1, AgentSelectionRequiredError before provider dispatch
head 8e2c249023aea0797f42f242aced22216df43a3d: exit 0, provider=proof model=vision text=loopback image accepted
negative-control: --agent missing => exit 1, Unknown agent id; provider not called
Proof fixture (Testing): loopback provider boundary
import http from "node:http";

const response = JSON.stringify({
  id: "proof-completion",
  object: "chat.completion",
  created: 0,
  model: "vision",
  choices: [{
    index: 0,
    message: { role: "assistant", content: "loopback image accepted" },
    finish_reason: "stop",
  }],
  usage: { prompt_tokens: 1, completion_tokens: 3, total_tokens: 4 },
});

http.createServer((request, result) => {
  if (request.method !== "POST" || request.url !== "/v1/chat/completions") {
    result.writeHead(404).end();
    return;
  }
  request.resume();
  request.on("end", () => {
    result.writeHead(200, { "content-type": "application/json" }).end(response);
  });
}).listen(18765, "127.0.0.1");

AI-assisted: built with Codex

@clawsweeper

clawsweeper Bot commented Sep 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 cli CLI command changes size: XS labels Sep 11, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 11, 2026
@clawsweeper

clawsweeper Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 11, 2026, 3:02 PM ET / 19:02 UTC.

ClawSweeper review

What this changes

Pass the selected agent into both image-description runtime paths and strengthen CLI regression coverage for explicit and inherited agent selection.

Merge readiness

✅ Ready for maintainer review

This remains a useful, focused fix: current main and the latest release still omit the selected agent at the media-runtime boundary. No blocking patch defects were found, and the supplied production CLI transcript demonstrates recovery.

Priority: P2
Reviewed head: 8e2c249023aea0797f42f242aced22216df43a3d

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A narrow caller-boundary repair with relevant production CLI proof and regression assertions; no blocking defects were found.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The supplied terminal transcript exercises the production image-description CLI and HTTP provider boundary on pinned base and head, showing recovery from selection failure and rejection of an unknown agent before dispatch; explicit-model and inherited-option coverage is supplemental parser testing.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The supplied terminal transcript exercises the production image-description CLI and HTTP provider boundary on pinned base and head, showing recovery from selection failure and rejection of an unknown agent before dispatch; explicit-model and inherited-option coverage is supplemental parser testing.
Evidence reviewed 8 items Verified introduced change: The pinned merge-base-to-head diff adds agentId to both description calls and updates the parser tests to inspect the runtime argument. The local diff agrees with the complete host introduction evidence; unrelated endpoint drift is excluded.
Current main still needs the fix: Current main resolves agentId before processing images but omits it from both describePreparedImageWithModel and describeImageFile.
Latest release retains the omission: The v2026.9.4 source also forwards only agentDir at both calls. The annotated tag was separately peeled to the supplied release commit.
Findings None None.
Security None None.

How this fits together

The image inference CLI accepts image files or URLs and selects an agent’s model and saved provider configuration. The media runtime prepares the image, invokes a provider, and returns a description.

flowchart LR
  A[Image and CLI options] --> B[Validate selected agent]
  B --> C{Explicit model supplied}
  C -->|Yes| D[Prepare image and model fallback]
  C -->|No| E[Configured image pipeline]
  D --> F[Provider using selected agent context]
  E --> F
  F --> G[Description output]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +2, Tests +24. Total +26 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 2 0 +2
Tests 1 28 4 +24
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 30 4 +26

Review metrics

None.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #145119
Summary: This PR implements the missing agent handoff described by the open canonical issue.

Members:

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

Technical review

Best possible solution:

Preserve the validated agent identity through both existing media-runtime calls while retaining current defaults, model fallbacks, and unknown-agent rejection.

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

Yes for the agent-propagation defect: current source drops the validated ID at both calls, and the contributor supplies a pinned-base failure and exact-head recovery transcript. This read-only review did not execute target code or establish universal failure across configurations.

Is this the best way to solve the issue?

Yes. Forwarding the already-validated ID repairs the existing caller contract without adding another selection mechanism; the revised assertions catch the omission that directory-only checks missed.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This repairs a bounded image-inference failure for explicit multi-agent configurations.
  • 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. Sufficient (terminal): The supplied terminal transcript exercises the production image-description CLI and HTTP provider boundary on pinned base and head, showing recovery from selection failure and rejection of an unknown agent before dispatch; explicit-model and inherited-option coverage is supplemental parser testing.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied terminal transcript exercises the production image-description CLI and HTTP provider boundary on pinned base and head, showing recovery from selection failure and rejection of an unknown agent before dispatch; explicit-model and inherited-option coverage is supplemental parser testing.

Evidence

What I checked:

  • Verified introduced change: The pinned merge-base-to-head diff adds agentId to both description calls and updates the parser tests to inspect the runtime argument. The local diff agrees with the complete host introduction evidence; unrelated endpoint drift is excluded. (src/cli/capability-cli/image.ts:180, 8e2c249023ae)
  • Current main still needs the fix: Current main resolves agentId before processing images but omits it from both describePreparedImageWithModel and describeImageFile. (src/cli/capability-cli/image.ts:177, 8a8d7a222f94)
  • Latest release retains the omission: The v2026.9.4 source also forwards only agentDir at both calls. The annotated tag was separately peeled to the supplied release commit. (src/cli/capability-cli/image.ts:177, 3a9d69db306c)
  • Existing runtime contract: The file-oriented runtime already accepts and propagates agentId into configured media execution and explicit-model provider requests. No new API, persistence format, or provider protocol is introduced. (src/media-understanding/runtime.ts:228, 8e2c249023ae)
  • Documented selection and validation: The inference documentation promises explicit agent selection for both description commands. The unchanged CLI resolver validates configured IDs before image processing or provider dispatch. Public docs: docs/cli/infer.md. (docs/cli/infer.md:105, 8e2c249023ae)
  • Production CLI proof: The supplied complete PR body at sourceRevision 0a108db8ef038bb50f126764d684639cded99f965fdb0243f1646250c30452be records the same image and production CLI command against a loopback OpenAI-compatible HTTP provider: pinned base exits with AgentSelectionRequiredError, exact head returns a description, and an unknown agent is rejected without provider dispatch. The fixture was inspected as text, not executed. The reported 249 passing tests are supplemental. (8e2c249023ae)

Likely related people:

  • omarshahine: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • steipete: 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.

obviyus added a commit that referenced this pull request Sep 12, 2026
…ces (#144931)

Closes #144930.

## What Problem This Solves

Local image, embedding, audio, and video inference fail before sending a provider request when the selected agent saves its credential as a SecretRef. Local model inference already prepares the same credential.

## Why This Change Was Made

Extend the existing selected-agent account-secret preparation to every local media and embedding runner. Rename the model-only helper to match its shared scope. Keep the preparation behavior, account selection, auth precedence, and storage unchanged.

This carries forward @masatohoshino’s repair from #144931 and retains @Bruce-Yii’s shared preparation from #141569.

## User Impact

Local media and embedding commands can use the selected agent’s saved credential reference, as local model inference already does. Missing secrets still fail before provider traffic.

## Evidence

Real CLI proof uses an isolated state, an account created with `onboard --secret-input-mode ref`, a distinct saved account on another agent, and local protocol-compatible HTTP fixtures. No Gateway or external provider account is used.

| Command | Base `f96c900b1d424820c43a184d67694003583581bf` | Head `7ab685a8195d534e22ee52202a2752c178c424de` |
| --- | --- | --- |
| Embedding create | Exit 1; unmaterialized account reference; zero requests | Exit 0; expected embedding; selected credential at HTTP egress |
| Image generate | Exit 1; same error; zero requests | Exit 0; PNG written; selected credential at HTTP egress |
| Audio transcribe | Exit 1; same error; zero requests | Exit 0; expected transcript; selected credential at HTTP egress |
| Video generate | Exit 1; same error; zero requests | Exit 0; authenticated create/download; fixture bytes written |
| Image describe, sole agent | Exit 1; unmaterialized account reference; zero requests | Exit 0; selected credential at HTTP egress; returned image description |
| Video describe, sole agent | Exit 1; unmaterialized account reference; zero requests | Exit 0; selected credential at HTTP egress; returned video description |
| Local model run | Exit 0; selected credential | Exit 0; selected credential |
| Missing selected secret | Exit 1; zero requests | Exit 1; zero requests despite a usable other-agent account |

Image proof uses the existing local-image fixture opt-in on both base and head. Audio and video use the existing private-network request opt-in. The original small-audio and image network-policy setup failures are retained in private evidence.

An independent source-blind pass confirms successful outputs and selected credentials for all four capability families, zero traffic for each missing-secret case, and the current credential after rotation in a new CLI process. The other-agent account succeeds when selected directly.

Description proof retains the real media runtime and provider adapters. Both matched pairs use the same saved account database and command arguments; configs differ only by the local fixture port. Image returns “A synthetic blue square is visible.” Video sends a playable ten-frame input and returns “A synthetic blue square moves across the video.” Removing the selected secret makes each command fail before HTTP. A separate independent audit confirms the captured requests, exact selected credential classification, media payload bytes, outputs, and base/head state comparison.

Image description uses a documented sole-agent configuration to isolate secret preparation. The explicit-agent multi-agent image command still fails on both base and head because the separate forwarding defect remains. Those failures are retained. Initial video fixture configuration and endpoint-policy failures are also retained; the qualified proof uses an existing provider adapter that supports a local compatible endpoint. No runtime or auth function is mocked in these description proofs.

Limits: HTTP fixtures prove credential routing and output handling, not external provider generation quality. Generated-video output is a synthetic container; its playback is unconfirmed. The playable video above is the description input. The independent pass observed audio model-override behavior outside this credential repair; no forwarding change is included.

## Consumers

- `model.ts`: existing local model caller migrates to the shared helper name; Gateway model flow remains unchanged.
- `embedding.ts`: `infer embedding create` prepares selected-account secrets before creating its embedding provider.
- `image.ts`: generation/edit share one runner; describe/describe-many share another; both prepare before provider auth.
- `audio.ts`: transcription prepares before the media runtime.
- `video.ts`: generation and description prepare before their respective runtimes.
- `local-account-secrets.test.ts`: retains both existing preparation contract tests under the new name.
- `capability-cli.test.ts`: mock follows the shared helper rename; command wiring coverage is retained.
- `local-runners.account-secrets.test.ts`: six registered command routes reach real SQLite account and secrets owners before mocked provider execution.
- Search across source, plugins, UI, native apps and docs finds no other consumer of the retired helper/module names. Provider inventories do not perform inference; TTS and web use separate auth contracts.
- Pipeline: registered command → config-reference resolution → selected agent → existing account-secret preparation → provider auth → HTTP request and output. Fixture HTTP headers are the credential proof boundary.

## Invalidation

No new cached or persisted state. The existing preparation activates a process-local snapshot only when none exists. Each standalone CLI process rereads the selected account and current secret value. An already active snapshot remains owned by the secrets runtime. Existing tests retain source-config preservation and active-snapshot behavior. Missing-secret and other-agent controls verify owner isolation. Independent rotation checks pass for embedding, image, audio and video in fresh CLI processes.

## Contention

No new locks, queues or transactions held. Existing account loading and snapshot activation owners remain unchanged.

## Tests

Base `f96c900b1d424820c43a184d67694003583581bf` reproduces unmaterialized account-reference failures for embedding, image generation, image description, audio transcription, video generation and video description: exit 1, zero HTTP requests. The same account succeeds for local model inference.

The regression table fails all six cases on the base with `SECRET_SURFACE_UNAVAILABLE`. It invokes the registered image generate/describe, embedding create, audio transcribe and video generate/describe commands. No new production test seam is needed.

Targeted validation passes: 316 tests across nine files, including capability commands, the existing model account-secret sibling, lazy registration, and command-secret coverage. Targeted formatting, diff whitespace, file-size and assertion safety checks pass. Full typechecking runs in CI.

Test deletion ledger: no behavior deleted. The existing helper test file is renamed with its two cases preserved; the wiring suite mock follows that rename. No baseline or snapshot exceptions.

Upgrade behavior: no schema, config, protocol, persistence, updater, Doctor or plugin contract changes; existing credentials and auth precedence are retained.

Related open work: #145188 and #145171 repair agent-option forwarding in the same owner files. Their defect is separate; this patch does not duplicate their change. Recheck overlap on the landing merge tree.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 12, 2026
…ces (openclaw#144931)

Closes openclaw#144930.

## What Problem This Solves

Local image, embedding, audio, and video inference fail before sending a provider request when the selected agent saves its credential as a SecretRef. Local model inference already prepares the same credential.

## Why This Change Was Made

Extend the existing selected-agent account-secret preparation to every local media and embedding runner. Rename the model-only helper to match its shared scope. Keep the preparation behavior, account selection, auth precedence, and storage unchanged.

This carries forward @masatohoshino’s repair from openclaw#144931 and retains @Bruce-Yii’s shared preparation from openclaw#141569.

## User Impact

Local media and embedding commands can use the selected agent’s saved credential reference, as local model inference already does. Missing secrets still fail before provider traffic.

## Evidence

Real CLI proof uses an isolated state, an account created with `onboard --secret-input-mode ref`, a distinct saved account on another agent, and local protocol-compatible HTTP fixtures. No Gateway or external provider account is used.

| Command | Base `ead0a74e21dfcd6de2007cc0695c732966a11dc0` | Head `7ab685a8195d534e22ee52202a2752c178c424de` |
| --- | --- | --- |
| Embedding create | Exit 1; unmaterialized account reference; zero requests | Exit 0; expected embedding; selected credential at HTTP egress |
| Image generate | Exit 1; same error; zero requests | Exit 0; PNG written; selected credential at HTTP egress |
| Audio transcribe | Exit 1; same error; zero requests | Exit 0; expected transcript; selected credential at HTTP egress |
| Video generate | Exit 1; same error; zero requests | Exit 0; authenticated create/download; fixture bytes written |
| Image describe, sole agent | Exit 1; unmaterialized account reference; zero requests | Exit 0; selected credential at HTTP egress; returned image description |
| Video describe, sole agent | Exit 1; unmaterialized account reference; zero requests | Exit 0; selected credential at HTTP egress; returned video description |
| Local model run | Exit 0; selected credential | Exit 0; selected credential |
| Missing selected secret | Exit 1; zero requests | Exit 1; zero requests despite a usable other-agent account |

Image proof uses the existing local-image fixture opt-in on both base and head. Audio and video use the existing private-network request opt-in. The original small-audio and image network-policy setup failures are retained in private evidence.

An independent source-blind pass confirms successful outputs and selected credentials for all four capability families, zero traffic for each missing-secret case, and the current credential after rotation in a new CLI process. The other-agent account succeeds when selected directly.

Description proof retains the real media runtime and provider adapters. Both matched pairs use the same saved account database and command arguments; configs differ only by the local fixture port. Image returns “A synthetic blue square is visible.” Video sends a playable ten-frame input and returns “A synthetic blue square moves across the video.” Removing the selected secret makes each command fail before HTTP. A separate independent audit confirms the captured requests, exact selected credential classification, media payload bytes, outputs, and base/head state comparison.

Image description uses a documented sole-agent configuration to isolate secret preparation. The explicit-agent multi-agent image command still fails on both base and head because the separate forwarding defect remains. Those failures are retained. Initial video fixture configuration and endpoint-policy failures are also retained; the qualified proof uses an existing provider adapter that supports a local compatible endpoint. No runtime or auth function is mocked in these description proofs.

Limits: HTTP fixtures prove credential routing and output handling, not external provider generation quality. Generated-video output is a synthetic container; its playback is unconfirmed. The playable video above is the description input. The independent pass observed audio model-override behavior outside this credential repair; no forwarding change is included.

## Consumers

- `model.ts`: existing local model caller migrates to the shared helper name; Gateway model flow remains unchanged.
- `embedding.ts`: `infer embedding create` prepares selected-account secrets before creating its embedding provider.
- `image.ts`: generation/edit share one runner; describe/describe-many share another; both prepare before provider auth.
- `audio.ts`: transcription prepares before the media runtime.
- `video.ts`: generation and description prepare before their respective runtimes.
- `local-account-secrets.test.ts`: retains both existing preparation contract tests under the new name.
- `capability-cli.test.ts`: mock follows the shared helper rename; command wiring coverage is retained.
- `local-runners.account-secrets.test.ts`: six registered command routes reach real SQLite account and secrets owners before mocked provider execution.
- Search across source, plugins, UI, native apps and docs finds no other consumer of the retired helper/module names. Provider inventories do not perform inference; TTS and web use separate auth contracts.
- Pipeline: registered command → config-reference resolution → selected agent → existing account-secret preparation → provider auth → HTTP request and output. Fixture HTTP headers are the credential proof boundary.

## Invalidation

No new cached or persisted state. The existing preparation activates a process-local snapshot only when none exists. Each standalone CLI process rereads the selected account and current secret value. An already active snapshot remains owned by the secrets runtime. Existing tests retain source-config preservation and active-snapshot behavior. Missing-secret and other-agent controls verify owner isolation. Independent rotation checks pass for embedding, image, audio and video in fresh CLI processes.

## Contention

No new locks, queues or transactions held. Existing account loading and snapshot activation owners remain unchanged.

## Tests

Base `ead0a74e21dfcd6de2007cc0695c732966a11dc0` reproduces unmaterialized account-reference failures for embedding, image generation, image description, audio transcription, video generation and video description: exit 1, zero HTTP requests. The same account succeeds for local model inference.

The regression table fails all six cases on the base with `SECRET_SURFACE_UNAVAILABLE`. It invokes the registered image generate/describe, embedding create, audio transcribe and video generate/describe commands. No new production test seam is needed.

Targeted validation passes: 316 tests across nine files, including capability commands, the existing model account-secret sibling, lazy registration, and command-secret coverage. Targeted formatting, diff whitespace, file-size and assertion safety checks pass. Full typechecking runs in CI.

Test deletion ledger: no behavior deleted. The existing helper test file is renamed with its two cases preserved; the wiring suite mock follows that rename. No baseline or snapshot exceptions.

Upgrade behavior: no schema, config, protocol, persistence, updater, Doctor or plugin contract changes; existing credentials and auth precedence are retained.

Related open work: openclaw#145188 and openclaw#145171 repair agent-option forwarding in the same owner files. Their defect is separate; this patch does not duplicate their change. Recheck overlap on the landing merge tree.

Co-authored-by: Ayaan Zaidi <[email protected]>
obviyus added a commit that referenced this pull request Sep 12, 2026
Related: #144931

## What Problem This Solves

Restoring an agent backup and registering that directory under a new agent name lets local capability inference use the original agent's saved credential. This follows supported `backup create`, `backup restore --target`, and `agents add --agent-dir` commands. Local model inference already refuses the durable owner mismatch. Follow-up to our #144931; found by the adversarial round, with no external reporter.

## Why This Change Was Made

The shared local account preparation now passes the selected identity to the auth database owner before resolving credentials, including when a secrets snapshot is active. The auth reader delegates to the existing durable schema-owner assertion without requiring a newer session schema. No schema, migration, configuration, or protocol change.

The decision 'may this agent use this saved credential' is made by exactly one mechanism at `src/state/openclaw-agent-db-schema-helpers.ts:311`.

## User Impact

A restored directory registered under another name now produces the same owner-mismatch refusal across local inference commands before any provider request. Legitimate saved credentials continue to work.

## Evidence

Pinned base: `d5e652099074b5801cc7e4e3a108c035d2888e99`.

- Supported restore reproduction: base embedding exits 0 and sends one recorded provider request with the original agent's synthetic credential. The model control exits 1 with `belongs to agent ops; requested agent restored` and sends no request.
- Candidate `2e81eb5998b460c47463907b0b8fdac88b19ead0`: restored embedding and model both exit 1 with the owner mismatch and zero provider requests. All six repaired commands—embedding, image generation, image description, audio transcription, video generation, and video description—reject the foreign owner before dispatch. Model inference remains a separate unchanged control. A supplemental video-generation capture uses the configured recorder endpoint: the legitimate owner creates and downloads a video; the restored owner exits 1 with the owner mismatch and sends zero create/content requests.
- Final pre-landing rebase: head `f1a33f00c1c7cdcc332b3e5464430f46a49e044c` preserves the exact repair patch and all four changed files. The six restored-owner refusal commands and legitimate-owner video/model controls were refreshed on this head; prior pinned-base, rotation, older-state, and targeted-test evidence remains retained.
- Legitimate saved-reference accounts succeed for all six command families. The known multi-agent image-description forwarding failure remains unchanged; the sole-agent description control succeeds, as in the original proof. #145188/#145171 track that separate path.
- Rotated credentials succeed through model, embedding, image edit, describe-many, audio, video generation/download, and video description. An unavailable unrelated credential does not block the healthy account.
- Previous state: v2026.9.4 application source created a schema-19 saved account; candidate embedding succeeds with its credential through the existing schema-20 upgrade path. The older source needed only upstream build-tool repair #144831 to complete its build; application sources were unchanged from the tag.
- All six registered capability regression cases fail on the original code. Candidate capability tests: 255 passed; auth SQLite sibling: 16 passed. The helper provenance test passes after an isolation-only correction.
- A source-blind validator independently ran the supported restore and legitimate-account CLI flows on pre-rebase head `2e81eb5998b460c47463907b0b8fdac88b19ead0`: PASS. The focused post-rebase CLI refresh was run by the repair worker.
- Proof uses synthetic credentials and a loopback provider to measure actual credential routing and request absence.

## Consumers

Seven calls to `prepareLocalCapabilityAccountSecrets` cover local `model run`, `embedding create`, image `generate`/`edit`, image `describe`/`describe-many`, audio `transcribe`, video `generate`/download, and video `describe`. Their shared preparation retains the selected identity and validates before credential use. No command-specific predicates were added.

`capability` is an alias for the same registered command tree at `src/cli/capability-cli.ts:106-124`, as documented by `docs/cli/infer.md:9`; it reaches the same preparation owner.

Test consumers: `src/cli/capability-cli/local-account-secrets.test.ts:35,49` imports and calls the preparation helper for source-config provenance, and lines 18-20 mock the new auth-owner adapter for isolation. `src/cli/capability-cli.test.ts:336-338` mocks shared preparation for command-wiring coverage.

`assertAuthProfileStoreAgentOwner` has one production caller: shared local capability account preparation. The existing canonical assertion remains used by agent database schema, read-only access, writable open, admission, and maintenance. Model preparation also reaches that same assertion through persisted model-catalog reads.

Memory CLI uses its separate config-reference preparation in `extensions/memory-core/src/cli-runtime-common.ts`; adversarial finding F4 remains separate. Provider listings, web, and speech synthesis do not consume this helper.

Related open PRs #145188 and #145171 forward agent identity through media-understanding calls. They are separate from this saved-credential admission. Preserve the shared preparation call when reconciling landing order. Their branches and metadata were not changed.

## Invalidation

No owner verdict is cached. Every shared preparation call reads durable metadata, before the active-snapshot shortcut. Existing auth read-pool lifecycle and credential revision invalidation remain the owners. Credential mutation advances the revision; snapshot activation validates it; clearing the runtime clears linked snapshots. Database/root closure and process exit close pooled readers. No additional cache or lifecycle was introduced.

## Contention

No explicit transaction, lock, or queue is held across an await. The short metadata read uses the existing auth read connection and busy policy. Credential preparation retains its existing asynchronous lifecycle.

## Tests

The registered entry points `infer image generate`, `infer image describe`, `infer embedding create`, `infer audio transcribe`, `infer video generate`, and `infer video describe` each first succeed for their durable owner, then reject another selected identity without further credential egress, with both active and cleared secrets snapshots.

Deletion ledger: removed the helper-only “does not replace an already active secrets runtime snapshot” case because its no-directory-resolution assertion preserved the unsafe bypass. The registered-command cases now cover admission with an active snapshot. The helper source-config provenance case remains, with its new database dependency mocked to keep fixed paths isolated.

Moved side effects: none. Production grows by 25 net lines to connect explicit selected identity to the existing durable decision through the version-tolerant auth reader.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 13, 2026
…145692)

Related: openclaw#144931

## What Problem This Solves

Restoring an agent backup and registering that directory under a new agent name lets local capability inference use the original agent's saved credential. This follows supported `backup create`, `backup restore --target`, and `agents add --agent-dir` commands. Local model inference already refuses the durable owner mismatch. Follow-up to our openclaw#144931; found by the adversarial round, with no external reporter.

## Why This Change Was Made

The shared local account preparation now passes the selected identity to the auth database owner before resolving credentials, including when a secrets snapshot is active. The auth reader delegates to the existing durable schema-owner assertion without requiring a newer session schema. No schema, migration, configuration, or protocol change.

The decision 'may this agent use this saved credential' is made by exactly one mechanism at `src/state/openclaw-agent-db-schema-helpers.ts:311`.

## User Impact

A restored directory registered under another name now produces the same owner-mismatch refusal across local inference commands before any provider request. Legitimate saved credentials continue to work.

## Evidence

Pinned base: `79a02b57732d6f4b24c7325d41a452d9d494e319`.

- Supported restore reproduction: base embedding exits 0 and sends one recorded provider request with the original agent's synthetic credential. The model control exits 1 with `belongs to agent ops; requested agent restored` and sends no request.
- Candidate `2e81eb5998b460c47463907b0b8fdac88b19ead0`: restored embedding and model both exit 1 with the owner mismatch and zero provider requests. All six repaired commands—embedding, image generation, image description, audio transcription, video generation, and video description—reject the foreign owner before dispatch. Model inference remains a separate unchanged control. A supplemental video-generation capture uses the configured recorder endpoint: the legitimate owner creates and downloads a video; the restored owner exits 1 with the owner mismatch and sends zero create/content requests.
- Final pre-landing rebase: head `f1a33f00c1c7cdcc332b3e5464430f46a49e044c` preserves the exact repair patch and all four changed files. The six restored-owner refusal commands and legitimate-owner video/model controls were refreshed on this head; prior pinned-base, rotation, older-state, and targeted-test evidence remains retained.
- Legitimate saved-reference accounts succeed for all six command families. The known multi-agent image-description forwarding failure remains unchanged; the sole-agent description control succeeds, as in the original proof. openclaw#145188/openclaw#145171 track that separate path.
- Rotated credentials succeed through model, embedding, image edit, describe-many, audio, video generation/download, and video description. An unavailable unrelated credential does not block the healthy account.
- Previous state: v2026.9.4 application source created a schema-19 saved account; candidate embedding succeeds with its credential through the existing schema-20 upgrade path. The older source needed only upstream build-tool repair openclaw#144831 to complete its build; application sources were unchanged from the tag.
- All six registered capability regression cases fail on the original code. Candidate capability tests: 255 passed; auth SQLite sibling: 16 passed. The helper provenance test passes after an isolation-only correction.
- A source-blind validator independently ran the supported restore and legitimate-account CLI flows on pre-rebase head `2e81eb5998b460c47463907b0b8fdac88b19ead0`: PASS. The focused post-rebase CLI refresh was run by the repair worker.
- Proof uses synthetic credentials and a loopback provider to measure actual credential routing and request absence.

## Consumers

Seven calls to `prepareLocalCapabilityAccountSecrets` cover local `model run`, `embedding create`, image `generate`/`edit`, image `describe`/`describe-many`, audio `transcribe`, video `generate`/download, and video `describe`. Their shared preparation retains the selected identity and validates before credential use. No command-specific predicates were added.

`capability` is an alias for the same registered command tree at `src/cli/capability-cli.ts:106-124`, as documented by `docs/cli/infer.md:9`; it reaches the same preparation owner.

Test consumers: `src/cli/capability-cli/local-account-secrets.test.ts:35,49` imports and calls the preparation helper for source-config provenance, and lines 18-20 mock the new auth-owner adapter for isolation. `src/cli/capability-cli.test.ts:336-338` mocks shared preparation for command-wiring coverage.

`assertAuthProfileStoreAgentOwner` has one production caller: shared local capability account preparation. The existing canonical assertion remains used by agent database schema, read-only access, writable open, admission, and maintenance. Model preparation also reaches that same assertion through persisted model-catalog reads.

Memory CLI uses its separate config-reference preparation in `extensions/memory-core/src/cli-runtime-common.ts`; adversarial finding F4 remains separate. Provider listings, web, and speech synthesis do not consume this helper.

Related open PRs openclaw#145188 and openclaw#145171 forward agent identity through media-understanding calls. They are separate from this saved-credential admission. Preserve the shared preparation call when reconciling landing order. Their branches and metadata were not changed.

## Invalidation

No owner verdict is cached. Every shared preparation call reads durable metadata, before the active-snapshot shortcut. Existing auth read-pool lifecycle and credential revision invalidation remain the owners. Credential mutation advances the revision; snapshot activation validates it; clearing the runtime clears linked snapshots. Database/root closure and process exit close pooled readers. No additional cache or lifecycle was introduced.

## Contention

No explicit transaction, lock, or queue is held across an await. The short metadata read uses the existing auth read connection and busy policy. Credential preparation retains its existing asynchronous lifecycle.

## Tests

The registered entry points `infer image generate`, `infer image describe`, `infer embedding create`, `infer audio transcribe`, `infer video generate`, and `infer video describe` each first succeed for their durable owner, then reject another selected identity without further credential egress, with both active and cleared secrets snapshots.

Deletion ledger: removed the helper-only “does not replace an already active secrets runtime snapshot” case because its no-directory-resolution assertion preserved the unsafe bypass. The registered-command cases now cover admission with an active snapshot. The helper source-config provenance case remains, with its new database dependency mocked to keep fixed paths isolated.

Moved side effects: none. Production grows by 25 net lines to connect explicit selected identity to the existing durable decision through the version-tolerant auth reader.

Co-authored-by: Ayaan Zaidi <[email protected]>
@RileyJJY
RileyJJY force-pushed the sunlit/fix/issue-145119 branch from 8e2c249 to 9438ac0 Compare September 14, 2026 11:02
@RileyJJY

Copy link
Copy Markdown
Contributor Author

Closing this PR because the underlying source fix is already present on main; the rebased branch only contains duplicate tests.

@RileyJJY RileyJJY closed this Sep 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

1 participant