Repository navigation
improve(boards): avoid duplicate target reads in cross-store writes - #170318
Conversation
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.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis 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.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete 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 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe 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]
Technical reviewBest 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
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +5, Tests +52, Docs +2. Total +59 across 3 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 12, 2026, 6:22 PM ET / 22:22 UTC. |
…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.
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, orgrant. 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:
readSessionSourceValidationrejects 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
putWidgetapplyOpsgrantThe 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 --checkpassed. 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 requiredpnpm deadcode:exportsscan 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.