Skip to content

perf(models): prepare personal model pin authority through workers - #165547

Merged
steipete merged 2 commits into
mainfrom
dbasync/w4modelpin
Oct 5, 2026
Merged

steipete merged 2 commits into
mainfrom
dbasync/w4modelpin

Conversation

@steipete

@steipete steipete commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Selecting a personal model account queried SQLite on the Gateway thread, and retained selection guards repeated the ownership query after awaited work.

Why This Change Was Made

Prepare ownership through the existing shared-state account reader, anchored to the profile owner's identity revision before the read. Directive selection, explicit Gateway selection, and session-default preparation retain that same live authority for their final checks. Remove the superseded synchronous ownership facade.

User Impact

Personal model selection no longer runs caller-thread SQL for ownership preparation or retained pin validation. Default-account changes preserve explicit pins; identity transfer and database retirement revoke them. Schemas, credential storage, permissions, RPC shapes, and released SDK signatures are unchanged. No new OPENCLAW_* names are added. OAuth settlement is a separate follow-up.

Evidence

  • Pin-only production diff: +95/-76, net +19 (171 changed lines).
  • Real directive entry measurement: preparation 14 → 0 caller-thread SQL interception calls; retained validation 5 → 0. These counts include SQL preparation and execution interception, not unique statements.
  • T1 against merge base e78e965a55e2: 883 → 882 overall; the four scoped runtime sites become three. Administrative SDK kernels retain their separate classification.
  • Main focused/import batch: 322 tests in 12 files passed with --maxWorkers=1; 2,869.70 s total wall time on the loaded local host. Includes runtime-process build graph, reply/shared-worker import closure, and the real pin measurement.
  • Madge: zero cycles (154.06 s wall). Database-worker ratchet passed. P2 Codex autoreview with ultrafast service: scoped-clean, no actionable findings.
  • Additional indirect models-session / sessions-title suites: 57 tests passed with --maxWorkers=1, 738.03 s wall.
  • node scripts/check-changed.mjs ran for 2,217.13 s and stopped on two base-present Knip findings: GoogleMeetJoinResult in extensions/google-meet/src/transports/types.ts and MeetingRuntimeOwner in src/meeting-bot/runtime-facade-types.ts. Their complete declaration/reference sets and scanner configuration match the pinned base; neither domain is changed here. Core and all 27 core-test type graphs passed. All nine remaining planned checks passed when run directly after that early exit (1231.90 s combined wall time). The unused-export failure remains recorded; no ignore or baseline exception was added.
  • SDK API comparison against the pinned merge base: no entrypoint or export changes; acknowledgement enforcement passed with no exception (1,924.08 s wall, including temporary checkout cleanup).
  • The worker-boundary suite took 85.813 s of test time on this host. It uses real worker transport and canonical transactions to prove thread placement, identity revocation, foreign-read freshness, and lost-reply behavior; mocked helper coverage cannot establish those contracts. CI timings are pending.
  • Worker test routing audited through indirect callers. Worker-reaching Gateway suites and agents-support already run in fork-owned projects; no routing exception is needed.

Existing role-policy cache misses can still read the separate profile-role owner at src/gateway/operator-role-policy.ts:48, reached by the retained Gateway authority guard at src/gateway/server-methods/users-model-account-access.ts:108. This pre-existing path is outside the moved account ownership operation.

Overlap: #162433 is the existing umbrella ownership draft; this change keeps focused account-selection hunks and does not adopt its redesign. #165288 also touches session-create-service.ts for unrelated cleanup; these hunks stay limited to account authority. The landed #165360 updates separate create-target hunks on main.

Landing audit: compared the changed signatures and removed ownership facade against v2026.9.8. They are internal-only, with no SDK barrel, documented subpath, or api.runtime export. The released modelAccountConnectService methods and Promise-returning createSessionEntry facade are unchanged; no compatibility shim is needed.

Initial CI at e53b2d21f39d8a573a74b7077122945123b6dd90 had one root failure: the Madge guard. The identical 17-module cycle failed independently in scheduled main architecture at the exact CI baseline 78e406060b56bac2d09810161ac7b483861e9879; every cycle module is outside this PR's changes. The aggregate CI gate fails downstream. Selected build, test, type, lint, and security jobs passed. Main subsequently fixed that cycle in 21901766c534; merge commit f554d535571f integrates the fix without rebasing. The new head receives fresh CI; the prior failure is not relabeled as passing.

ClawSweeper completed its review of f554d535571f at 2026-10-05 13:27 UTC with no actionable findings. Current-head CI passed with no failed or cancelled CI jobs.

Post-integration evidence for f554d535571f:

  • Core production types passed in 73.71 s; all 27 core-test type graphs passed in 1,307.25 s. Madge reports zero cycles (341.80 s).
  • The five focused worker/import files passed all 27 tests with --maxWorkers=1 in 612.00 s. The original 379-test proof remains applicable to the unchanged pin production patch.
  • Main’s cycle repair extracted a runtime schema module but omitted it from the compiled PR wrapper inventory. Added the one missing inventory entry. The exact inventory regression failed before the entry (33.45 s) and passed after it (29.29 s).
  • Fresh P2 Codex autoreview of the complete integrated candidate, including the inventory entry, is scoped-clean.
  • The original SDK report retains its e78e965a55e2 → e53b2d21 binding. A fresh integration audit verified identical production patches, unchanged relevant public contracts, and no new SDK reachability for the changed private functions. It is reused evidence, not a relabeled exact-head rerender.
  • Initial CI’s 13 selected Node jobs consumed 2,775 aggregate runner seconds; this is total selected-job cost, not the marginal cost of added tests. Current-head CI is green.

The operator-requested published-driver update cell passed on isolated Linux state: published 2026.9.8 updated to candidate commit f554d535571f8e52124a6039cb2977afa77208ba. The actual updater exited 0 in 361.706 s, the durable update phase was finished, readiness returned 200, and the running build ID matched the candidate. Durable and incognito session after-checks and service shutdown all passed. Full candidate build, tarball integrity, and packaged import-graph checks passed beforehand. Candidate SHA-256: b8321aa7c0a95faea5352eb88a973cdb24953cdb5594d24bb32b26a1b325a35f. This is separate proof because ordinary PR CI does not run that cell.

Prepare exact account ownership through the existing shared-state reader and retain profile identity authority across awaited selection. Final pin checks consume live owner-held revisions without SQLite; default-link changes preserve explicit pins while identity transfer and store retirement revoke them.
@clawsweeper

clawsweeper Bot commented Oct 5, 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 gateway Gateway runtime size: M labels Oct 5, 2026
@steipete

steipete commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@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 5, 2026
@clawsweeper

clawsweeper Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 5, 2026, 9:27 AM ET / 13:27 UTC (Revision 3).

ClawSweeper review

What this changes

The PR moves personal model-account ownership preparation to the existing database worker and retains live identity checks when committing session selections.

Merge readiness

✅ Ready for maintainer review

The PR remains useful: current main still performs synchronous account-ownership reads. The introduced cutover preserves final authorization checks, and no actionable patch defect was found.

Priority: P2
Reviewed head: f554d535571f8e52124a6039cb2977afa77208ba

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, maintainable cutover with meaningful boundary coverage and no actionable introduced defect.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied Repository State identifies a MEMBER author, so ordinary external-contributor proof is exempt. The changed worker preparation and final authorization composition were inspected alongside real-worker boundary coverage; no unresolved authority-chain violation requires additional final-effect proof. No tests or runtime probes were executed by this reviewer.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied Repository State identifies a MEMBER author, so ordinary external-contributor proof is exempt. The changed worker preparation and final authorization composition were inspected alongside real-worker boundary coverage; no unresolved authority-chain violation requires additional final-effect proof. No tests or runtime probes were executed by this reviewer.
Evidence reviewed 8 items Pinned introduced change: Reviewed the merge-base-to-head delta at the supplied identities. The checkout is the original PR head; the supplied stale test merge was not used to infer removal of current-main behavior. Final git status remained clean.
Worker preparation and retained authority: Account preparation captures the identity owner's revision before awaiting the existing summary read, binds both requester and account-locator identities, and returns an owner-held currentness check. The existing identity owner rejects pending or uncertain mutations and retired database admission.
Final-effect authorization composition: Gateway selections retain connection, scope, role, and account checks together. Directive persistence passes the retained account validator into the synchronous commit guard; session-default preparation likewise carries its validator through runtime preparation and creation commit.
Findings None None.
Security None None.

How this fits together

Personal model accounts let signed-in users select their own provider credentials for a session. Chat directives and Gateway requests prepare account ownership, then session writers recheck that authority before saving the selection.

flowchart TD
  A[Chat model directive] --> C[Account selection preparation]
  B[Gateway model request] --> C
  C --> D[Shared-state database worker]
  D --> E[Live identity authority]
  E --> F{Authority still current}
  F -->|Yes| G[Save session selection]
  F -->|No| H[Reject selection]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +19, Tests +101, Docs +3, Other +1. Total +124 across 16 files.

View PR surface stats
Area Files Added Removed Net
Source 9 95 76 +19
Tests 5 169 68 +101
Docs 1 5 2 +3
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 0 +1
Total 16 270 146 +124

Review metrics

None.

Technical review

Best possible solution:

Use the existing worker reader and identity owner for account preparation while preserving synchronous final commit checks and established session-pin semantics.

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

Yes, source establishes the synchronous ownership-read path on current main; the PR also reports before/after SQL interception measurements. This read-only review did not execute the path.

Is this the best way to solve the issue?

Yes, reusing the existing account worker and identity authority is a focused cutover, and the final persistence guards continue to consume live authorization.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded runtime performance improvement that preserves existing account-selection behavior.
  • 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 supplied Repository State identifies a MEMBER author, so ordinary external-contributor proof is exempt. The changed worker preparation and final authorization composition were inspected alongside real-worker boundary coverage; no unresolved authority-chain violation requires additional final-effect proof. No tests or runtime probes were executed by this reviewer.

Evidence

What I checked:

  • Pinned introduced change: Reviewed the merge-base-to-head delta at the supplied identities. The checkout is the original PR head; the supplied stale test merge was not used to infer removal of current-main behavior. Final git status remained clean. (f554d535571f)
  • Worker preparation and retained authority: Account preparation captures the identity owner's revision before awaiting the existing summary read, binds both requester and account-locator identities, and returns an owner-held currentness check. The existing identity owner rejects pending or uncertain mutations and retired database admission. (src/state/user-model-account-operations.ts:186, f554d535571f)
  • Final-effect authorization composition: Gateway selections retain connection, scope, role, and account checks together. Directive persistence passes the retained account validator into the synchronous commit guard; session-default preparation likewise carries its validator through runtime preparation and creation commit. (src/gateway/server-methods/users-model-account-access.ts:131, f554d535571f)
  • Focused boundary coverage: The added cases use real database workers to check foreign-commit freshness, zero caller-thread account SQL, rejection of another profile, preservation after default unlinking, and revocation after identity transfer, including transfer while an account read is awaited. Existing session-patch coverage checks forbidden callers and unchanged stored rows after connection or role revocation. These tests were inspected, not executed during this review. (src/gateway/model-account-connect.worker.test.ts:70, f554d535571f)
  • Still necessary on current main: Fetched main lacks the new account-authority preparation operation and retains synchronous ownership preparation. The related merged session-creation and cleanup PRs address different responsibilities, so they do not supersede this cutover. (src/state/user-model-account-operations.ts, b2dfd4e9dc58)
  • Compatibility and update scope: The introduced hunks change runtime read preparation and retained checks, without changing stored records, schemas, RPC shapes, or released service signatures. The PR body reports a released-surface audit. A published-driver update cell is not applicable to this runtime read cutover; the body’s earlier request does not establish a changed updater or migration contract. Public docs: docs/reference/database-schemas/worker-access.md. (docs/reference/database-schemas/worker-access.md:1306, f554d535571f)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • scoootscooob: 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-10-05T11:43:31.392Z sha e53b2d2 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-05T11:56:40.514Z sha e53b2d2 :: needs maintainer review before merge. :: none

Merge main without rebasing the personal model pin authority branch.
Keep the reviewed ownership cutover unchanged and include the extracted
deferred migration schema contract in the compiled PR wrapper inventory.
The inventory regression failed before that entry and passes afterward.

Validation: core and all 27 core-test type graphs, Madge (zero cycles),
27 focused worker/import tests, wrapper inventory regression, and clean
P2 autoreview of the integrated candidate. The original SDK report is
reused with a fresh reachability audit; the production patch is unchanged.
@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Oct 5, 2026
@steipete
steipete merged commit 41a5e83 into main Oct 5, 2026
138 checks passed
@steipete
steipete deleted the dbasync/w4modelpin branch October 5, 2026 14:09
@steipete

steipete commented Oct 5, 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 6, 2026
…penclaw#165547)

Prepare exact account ownership through the existing shared-state reader and retain profile identity authority across awaited selection. Final pin checks consume live owner-held revisions without SQLite; default-link changes preserve explicit pins while identity transfer and store retirement revoke them.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: M 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