Skip to content

fix(auth): saving an API key for a new agent fails with a database identity error - #175656

Merged
steipete merged 1 commit into
mainfrom
codex/fresh-agent-db-identity
Oct 17, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/fresh-agent-db-identity

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: saving an API key for a newly configured agent (Gateway models.authSetApiKey, as used by onboarding, the Control UI, and live suites) fails with UNAVAILABLE: SQLite database path identity changed: …/agents/<id>/agent/openclaw-agent.sqlite when that agent's database does not exist yet.

User Impact

User impact: storing credentials for a fresh agent succeeds instead of failing the first time. Integrity checks for existing agent databases are unchanged: a known database file that gets replaced is still rejected.

Why This Change Was Made

Candidate auth-store discovery records each candidate database's identity. For a fresh agent that identity is "absent at this path". The same Gateway then creates the database, either in the operation itself or through concurrent startup work, and the later identity assertion rejects the file that now exists. The capture/check pair came from #166183.

An absence snapshot protects no file. So the first check after the file appears adopts its identity once, and every later check (including candidates discovered as existing files) stays strict. The Gateway owns these databases, so a foreign writer creating the file in that window is not a supported concurrent case. That trade is noted in the code.

A first attempt only accepted files created by the same operation's execution owner. Under host load it still failed intermittently when startup work created the database first. The second commit replaces that with the simpler rule and removes the owner-witness plumbing, leaving a net diff of 2 files.

Evidence

  • Offline repro (fresh agent, loopback provider, no inference): before, models.authSetApiKey failed with the identity error. After, 8/8 consecutive runs succeed, moving path: → file: with zero inference requests.
  • Live: src/gateway/gateway-cron-tools-allow.live.test.ts used to fail its OpenClaw-harness case with this identity error on main and on the first attempt. It now passes both cases (OpenClaw 173s, Codex 188s). gateway-cron-placement.live.test.ts still fails with an unrelated "forced cron run did not publish its completion record", the same as before this change.
  • Unit: candidate-stores.test.ts covers creation before and during first use, replacement after adoption, and replacement of a file discovered as existing (37 tests with the creation-witness suite).
  • Autoreview: scoped-clean at P1.

@steipete
steipete marked this pull request as ready for review October 17, 2026 15:38
@clawsweeper

clawsweeper Bot commented Oct 17, 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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-17T17:53:32.736461Z 71aa372 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: 71aa37229151ea842a812a8cfc10a45e4e24ff2a
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/agents/auth-profiles/candidate-stores.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.

Carefully review these changes before merging.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Oct 17, 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. P1 High-priority user-facing bug, regression, or broken workflow. 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 clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 17, 2026
@clawsweeper

clawsweeper Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

The PR lets auth-store candidates discovered before database creation adopt the newly created file identity.

Example: Save an API key for a newly configured agent named probe.

  • Before: If startup creates probe's database after candidate discovery, saving fails with a SQLite database path identity error.
  • After: The candidate adopts the new file identity, allowing the save while rejecting subsequent file replacement.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused patch has useful database-boundary coverage and passing gates; shipped-entry runtime results are reported without attached traces.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate; its body reports fresh-agent Gateway saves and live cases, while inspectable tests exercise real SQLite owners.
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 credentials for a fresh agent fails when its database appears after candidate discovery.
Reason: The maintainer-authored direction restores credential saving within the documented Gateway ownership contract.

Regression provenance

Possible regression — probable (reviewed change; failure trace). No predecessor PR is attributed.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it fixes a current-main credential-saving failure, preserves known-file replacement checks, and has no actionable review findings.

Priority: P1
Reviewed head: 40437d50d2f2b86ff5457a9671d949d40e6ee5d9

Before merge

None.

Findings

None.

Agent review details

How this fits together

Gateway credential operations discover agent auth stores, then use the existing readers and transaction owners to inspect or update credentials in SQLite.

flowchart TD
  A[Gateway API key request] --> B[Credential save owner]
  B --> C[Candidate store discovery]
  C --> D[Candidate identity check]
  D --> E[Auth reader or writer]
  E --> F[Agent SQLite database]
Loading

Technical review

Best possible solution:

Use this focused candidate-owner fix while retaining strict identity checks after a physical file is observed.

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

Source shows discovery capturing a path identity and later checks rejecting legitimate database creation; the maintainer reports a matching Gateway reproduction, but this read-only review ran no target code.

Is this the best way to solve the issue?

The change belongs in the shared candidate owner, fixes all its read/write adapters, and preserves existing-file checks without adding creation-witness machinery.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Candidate physical identity checks changes intended behavior with a stated reason (2fe7995: Capture physical database identity before asynchronous worker operations so replaced stores cannot be used.)
  • Native worker candidate update checks keeps the original intent (43c68c3: Historical OAuth peers must update through the catalog worker's existing write owner while retaining captured target identity and transactional credential comparisons.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Vincent Koc: Raw commit b824b72 adds src/agents/auth-profiles/candidate-stores.ts:23 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: b824b72ce284; files: src/agents/auth-profiles/candidate-stores.ts)
  • Ayaan Zaidi: Raw commit 43c68c3 adds src/agents/auth-profiles/candidate-stores.ts:233 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 43c68c34df71; files: src/agents/auth-profiles/candidate-stores.ts)

PR surface

Source +10, Tests +116. Total +126 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 16 6 +10
Tests 1 117 1 +116
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 133 7 +126

Labels

Label changes:

No label changes.

Label justifications:

  • P1: The current-main defect breaks credential saving for newly configured agents and blocks the affected agent workflow.
  • 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 October 17, 2026, 11:54 AM ET / 15:54 UTC.

Saving an API key for a freshly configured agent failed with 'SQLite
database path identity changed': candidate discovery recorded the agent
database as absent, the Gateway then created it, and the later identity
assertion rejected the new file. An absence snapshot protects no file, so
the first check after the file appears adopts its identity; every later
check stays strict, and a replaced known file is still rejected.
@steipete
steipete force-pushed the codex/fresh-agent-db-identity branch from 40437d5 to 71aa372 Compare October 17, 2026 17:50
@steipete
steipete merged commit dc4b96e into main Oct 17, 2026
115 checks passed
@steipete
steipete deleted the codex/fresh-agent-db-identity branch October 17, 2026 19:11
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 18, 2026
…penclaw#175656)

Saving an API key for a freshly configured agent failed with 'SQLite
database path identity changed': candidate discovery recorded the agent
database as absent, the Gateway then created it, and the later identity
assertion rejected the new file. An absence snapshot protects no file, so
the first check after the file appears adopts its identity; every later
check stays strict, and a replaced known file is still rejected.
RomneyDa added a commit that referenced this pull request Oct 30, 2026
Backport the exact candidate-store adoption contract from main #175656 for the release line.

Co-authored-by: roboclaw-bot <[email protected]>
Co-authored-by: RomneyDa <[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 P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. security-sensitive-changed 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