Skip to content

refactor(auth-profiles): record personal model-account usage in workers - #164240

Merged
steipete merged 1 commit into
mainfrom
dbasync/acctusage
Oct 3, 2026
Merged

steipete merged 1 commit into
mainfrom
dbasync/acctusage

Conversation

@steipete

@steipete steipete commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Personal model-account success and failover-failure bookkeeping performed native SQLite work before its nominally background promise yielded, keeping per-run accounting on the Gateway thread.

Why This Change Was Made

Route typed success/failure reductions through the existing authProfiles shared-state worker. Capture the physical store before yielding, reread authoritative usage in the same synchronous transaction, refuse changed credentials, recheck host authority at transaction and commit, and publish only acknowledged usage to the selected turn. Post-run success remains nonblocking; maintenance close joins accepted work.

Host and worker share the existing usage reducers. Provider probing stays outside the transaction, with credential and block-generation checks preserved. The auth scope state moves to a small sibling module so the isolated-scope guard has one owner without growing the already oversized store module.

User Impact

Credential bytes, shared rotation, schema, retention, durability, and update behavior are unchanged. Connect/disconnect, OAuth refresh, selection, and private GitHub stores remain outside this change. The synchronous updater remains for the released v2026.9.8 SDK callback contract and excluded credential/selection flows; success/failure bookkeeping no longer reaches that path.

Coordination with #125573: state.ts, types.ts, and usage-state.ts are untouched. Its probe-result type and applyWhamCooldownResult changes belong in the extracted usage-reduction.ts; parsing stays in usage.ts. A mechanical relocation conflict in usage.ts is expected when rebasing that older draft, but both host and worker will consume the same changed reducer without a second worker implementation. Current main already shares persisted normalization through coerceProfileUsageStats. Adjacent #107671 extracts the untouched owner-write helper; #143744 changes shared OAuth routing; #163350 extracts store-save code; #162398 changes retry selection. Those semantics are unchanged here.

Evidence

  • Real embedded success hook plus retry-controller failure: 40 caller-thread SQL observations before → 0 after. Tests also prove concurrent reductions survive, stale credentials and authoritative probe generations are refused without overwriting current usage, close joins accepted bookkeeping, and authority error identity survives.
  • Focused usage, inherited-account, released-SDK compatibility, worker-error, and boundary suites: 140 tests passed, 412.88 s wall, with --maxWorkers=1.
  • New boundary file alone: 7 tests passed, 194.27 s wall, including compiled-worker preparation. After the final scope extraction, the boundary and inherited-account suites passed again: 15 tests, 245.28 s wall. The new file's cases took 30.51 s in that loaded-host run; real worker transactions and lifecycle settlement are the contracts under test and cannot be established by reducer mocks. CI timing is pending.
  • Released SDK checked against v2026.9.8; the existing compatibility suite passed all 5 cases. Landing inspection reconfirmed that updateUserModelAuthProfile is internal, the public success/failure signatures are unchanged, and provider-auth-write-compat.ts plus its type/behavior tests remain byte-identical to the release. No new compatibility record is required.
  • T1 inventory: 1,303 → 1,303. The three account-store primitives remain classified T1 because excluded callers still share them; the moved flow is proven by the runtime SQL counter.
  • Production LOC: +419 / −239 / net +180 (658 changed). Zero new OPENCLAW_* names.
  • Database-worker ratchet passed against merge base f1c2314964b7504df8f2686e996559e71de4bf7a; Madge reported 0 cycles. The new modules are outside the compiled PR-wrapper dependency closure.
  • Codex autoreview through P2: scoped-clean.
  • node scripts/check-changed.mjs --base f1c2314964b7504df8f2686e996559e71de4bf7a: passed, 2,679.04 s wall. Core and test typechecks, lint, and policy guards passed; the untouched Doctor registry retains an existing max-lines warning.

No live provider request was made; provider probe races use synthetic responses with real account storage and workers.

Move personal run-success and failover-failure reductions to the existing authProfiles worker. Reread usage under the writer transaction, preserve credential and probe generations, and join accepted maintenance work. Keep shared reducers and released SDK updater compatibility.
@clawsweeper

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

@github-actions

github-actions Bot commented Oct 3, 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: 9b8f7482bbdf7a158cd86d828a2702059f68ace8
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/agents/auth-profiles/personal-usage.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/profiles.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/runtime-scope.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/store.worker.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/usage-reduction.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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: XL labels Oct 3, 2026
@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 Oct 3, 2026
@clawsweeper

clawsweeper Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 3, 2026, 6:18 AM ET / 10:18 UTC (Revision 2).

ClawSweeper review

What this changes

Moves personal model-account success and failure bookkeeping into OpenClaw’s existing database worker while sharing cooldown calculations and preserving credential ownership.

Merge readiness

✅ Ready for maintainer review

This remains useful: current main still performs personal-account bookkeeping through the synchronous writer, and the related PRs address different behavior. No actionable introduced defect was found; maintainer-authored work also remains protected from automatic closure.

Priority: P2
Reviewed head: 9b8f7482bbdf7a158cd86d828a2702059f68ace8

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, maintainable refactor with meaningful boundary coverage, preserved compatibility, and no blocking finding.
Proof confidence 🌊 off-meta tidepool Not applicable: The ordinary external-contributor proof gate does not apply to this maintainer-authored PR. Reported production-hook tests use real account storage and workers to show zero caller-thread SQL, stale-state refusal, and close settlement; provider responses are synthetic. Source inspection found no unresolved authority-chain violation requiring an additional proof gate, and no stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The ordinary external-contributor proof gate does not apply to this maintainer-authored PR. Reported production-hook tests use real account storage and workers to show zero caller-thread SQL, stale-state refusal, and close settlement; provider responses are synthetic. Source inspection found no unresolved authority-chain violation requiring an additional proof gate, and no stored-data contract changes.
Evidence reviewed 9 items Pinned introduction: Reviewed the merge-base-to-head introduced hunks at the recorded original head. The changes stay within personal usage accounting, shared reducers, runtime scope extraction, documentation, and focused worker coverage.
Current-main necessity: Fetched main still routes personal success through updateAuthProfileStoreWithLock and has only personal-account read operations in its auth worker table; it lacks the introduced personalUsage worker operation.
Captured authority and publication: The host captures its physical database context before yielding, retains maintenance and isolated-scope checks, uses the existing transaction/commit admission factory, and publishes returned usage only when the caller credential still matches.
Findings None None.
Security None None.

How this fits together

Agent runs report credential success or failure to auth-profile accounting. That accounting updates the selected personal account’s usage in shared SQLite storage and returns committed usage to the active turn.

flowchart TD
  A[Agent success or failure] --> B[Capture selected account and store]
  B --> C[Existing database worker]
  C --> D[Check authority and credential generation]
  D --> E[Reduce current usage and commit]
  E --> F[Publish acknowledged usage to turn]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +180, Tests +346, Docs +12. Total +538 across 11 files.

View PR surface stats
Area Files Added Removed Net
Source 8 419 239 +180
Tests 2 346 0 +346
Docs 1 12 0 +12
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 11 777 239 +538

Review metrics

Metric Value Why it matters
Production versus test growth Production +419/-239, net +180; tests +345; test routing +1 Production growth is justified by typed worker reductions and authority-preserving dispatch, with shared calculations extracted rather than duplicated.

Technical review

Best possible solution:

Keep personal usage reductions on the canonical worker with live commit admission, shared reducers, and unchanged released SDK callback behavior.

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

Yes, source establishes that the existing personal-account path enters synchronous SQLite work before its background promise yields. The PR reports a focused before/after SQL counter; this read-only review did not execute it.

Is this the best way to solve the issue?

Yes, the patch reuses the existing worker, transaction owner, and usage calculations while retaining the released callback path for its separate compatibility contract.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded runtime responsiveness 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 external-contributor proof gate does not apply to this maintainer-authored PR. Reported production-hook tests use real account storage and workers to show zero caller-thread SQL, stale-state refusal, and close settlement; provider responses are synthetic. Source inspection found no unresolved authority-chain violation requiring an additional proof gate, and no stored-data contract changes.

Evidence

What I checked:

  • Pinned introduction: Reviewed the merge-base-to-head introduced hunks at the recorded original head. The changes stay within personal usage accounting, shared reducers, runtime scope extraction, documentation, and focused worker coverage. (9b8f7482bbdf)
  • Current-main necessity: Fetched main still routes personal success through updateAuthProfileStoreWithLock and has only personal-account read operations in its auth worker table; it lacks the introduced personalUsage worker operation. (src/agents/auth-profiles/store.worker.ts:12, 260a31989937)
  • Captured authority and publication: The host captures its physical database context before yielding, retains maintenance and isolated-scope checks, uses the existing transaction/commit admission factory, and publishes returned usage only when the caller credential still matches. (src/agents/auth-profiles/personal-usage.ts:12, 9b8f7482bbdf)
  • Canonical writer and unchanged storage format: The worker rereads the current account inside updateUserModelAuthProfile, refuses changed credentials, and changes only usageStats through the existing serializer. Added admission callbacks run at transaction entry and before commit; no schema, credential format, selection, or retention change is introduced. (src/agents/auth-profiles/store.worker.ts:29, 9b8f7482bbdf)
  • Boundary coverage and reported execution: Read all seven new cases: production success/failure entrypoints with real account storage and workers, caller-thread SQL detection, stale probe and credential controls, close settlement, and revoked queued work. The captured PR body reports 140 focused tests passing and 40 before versus zero after caller-thread SQL observations. Provider fetch responses are synthetic; this reviewer executed no tests. (src/agents/embedded-agent-runner/run/auth-profile-personal-usage.worker.test.ts:119, 9b8f7482bbdf)
  • Revocation control: The queued-work control revokes the captured maintenance owner before dispatch resumes, then checks rejection identity and unchanged durable account and caller state. Source additionally retains transaction and commit grants through the existing broker. (src/agents/embedded-agent-runner/run/auth-profile-personal-usage.worker.test.ts:306, 9b8f7482bbdf)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • stevenlee-oai: 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 (1 earlier review cycle)
  • reviewed 2026-10-03T10:08:12.179Z sha 9b8f748 :: needs maintainer review before merge. :: none

@steipete
steipete merged commit 662bfff into main Oct 3, 2026
153 of 155 checks passed
@steipete
steipete deleted the dbasync/acctusage branch October 3, 2026 11:06
@steipete

steipete commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 4, 2026
…rs (openclaw#164240)

Move personal run-success and failover-failure reductions to the existing authProfiles worker. Reread usage under the writer transaction, preserve credential and probe generations, and join accepted maintenance work. Keep shared reducers and released SDK updater compatibility.
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 P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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