Skip to content

improve(boards): avoid duplicate target reads in cross-store writes - #170318

Merged
steipete merged 1 commit into
mainfrom
dbasync/boardcut
Oct 12, 2026
Merged

steipete merged 1 commit into
mainfrom
dbasync/boardcut

Conversation

@steipete

@steipete steipete commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Cross-store Board mutations read the target session twice in the same synchronous transaction: once to validate its captured identity and again in the mutation kernel to check existence.

User Impact

Board writes keep the same behavior while issuing one fewer target-session SELECT per cross-store putWidget, applyOps, or grant. There are no schema, SDK, update, or operator configuration changes.

Why This Change Was Made

Pass the already captured target identity into the kernel's existing validation and delete the outer duplicate read. The kernel checks both identity and existence before changing Board rows.

This is a bounded improvement, not the full Board worker cutover. The remaining cross-physical source path is a real permission boundary: readSessionSourceValidation rejects a source identity from another physical database, and host admission currently cannot preserve foreign-source authority through the target worker's commit. Moving the check before dispatch would permit a revoked source to authorize a later write. Keep the existing native path until the shared final-authority owner supplies that contract. This is the same limitation recorded in #169631.

Removed check and accepted edge case: the outer target-session identity read is removed; the kernel validates the same captured session ID and lifecycle revision in the same transaction, so no additional stale-target edge is accepted. Existing source-permission checks stay intact.

Evidence

Cross-store operation Target-session SELECTs before After Requests delta
putWidget 2 1 0
applyOps 2 1 0
grant 2 1 0

The baseline follows the two calls to hasBoardSession; the regression counts executed target-database statements, including prepared-statement reuse. Source and target fixtures use different physical databases. The target-replacement regression now covers both ordinary worker writes and the cross-store native path; the existing source-permission revocation check remains covered.

No warmed-turn harness pair: the changed path is cross-store Board mutation, not the shared harness's chat-turn path. No changes to worker routing, caches, invalidation, or shared read families. Warmed all-thread statements/requests and MAIN are not measured or claimed by this PR.

T1 primitive inventory: 12 → 12 in src/boards (9 kernel calls + 3 store calls); the lane-specific Board publication/source-authority subset remains 8 → 8, with 4 native-incognito read sites. A fresh full inventory captured the baseline; this patch leaves every primitive call and classification unchanged. The retained cross-store path is intentionally not reclassified or hidden.

Validation: local formatting, basic lint, and git diff --check passed. PR CI run 38315255980 passed all selected Node test shards, production/test types, lint, source contracts, Madge, and the database ratchets. The slowest selected Node shard took 306 seconds including setup. No local test suite was run under the relaxed testing rules. Ordinary PR CI skips Knip, so the required pnpm deadcode:exports scan ran through the campaign CPU slot: production, full-tree, and script export scans all passed with zero entries. Codex autoreview: scoped-clean at P0/P1 (one round).

LOC: production +20/-15, tests +89/-37, docs +3/-1. Test growth extends existing fixtures instead of adding another test harness.

Pass the captured target identity into the mutation kernel so native cross-store Board writes validate it once. Preserve source-permission guards and the native exception pending the shared final-authority contract.
@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 size: S labels Oct 12, 2026
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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 removes a duplicate target-session read from cross-store Board mutations by passing the captured identity into the existing mutation kernels.

Example: Source session agent:source:authority writes widget permitted into agent:main:board in another physical database.

  • Before: The native transaction reads the target session twice before completing the mutation.
  • After: The kernel reads the target session once, checking both existence and captured identity before writing.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The patch is focused and source-consistent, with meaningful production-owner coverage; available behavior evidence remains harness-based.
Proof confidence 🦐 gold shrimp (3/6) Ordinary contributor proof gating does not apply to this maintainer-authored PR; inspected evidence is the real-database test harness, and the patch relocates equivalent validation without changing which principals may write.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Cross-store Board writes perform an unnecessary target-session SELECT for every mutation.
Reason: The maintainer-directed change removes evidenced redundant work through existing validation contracts and preserves the documented native authority exception.

Merge readiness

✅ Ready for maintainer review

Keep open: this PR provides a focused, maintainer-directed optimization that current main still needs, with no concrete introduced defect found.

Priority: P3
Reviewed head: 57162bda21140099da0e2c011bebd8fd783a42e2

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: No compiled-store or Gateway trace is supplied, and an executed baseline-versus-head run of the new read-count assertion is not shown.
Agent review details

How this fits together

The Board store accepts widget, layout, and grant mutations, prepares session authority, and routes writes through worker or native transactions that persist Board rows and publish session changes.

flowchart TD
A[Board mutation caller] --> B[Session and source preparation]
B --> C[Write admission]
C --> D[Ordinary worker transaction]
C --> E[Cross-store native transaction]
D --> F[Mutation kernel and identity check]
E --> F
F --> G[Board rows and change publication]
Loading

Technical review

Best possible solution:

Consolidate target validation in the existing kernels while retaining the synchronous cross-store source-authority boundary.

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

Current-main source shows the outer identity read followed by another session read in each native mutation kernel; no target code was executed during this read-only review.

Is this the best way to solve the issue?

Passing the captured identity into the existing kernels removes the redundant read without adding an owner, changing routing, or weakening the synchronous source checks.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Native cross-store target validation keeps the original intent (c5cce7d: The session-admission migration captured target identity before asynchronous preparation and rechecked it inside the native transaction to reject replacement.)
  • Native mutation callbacks keeps the original intent (d1a550d: The worker migration retained native consumers and shared synchronous kernels while preserving current authority and write ordering.)
  • Cross-store authority exception and documentation keeps the original intent (ef7aa6a: Foreign-source authority cannot be validated through the existing target worker's commit contract, so the native effect boundary remains explicit.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Introduced change: The pinned introduction removes the outer hasBoardSession check and passes expectedSession through all three native mutation callbacks; the verified test merge contains the same production change. (src/boards/sqlite-board-store.ts:295, 57162bda2114)
  • Identity validation remains before writes: Each mutation kernel already calls hasBoardSession with expectedSession before modifying rows; that helper compares sessionId and lifecycleRevision, preserving the removed guard's predicate. (src/boards/sqlite-board-store.kernel.ts:280, 57162bda2114)
  • Current-main provenance: The session-admission migration introduced the outer identity guard to reject replaced targets; current-main blame retains that guard, while this PR consolidates it into the existing kernels. (src/boards/sqlite-board-store.ts:293, ec71e926c1a2)
  • Accepted native authority boundary: The merged perf(storage): move bookkeeping reads to existing workers #169631 explicitly retains cross-physical Board writes because the target worker cannot validate foreign-source authority; this PR preserves that decision and the synchronous checks surrounding the mutation. (src/boards/sqlite-board-authority.ts:30, ef7aa6a11619)
  • Focused regression coverage: The extended real-database fixture counts executed target-session statements for putWidget, applyOps, and grant, covers target replacement on both routes, and retains source-permission revocation with an unchanged Board result. (src/boards/sqlite-board-store.worker.test.ts:195, 57162bda2114)
  • Discussion and check state: The complete live body and comments supply no additional runtime artifact or owner objection; exact-head CI remains pending, with no failing check observed in the paginated check-run read. (57162bda2114)

PR surface

Source +5, Tests +52, Docs +2. Total +59 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 20 15 +5
Tests 1 89 37 +52
Docs 1 3 1 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 112 53 +59

Review metrics

Metric Value Why it matters
Production versus test changes Production +20/-15; tests +89/-37 Small identity-argument plumbing extends existing fixtures to cover cross-store read reduction and stale-target rejection without adding another harness.

Labels

Label changes:

  • add P3: This is a bounded performance improvement that preserves user behavior and existing authorization checks.
  • 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:

  • P3: This is a bounded performance improvement that preserves user behavior and existing authorization checks.
  • 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, 6:22 PM ET / 22:22 UTC.

@steipete
steipete merged commit 6f41a20 into main Oct 12, 2026
133 checks passed
@steipete
steipete deleted the dbasync/boardcut branch October 12, 2026 22:30
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 13, 2026
…nclaw#170318)

Pass the captured target session identity into the existing Board mutation-kernel validation, eliminating one redundant target-session SELECT per cross-store putWidget, applyOps, and grant. Preserve source-permission checks and cover cross-physical target replacement and source revocation.

The full cross-database worker cutover remains blocked on the shared final-authority contract described in openclaw#169631; Board T1 primitive counts remain unchanged.

Validation: PR CI tests and static gates, Knip export scans, and independent Codex review.
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 P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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