Skip to content

refactor: record inline API-key failures off the main thread - #153570

Merged
steipete merged 3 commits into
mainfrom
codex/auth-inline-failure-publish-20260920
Sep 20, 2026
Merged

steipete merged 3 commits into
mainfrom
codex/auth-inline-failure-publish-20260920

Conversation

@steipete

@steipete steipete commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Related: #152286

What Problem This Solves

Inline API-key auth and billing failures still read, update, and republish auth state with native SQLite work on the calling thread during model retry handling.

User Impact

The retry controller records inline-key failures through the selected agent's existing SQLite worker, preserving cooldown behavior, scoped CLI auth state, and the synchronous public SDK APIs. This changes where bookkeeping runs; it does not claim faster retries. No configuration, schema, migration, or updater change is required.

Why This Change Was Made

The existing agent owner captures admission before waiting, rereads authoritative state inside its transaction, and publishes committed facts before the next admitted operation. Host snapshots use canonical worker reads and retain current resolved secrets and external profiles. Closing a queued owner rejects the write. Once a commit is acknowledged, publication, observer, or cleanup failures cannot make that write replayable, and a failing observer cannot leave sibling snapshots exposing an older cooldown.

Failure calculation, JSON-cell writes, and snapshot composition remain shared with the retained synchronous paths. The old inline timeout test's generic-updater mock is replaced by actual retry-controller state checks. Existing billing tests now use the required host-owned worker lane and await native cleanup before removing their state. A required preexisting prepared-runtime fixture uses its already-reviewed lifecycle factory with unchanged assertions.

Evidence

  • All 24 runtime cases pass: 13 real retry-controller/SQLite controls and the 11 existing auth-failure persistence cases. They cover three owner layouts with zero host data SQL after explicit bootstrap, rollback and recovery, FIFO ordering, queued agent/root closure, scoped directory overrides and inherited counters, empty-store initialization, timeout without writes, billing backoff, and post-commit closure with throwing observers.
  • The derived-snapshot regression failed on the unfixed worker candidate: the parent committed counter three while its child still exposed counter two. The same test passes after per-snapshot recovery; healthy fanout also preserves local precedence, resolved keys, external overlays, and child durable rows.
  • Retained neighboring auth usage, inherited-owner, write-admission, and snapshot proof passes all 159 cases. The final integrated review composed against current main is clean through P2.
  • All 1,119 routing-catalog cases and 40 export-protocol guard cases pass. The guard also passes on the actual main-plus-candidate composition, including the landed Board and Heartbeat workers; unrelated modules remain collisions.
  • The full package/SDK/UI build and the corrected production runtime build both pass. The emitted sidecar also runs on a physical Node worker: commit counter one, confirmed rollback retaining counter one, explicit recovery to counter two, and preserved borrowed-connection ownership.
  • The later repairs make host operation/release settlement explicit, remove an unused private export, and complete test/protocol inventories. The worker implementation and import/entrypoint graph are unchanged; the final host paths are covered by the 24 runtime cases. The complete changed-file gate passes, and exact-head CI is green.

Data-model compatibility, addressing the review note: both SQLite schema files and their version declarations are byte-identical to the PR base. AUTH_STORE_VERSION remains 1, and the state serializer and persisted-store reader are unchanged. The adapter change extracts the same table/key/column DML into a shared helper; it introduces no schema or format migration. The real-controller round trips seed existing-format stores, write through the worker, and read them with the unchanged reader while checking credentials, order, last-good, and sibling state. Empty-store creation, legacy-main ownership, and a relocated shared base are covered too.

A single identical-input scoped/empty-store test-harness comparison passed on both versions: baseline 130.50 seconds / 3,485,335,552 bytes maximum RSS; worker candidate 99.29 seconds / 3,160,997,888 bytes. These are whole-harness observations, not production latency or isolated-allocation measurements. These historical matched-input observations describe the initial worker conversion; later settlement and validation repairs were verified separately.

@clawsweeper

clawsweeper Bot commented Sep 20, 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 docs Improvements or additions to documentation agents Agent runtime and tooling size: XL maintainer Maintainer-authored PR labels Sep 20, 2026
@github-actions

github-actions Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components. This comment is informational because the PR author has repository Maintain or Admin access.

  • Current SHA: 8b828b3a3325530744d584687d3045a94ab4699f
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/agents/auth-profiles/constants.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/inline-usage-kernel.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/inline-usage-publication.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/inline-usage.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/inline-usage.worker.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/runtime-snapshot-publication.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/sqlite-json.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/sqlite.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/store-mutation.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/store.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/usage-failure-state.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/usage.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.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 20, 2026
@clawsweeper

clawsweeper Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 20, 2026, 6:16 AM ET / 10:16 UTC (Revision 4).

ClawSweeper review

What this changes

Moves inline API-key failure recording and auth snapshot refreshes into SQLite workers while retaining existing cooldown rules and synchronous SDK store APIs.

Warning

SQLite table change

This PR modifies persisted SQLite tables in src/agents/auth-profiles/sqlite.ts. Prefer a design that avoids changing persisted SQLite tables. If the change is necessary, verify migration and upgrade compatibility against an existing database before merge.

Merge readiness

⛔ Blocked before merge - 1 item remains

This remains useful: current main still performs inline-key bookkeeping synchronously. No actionable introduced defect was found, and the updated compatibility evidence resolves the earlier storage concern.

Priority: P2
Reviewed head: 8b828b3a3325530744d584687d3045a94ab4699f

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A coherent internal refactor with meaningful lifecycle coverage, preserved storage contracts, and successful exact-head CI.
Proof confidence 🌊 off-meta tidepool Not applicable: The ordinary contributor-proof gate does not apply to this maintainer-authored refactor. Supplied evidence reports production retry-controller/SQLite runs and a physical Node-worker commit, rollback, and recovery sequence; inspected coverage checks owner revocation and unchanged durable credentials.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The ordinary contributor-proof gate does not apply to this maintainer-authored refactor. Supplied evidence reports production retry-controller/SQLite runs and a physical Node-worker commit, rollback, and recovery sequence; inspected coverage checks owner revocation and unchanged durable credentials.
Evidence reviewed 9 items Current-main necessity: The fetched main revision still records inline failures through updateAuthProfileStoreWithLock, whose transaction callback performs synchronous persistence. The proposed worker path remains distinct work.
Introduced worker behavior: The host captures the selected database owner before admission, uses the existing agent executor, and retains an acknowledged durable receipt through publication and cleanup failures. The worker requests transaction and commit admission and rereads canonical state.
Storage compatibility: The introduced delta leaves both SQL schemas, schema-version declarations, auth-state serializer, and persisted-store reader unchanged. Inspection of the extracted SQL writer confirms the same tables, keys, columns, and JSON representation; this is not a stored-data-model migration.
Findings None None.
Security None None.

How this fits together

The model retry controller records authentication and billing failures in the selected agent’s auth store. Persisted cooldown state then feeds runtime snapshots used for subsequent model selection.

flowchart TD
  A[Model authentication or billing failure] --> B[Retry controller]
  B --> C[Selected agent write admission]
  C --> D[SQLite worker transaction]
  D --> E[Persisted cooldown state]
  E --> F[Runtime snapshot publication]
  F --> G[Subsequent model selection]
Loading

Before merge

  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source +664, Tests +647, Docs +7, Other +2. Total +1320 across 23 files.

View PR surface stats
Area Files Added Removed Net
Source 13 1090 426 +664
Tests 7 678 31 +647
Docs 1 7 0 +7
Config 0 0 0 0
Generated 0 0 0 0
Other 2 3 1 +2
Total 23 1778 458 +1320

Review metrics

Metric Value Why it matters
Production versus validation growth Production/tooling net +666 lines; tests/test support net +647 lines Production growth implements worker admission, settlement, and snapshot publication while extracting shared logic; boundary tests cover those lifecycle contracts.
Persistent contract changes 0 schema, serializer, or public SDK API changes The adapter retains the existing persisted representation and public store contracts, resolving the prior migration concern.

Stored data model

Persistent data-model change detected: database schema: src/agents/auth-profiles/sqlite.ts, serialized state: src/agents/auth-profiles/inline-usage-kernel.ts, unknown-data-model-change: src/agents/auth-profiles/inline-usage-kernel.ts, unknown-data-model-change: src/agents/auth-profiles/sqlite.ts. Confirm migration or upgrade compatibility proof before merge.

Technical review

Best possible solution:

Keep failure recording under the existing agent database owner, sharing cooldown calculation and serialization while preserving committed outcomes through snapshot or cleanup failures.

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

Not applicable as a user-facing bug reproduction: this is an internal scheduling refactor, and current-main source confirms the synchronous path it replaces.

Is this the best way to solve the issue?

Yes. Reusing the existing agent executor and shared state reducers preserves one persistence owner without adding configuration, a parallel public API, or a new data format.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This is a bounded auth-bookkeeping scheduling improvement without evidence of an urgent user-facing outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The ordinary contributor-proof gate does not apply to this maintainer-authored refactor. Supplied evidence reports production retry-controller/SQLite runs and a physical Node-worker commit, rollback, and recovery sequence; inspected coverage checks owner revocation and unchanged durable credentials.

Evidence

What I checked:

  • Current-main necessity: The fetched main revision still records inline failures through updateAuthProfileStoreWithLock, whose transaction callback performs synchronous persistence. The proposed worker path remains distinct work. (src/agents/auth-profiles/usage.ts:1188, 2889a999b1eb)
  • Introduced worker behavior: The host captures the selected database owner before admission, uses the existing agent executor, and retains an acknowledged durable receipt through publication and cleanup failures. The worker requests transaction and commit admission and rereads canonical state. (src/agents/auth-profiles/inline-usage.ts:47, 8b828b3a3325)
  • Storage compatibility: The introduced delta leaves both SQL schemas, schema-version declarations, auth-state serializer, and persisted-store reader unchanged. Inspection of the extracted SQL writer confirms the same tables, keys, columns, and JSON representation; this is not a stored-data-model migration. (src/agents/auth-profiles/state.ts:117, 8b828b3a3325)
  • Controller and durable-state coverage: The inspected tests enter the production retry controller and check existing-format round trips across three owner layouts, unchanged credentials and sibling state, FIFO publication, rollback/recovery, empty-store initialization, and timeout non-writes. Additional cases close queued agent/root owners and verify rejection without durable mutation. (src/agents/embedded-agent-runner/run/failover-retry-controller.inline-auth.worker.test.ts:239, 8b828b3a3325)
  • Revocation and post-commit recovery: The remaining controller cases verify queued owner closure before mutation and committed-state preservation after closure with a throwing snapshot observer, including invalidation of inherited snapshots and a subsequent explicit recovery request. (src/agents/embedded-agent-runner/run/failover-retry-controller.inline-auth.worker.test.ts:404, 8b828b3a3325)
  • Prior review and supplied execution evidence: The supplied completed review at this same head contains no findings. The captured PR body addresses its storage concern and reports 24 passing runtime cases, neighboring coverage, and an emitted physical Node-worker commit/rollback/recovery sequence. These are contributor-reported results; this read-only review did not rerun them. (8b828b3a3325)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; 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 (3 earlier review cycles)
  • reviewed 2026-09-20T08:41:49.101Z sha f435858 :: blocked before merge. :: none
  • reviewed 2026-09-20T08:58:09.662Z sha db489e4 :: blocked before merge. :: none
  • reviewed 2026-09-20T09:52:22.442Z sha 8b828b3 :: needs maintainer review before merge. :: none

@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Sep 20, 2026
@steipete
steipete merged commit dbea406 into main Sep 20, 2026
225 checks passed
@steipete
steipete deleted the codex/auth-inline-failure-publish-20260920 branch September 20, 2026 10:48
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 21, 2026
…w#153570)

* refactor: record inline API-key failures off the main thread

* refactor: keep shared auth SQLite builder internal

* fix: preserve inline auth worker settlement and validation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts security-sensitive-changed size: XL 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