Skip to content

fix(cli): refuse another agent's credentials after restore - #145692

Merged
obviyus merged 1 commit into
mainfrom
bugloop/infer-agent-owner-check
Sep 12, 2026
Merged

obviyus merged 1 commit into
mainfrom
bugloop/infer-agent-owner-check

Conversation

@obviyus

@obviyus obviyus commented Sep 12, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #144931, #145188, #145171, #144831.

What Problem This Solves

Restoring an agent backup under a different agent name could let local capability commands use the original agent's saved credential. Local model inference already rejected this ownership mismatch.

Why This Change Was Made

Shared local account preparation now passes the selected agent identity to the existing durable credential-owner check before resolving credentials, including when a secrets snapshot is active.

User Impact

Local inference rejects credentials owned by another agent before making a request. Legitimate accounts continue to work. No schema, migration, configuration, or protocol change is required.

Consumers: embedding, image generation and description, audio transcription, and video generation and description now enforce the same saved-credential ownership rule.

Evidence

Supported backup restore and agent registration commands reproduced credential use before the fix. All six repaired command families then rejected the restored identity with zero recorded requests. Legitimate and rotated credentials succeeded against a recording endpoint. Registered capability regressions failed before the fix; 255 capability tests and 16 auth database tests passed. Post-rebase command checks passed. Previous-release saved accounts remained usable. A separate multi-agent image-description forwarding issue remains tracked by #145188 and #145171.

@obviyus
obviyus requested a review from a team as a code owner September 12, 2026 06:21
@clawsweeper

clawsweeper Bot commented Sep 12, 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 agents Agent runtime and tooling size: S maintainer Maintainer-authored PR labels Sep 12, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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 12, 2026
@clawsweeper

clawsweeper Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 12, 2026, 2:55 AM ET / 06:55 UTC (Revision 3).

ClawSweeper review

What this changes

Local inference commands now check that an agent database belongs to the selected agent before preparing saved credentials, including when a secrets snapshot is already active.

Merge readiness

⛔ Blocked before merge - 3 items remain

This remains a useful, focused repair absent from fetched main. No introduced correctness defect was found; the retained proof covers legitimate credentials and foreign-owner refusal. The recorded owner-review approval needs reconciliation with the restricted-path ownership requirement.

Priority: P2
Reviewed head: f1a33f00c1c7cdcc332b3e5464430f46a49e044c
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with strong relevant behavior evidence and no correctness findings; ownership acceptance remains a separate landing decision.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The supplied production-CLI observations exercise the changed shared preparation through supported restore and inference flows: legitimate owners succeed, restored foreign owners generate zero provider requests, and rotation and older-state controls pass. The registered-command tests additionally cover active-snapshot reassignment; no new persisted authorization is introduced.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The supplied production-CLI observations exercise the changed shared preparation through supported restore and inference flows: legitimate owners succeed, restored foreign owners generate zero provider requests, and rotation and older-state controls pass. The registered-command tests additionally cover active-snapshot reassignment; no new persisted authorization is introduced.
Evidence reviewed 7 items Guard precedes snapshot reuse: The selected directory and agent identity reach the auth ownership check before the active-snapshot return. The adapter reuses the existing read pool and canonical ownership assertion without writing metadata or requiring current session-schema convergence.
Existing ownership contract: The canonical assertion rejects a wrong database role, missing recorded owner, or different normalized agent ID. Existing writable and read-only agent database paths use the same assertion. This is an OpenClaw database contract; the changed behavior does not depend on the Codex harness.
Still necessary on fetched main: Fetched main retains the active-snapshot shortcut without selected-agent database admission. The merged saved-SecretRef repair at #144931 supplies shared preparation but does not implement this ownership check; it is not a fixing PR for this request. No shipped fix is established.
Findings None None.
Security None None.

How this fits together

Local inference commands select an agent and prepare its saved credentials before calling an embedding or media provider. The auth database adapter checks the database’s recorded owner through the shared state ownership assertion.

flowchart TD
  A[Local inference command] --> B[Selected agent and directory]
  B --> C[Read database ownership]
  C --> D{Owner matches?}
  D -->|No| E[Refuse before provider request]
  D -->|Yes| F[Prepare or reuse secrets]
  F --> G[Provider request and output]
Loading

Decision needed

Question Recommendation
Does the recorded owner-review approval satisfy the listed security-owner requirement for refusing renamed restored-agent databases? Confirm owner acceptance: Validate the existing approval against the listed security ownership, or obtain that owner’s acceptance of the documented refusal.

Why: The approval comment is relevant, but its author’s listed-owner authority is not established in the available evidence; code correctness and runtime proof cannot establish that authority.

Before merge

  • Resolve merge risk (P1) - A restored database registered under a different agent ID will now stop local inference before dispatch; operators must retain the recorded identity or initialize separate agent state. Acceptance of this intentional compatibility change by the listed security owner remains unverified.
  • Complete next step (P2) - Reconcile the recorded owner-review approval with listed security-owner acceptance of the restored-agent refusal before merge.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.
Agent review details

Security

None.

PR surface

Source +25, Tests +5. Total +30 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 26 1 +25
Tests 2 23 18 +5
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 49 19 +30

Review metrics

Metric Value Why it matters
Production versus test growth production +25 net lines; tests +5 net lines Production growth connects selected-agent identity to an existing ownership decision, while tests extend the existing command table.

Merge-risk options

Maintainer options:

  1. Accept the documented ownership refusal (recommended)
    Confirm security-owner acceptance while retaining the recorded legitimate-account and older-state proof.
  2. Pause for identity-transfer direction
    Defer this change if maintainers require restored databases to support a different agent identity through an explicit migration.

Technical review

Best possible solution:

Use the existing durable-owner assertion consistently across local inference, with security-owner acceptance of the refusal and preservation of legitimate fresh and upgraded account behavior.

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

Yes: restore an agent backup, register its directory under another agent ID, and invoke local embedding inference. Fetched-main source lacks the identity check, and the supplied CLI observations demonstrate the failure; this read-only review did not execute it.

Is this the best way to solve the issue?

Yes: passing the selected identity to the existing database-owner assertion is a narrow repair, and checking before snapshot reuse closes the demonstrated bypass without adding a competing policy or schema.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This repairs a bounded restored-agent credential-selection defect in local inference.
  • merge-risk: 🚨 compatibility: Previously successful local inference against a restored database registered under another ID will now be refused.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The supplied production-CLI observations exercise the changed shared preparation through supported restore and inference flows: legitimate owners succeed, restored foreign owners generate zero provider requests, and rotation and older-state controls pass. The registered-command tests additionally cover active-snapshot reassignment; no new persisted authorization is introduced.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied production-CLI observations exercise the changed shared preparation through supported restore and inference flows: legitimate owners succeed, restored foreign owners generate zero provider requests, and rotation and older-state controls pass. The registered-command tests additionally cover active-snapshot reassignment; no new persisted authorization is introduced.

Evidence

What I checked:

  • Guard precedes snapshot reuse: The selected directory and agent identity reach the auth ownership check before the active-snapshot return. The adapter reuses the existing read pool and canonical ownership assertion without writing metadata or requiring current session-schema convergence. (src/cli/capability-cli/local-account-secrets.ts:15, f1a33f00c1c7)
  • Existing ownership contract: The canonical assertion rejects a wrong database role, missing recorded owner, or different normalized agent ID. Existing writable and read-only agent database paths use the same assertion. This is an OpenClaw database contract; the changed behavior does not depend on the Codex harness. (src/state/openclaw-agent-db-schema-helpers.ts:311, f1a33f00c1c7)
  • Still necessary on fetched main: Fetched main retains the active-snapshot shortcut without selected-agent database admission. The merged saved-SecretRef repair at fix: local infer image, embedding, audio, and video commands fail for saved accounts stored as SecretRefs #144931 supplies shared preparation but does not implement this ownership check; it is not a fixing PR for this request. No shipped fix is established. (src/cli/capability-cli/local-account-secrets.ts:14, 354943cc2f7e)
  • Retained production-path proof: The complete supplied PR body, captured in sourceRevision ed74c1183edda40207e5335e278e737d1b177a394a353ff28918dceee77cad42, reports supported backup/restore and agent-registration flows through the production CLI against a loopback provider. Base embedding sent the original agent’s synthetic credential; candidate commands rejected the restored identity with zero provider requests. All six refusal commands and legitimate video/model controls were refreshed on the reviewed head. Retained evidence also covers legitimate accounts, credential rotation, unrelated unavailable credentials, and a v2026.9.4-created schema-19 account. These are supplied runtime observations, not executions performed during this review. (f1a33f00c1c7)
  • Registered-command regression coverage: Six command cases first resolve the legitimate owner’s credential, then reject a different selected identity without additional credential egress, both with active and cleared snapshots. The provider boundary is mocked in these tests, so they supplement the separately supplied CLI proof. The removed helper test’s no-directory-resolution assertion preserved the bypass. (src/cli/capability-cli/local-runners.account-secrets.test.ts:166, f1a33f00c1c7)
  • Restricted ownership and prior-review disposition: CODEOWNERS assigns auth-profiles to openclaw/openclaw-secops. The prior review had no findings and requested ownership acceptance. The later approval at fix(cli): refuse another agent's credentials after restore #145692 (comment) explicitly names owner-review scope for the previous head, which is relevant positive engagement, but the supplied record does not establish listed-team membership or a listed-owner review. Live ownership verification was unavailable; this is a reviewer verification limit, not missing contributor behavior proof. (.github/CODEOWNERS:45, f1a33f00c1c7)

Likely related people:

  • openclaw/openclaw-secops: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • masatohoshino: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed 2026-09-12T06:27:39.386Z sha 2e81eb5 :: blocked before merge. :: none
  • reviewed 2026-09-12T06:43:29.037Z sha 2e81eb5 :: blocked before merge. :: none

@obviyus

obviyus commented Sep 12, 2026

Copy link
Copy Markdown
Collaborator Author

landpr-approve-admin-merge
pr: 145692
head: 2e81eb5
scope: owner-review

@obviyus
obviyus force-pushed the bugloop/infer-agent-owner-check branch from 2e81eb5 to f1a33f0 Compare September 12, 2026 06:48
@obviyus

obviyus commented Sep 12, 2026

Copy link
Copy Markdown
Collaborator Author

landpr-approve-admin-merge
pr: 145692
head: f1a33f0
scope: owner-review

@obviyus
obviyus merged commit 583d23f into main Sep 12, 2026
187 checks passed
@obviyus
obviyus deleted the bugloop/infer-agent-owner-check branch September 12, 2026 07:13
@obviyus

obviyus commented Sep 12, 2026

Copy link
Copy Markdown
Collaborator Author

Landed the saved-credential ownership repair, found by the adversarial round as a follow-up to #144931.

  • Bug: A supported backup/restore followed by registration under a new agent name could send the original agent's saved credential.
  • Fix: Shared inference preparation now uses the existing durable owner check before credential use.
  • Proof: All six repaired commands refuse the restored owner with zero provider requests. The model control remains unchanged. Legitimate credentials, rotation, and previous-release state are covered.
  • Validation: Targeted tests and required CI passed. Fresh review found no code or security defects.
  • Owner review: Used the exact-head owner-review approval to waive the procedural listed-owner review hold. Code, proof, and CI gates remained required.

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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling cli CLI command changes maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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: 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