Skip to content

perf(auth): reuse persisted rows across session writes - #169749

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-micro-auth-profile-rows-immutable-visit-20260919
Oct 12, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-micro-auth-profile-rows-immutable-visit-20260919

Conversation

@steipete

@steipete steipete commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Repeated model-auth reads reload and deeply freeze unchanged persisted credentials after unrelated session writes to the same SQLite database.

User Impact

Reduces allocation and repeated credential reads during active chat sessions. Credential changes, runtime publications, database replacement, and reader revocation retain their existing invalidation and authority checks. No schema, config, migration, or update behavior changes.

Why This Change Was Made

The rows cache currently keys reuse on the whole-database write token. Use the existing scoped-receipt owner instead: session-only writes no longer invalidate auth rows, while auth writes and all unclassified writes still invalidate through its unscoped revision. Freeze still occurs once when a new row revision is loaded; no second cache or alternate freeze path is introduced.

The source audit found that production scoped writers are session owners. Auth writes remain unscoped. Production LOC is +4 (7 added / 3 removed), entirely the scoped-token argument, its formatting, and the ownership comment. Retaining invalidation for unknown writes and schema/physical-generation changes requires the existing scoped receipt; dropping the write check in favor of auth publications alone would not preserve that contract. There is no new state owner, cache, branch, or helper.

Evidence

The corrected 20-session allocation profile attributed 7.122 GiB to property descriptors and 5.871 GiB to immutable traversal from auth-row cache admission: 12.993 GiB / 5.87% of sampled main-thread allocation.

A synthetic Linux benchmark uses the real row reader and cache with 64 credential profiles and 3,000 reads interleaved with certified session writes. Each timing run has 100 warmups; allocation is sampled separately at 1 KiB including collected objects. The auth-read timing excludes the preceding SQLite write; total iteration time includes it.

Measurement Before After
Auth read 426.6 µs 23.8 µs (18× faster)
Full write/read iteration 2,061 µs 1,576 µs
Auth SQL reloads, after warmup 3,000 0
Gross sampled allocation 713.3 MB 20.4 MB (97.1% lower)
Freeze-subtree allocation 384.8 MB (53.95%) 0 sampled bytes

Measurement host: isolated Linux rig, Node 26.8.1, source ac5432479226a46259c303ad3a8907fc8ad310fe plus this change. Command: nice -n 10 ionice -c3 node --import ./scripts/tsx.mjs .rig/bench.mts baseline and the same command with candidate. The fixture uses real SQLite writes, the production receipt mechanism, readAuthProfileRows, and createRuntimeAuthProfileRowsCache. These are focused measurements, not a full-Gateway throughput claim.

The new worker-receipt regression fails on the unchanged implementation at the row-identity assertion and passes with the fix. pnpm test src/agents/auth-profiles/runtime-persisted-rows.test.ts --maxWorkers=1: 4 tests passed; 1.18 s test bodies, 96.58 s wrapper wall time (mostly worker-artifact preparation). Changed-file oxfmt passed. Focused repository lint passed on both changed TypeScript files (runOxlint with config/tsconfig/oxlint.core.json). Independent Codex autoreview returned scoped-clean with no actionable P0–P2 findings. PR CI owns full gates. No Testbox or Crabbox lease was allocated. The Linux rig is used only for measurement; no Team or live user data was accessed. Full-workload allocation share after this change has not been measured.

CI disposition

CI run 38222430842 stopped on the inherited type-suppression-inventory.test.ts ratchet failure: scripts/lib/managed-cleanup-handoff.mts adds a Bun @ts-expect-error, yielding 19 entries versus 18 expected. The failing test and its subjects are unchanged between the tested main baseline 76f4fdd41acf06621fe5b4605f67816f63a7f698 and CI merge 3f952a215d8fef42f550062dfe581c70cb277aa2. The same assertion reproduces on unmodified main ccb7b5f7e5de8e0e6c3bd20030c902d2134e9a15 using pnpm test test/scripts/type-suppression-inventory.test.ts --maxWorkers=1 (10.51s).

The successful fail-fast monitor cancelled 27 remaining jobs; those are unrun coverage, not additional source failures. The aggregate gate reports the originating inventory failure. No rerun or re-push was requested. Closest sibling proof passed: runtime-snapshots.test.ts and runtime-snapshot-publication.test.ts, 22 tests / 29.82s wrapper. Together with the changed-file proof, 26 focused auth tests pass. Landing uses the authorized inherited-failure exception.

Use scoped SQLite receipts so certified session-only writes retain the existing immutable auth row revision. Auth and unclassified writes, schema changes, publication revisions, physical generations, and live reader authority still fence reuse. Avoid repeated credential reads and freezing during chat turns.
@clawsweeper

clawsweeper Bot commented Oct 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 docs Improvements or additions to documentation agents Agent runtime and tooling size: XS labels Oct 12, 2026
@github-actions

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: cb4d39e2b734fa54fa5c4244120ea52abc4ad474
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/agents/auth-profiles/runtime-persisted-rows.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: 🦐 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. labels Oct 12, 2026
@clawsweeper

clawsweeper Bot commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR preserves cached immutable auth rows across certified session-only database writes.

Example: The supplied benchmark reads 64 credential profiles 3,000 times between certified session writes.

  • Before: After warmup, auth rows reload 3,000 times.
  • After: After warmup, auth rows reload zero times.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused patch appears correct and worthwhile; the inspected evidence establishes the cache mechanism rather than shipped end-to-end performance.
Proof confidence 🦐 gold shrimp (3/6) The ordinary contributor proof gate does not apply to this maintainer-authored PR; its Linux benchmark exercises the real row reader, SQLite writes, receipts, and cache, without claiming a shipped Gateway run.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Active chat sessions repeatedly reload and freeze unchanged credentials after unrelated session writes.
Reason: The maintainer-authored direction addresses measured allocation cost through a small change to the existing owner, without new configuration or public behavior.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it is maintainer-authored and provides a focused performance improvement still absent from current main; source review found no actionable introduced defect.

Priority: P2
Reviewed head: cb4d39e2b734fa54fa5c4244120ea52abc4ad474

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied fixture demonstrates cache-boundary savings, but no shipped Gateway run demonstrates the improvement across real chat-session writes.
Agent review details

How this fits together

Model-auth preparation reads persisted credential and health rows through a bounded runtime cache, then applies request-specific composition and live reader authority checks.

flowchart TD
  A[Model auth preparation] --> B[Live reader authority]
  B --> C[Runtime auth rows cache]
  D[SQLite scoped receipts] --> C
  E[Auth publication revisions] --> C
  C --> F[Persisted row reader]
  C --> G[Request auth composition]
Loading

Technical review

Best possible solution:

Use the existing scoped receipt owner to preserve immutable auth rows across session writes while retaining all auth invalidation and reader authority checks.

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

Current main keys reuse on the whole-database write token, establishing why a committed session write forces another auth-row read; the PR reports a baseline-failing regression, which was inspected but not executed during this read-only review.

Is this the best way to solve the issue?

The patch changes both token checks together and consumes the existing scoped receipt mechanism without adding another cache, state owner, or persistence contract.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Auth-row cache invalidation changes intended behavior with a stated reason (1d76f57: The physical admission owner replaced repeated SQLite freshness queries with in-process committed write receipts.)
  • Documented cache freshness contract keeps the original intent (perf(auth): avoid per-turn auth reader spawns on Gateways #152266: Bounded persisted-row reuse reduced worker startup and IPC while preserving publication invalidation and request-owned authority.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit d3d2d2e adds src/agents/auth-profiles/runtime-persisted-rows.ts:22 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: d3d2d2ea3b47; files: src/agents/auth-profiles/runtime-persisted-rows.ts)

PR surface

Source +4, Tests +11, Docs 0. Total +15 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 7 3 +4
Tests 1 12 1 +11
Docs 1 7 7 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 26 11 +15

Labels

Label changes:

  • add P2: A measured allocation and credential-read improvement during active sessions, with limited scope and no demonstrated urgent user-facing failure.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: A measured allocation and credential-read improvement during active sessions, with limited scope and no demonstrated urgent user-facing failure.
  • 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 12, 2026, 4:20 AM ET / 08:20 UTC.

@steipete

Copy link
Copy Markdown
Contributor Author

Landing under the authorized inherited-failure exception. The sole root failure is the suppression inventory assertion: the pre-existing Bun assertion in scripts/lib/managed-cleanup-handoff.mts adds entry 19 to an expected list of 18. It reproduces on untouched main ccb7b5f7e5de8e0e6c3bd20030c902d2134e9a15 with pnpm test test/scripts/type-suppression-inventory.test.ts --maxWorkers=1 (10.51s). Failing sources are identical between CI's baseline 76f4fdd41acf06621fe5b4605f67816f63a7f698 and merge 3f952a215d8fef42f550062dfe581c70cb277aa2.

The fail-fast monitor cancelled 27 collateral jobs; cancelled coverage remains unrun. The aggregate gate names that originating failure. Changed-file checks and 26 focused auth tests pass, including both nearest runtime snapshot test files; independent review is clean. No CI rerun, dispatch, or re-push was used to chase green.

@steipete
steipete merged commit c5fffa2 into main Oct 12, 2026
103 of 134 checks passed
@steipete
steipete deleted the steipete/perf-micro-auth-profile-rows-immutable-visit-20260919 branch October 12, 2026 08:24
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 13, 2026
Use scoped SQLite receipts so certified session-only writes retain the existing immutable auth row revision. Auth and unclassified writes, schema changes, publication revisions, physical generations, and live reader authority still fence reuse. Avoid repeated credential reads and freezing during chat turns.
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: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. security-sensitive-changed size: XS 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