Repository navigation
refactor(gateway): sharing member authority from prepared facts (S33 cohort 2) - #163572
Conversation
Use current prepared session and profile facts for management grants, retain logical lifecycle fences alongside physical store identity, and validate fresh stored rows before disclosure or visibility decisions. Preserve existing worker and incognito owners. Prove zero caller-thread SQL for member add/list/remove and refusal of revoked or dirty authority.
|
🦞👀 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. |
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Codex review: needs changes before merge. Reviewed October 2, 2026, 10:58 AM ET / 14:58 UTC (Revision 4). ClawSweeper reviewWhat this changesSharing-management requests reuse prepared permission facts and worker reads while preserving session identity, revocation checks, and lifecycle ordering. Merge readiness⛔ Needs changes before merge - 1 item remains The work remains necessary and has no actionable correctness or security findings. This maintainer-authored PR should stay open; failed exact-head CI prevents a landing-ready verdict. Priority: P2 Review scores
Verification
How this fits togetherGateway sharing handlers receive requests to manage session members, visibility, and public links. They authorize the caller against current session and profile facts before reading or changing SQLite-backed session state. flowchart TD
A[Sharing request] --> B[Retain original session and database]
B --> C[Prepare current permission facts]
C --> D{Caller still authorized}
D -->|No| E[Refuse request]
D -->|Yes| F[Worker read or guarded write]
F --> G[Validate current authority and stored row]
G --> H[Return result or publish committed change]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +78, Tests +275, Docs +10. Total +363 across 10 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep one prepared sharing-authority owner serving the existing handlers, with current authorization enforced at disclosure and durable write boundaries. Do we have a high-confidence way to reproduce the issue? Not applicable to the refactor itself: source inspection confirms the synchronous management path on current main. The separate CI failure has a named scenario but no established current-main reproduction. Is this the best way to solve the issue? Yes: the patch reuses existing facts, reader, writer, and lifecycle owners while removing superseded management helpers and preserving public and stored-data contracts. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 918153ea3355. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles) |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
…cohort 2) (openclaw#163572) * refactor(gateway): prepare sharing management authority Use current prepared session and profile facts for management grants, retain logical lifecycle fences alongside physical store identity, and validate fresh stored rows before disclosure or visibility decisions. Preserve existing worker and incognito owners. Prove zero caller-thread SQL for member add/list/remove and refusal of revoked or dirty authority. * test(gateway): initialize and drain steering custody projection
What Problem This Solves
Sharing-management RPCs still resolved session targets, manager roles, and public-share list details through caller-thread SQLite, even though member writes already ran in the collaboration worker. A delayed preparation or writer grant must not authorize a revoked manager or a replacement session.
Why This Change Was Made
Retain the original session and physical source before preparation yields. Use resident membership readiness and current prepared profile/role/sharing facts, with the existing asynchronous facts owner for aliases, absent rows, and incognito. Recheck those facts at the existing transaction and commit grants. Member-list public-share details now use the existing reader worker. Keep the logical lifecycle locator separate from the physical worker target so member removal retains the same FIFO fence as fork/reset.
Remove the superseded synchronous management helpers and migrate all their callers. Visibility and public-share updates use the same prepared authority; their patch callbacks also validate the actual row supplied by the existing patch owner, preserving protection against foreign owner changes that have not published resident facts. List disclosure and visibility no-op decisions also validate the fresh stored row.
User Impact
Permissions and stored formats are unchanged. No new worker service, schema, cache, retention, durability, migration, or update behavior. Participant/category persistence already uses the collaboration worker and is unchanged. Incognito keeps its native owner. The generic visibility/public-share patch writer and broad router-admission fallbacks remain separate migration work.
Production TypeScript: +326 / −248 / net +78 lines against pinned base
a8c1182c16eb7fb0dc374416c7b0024cc56a4feb.The S33 primitive inventory stays T1 4 → 4, and the repository inventory stays 1518 → 1518: these primitives retain other callers and native ownership. The registered member add/list/remove regression changes from 5 caller-thread prepared statements → 0, while using the actual reader/writer workers.
Evidence
node scripts/worktree-setup.mjs gatewaypassed.pnpm testover the eight sharing, metadata, writer, and lifecycle files below with--maxWorkers=1: 86/86 passed, 276.83 s wall. The adjusted visibility-replacement case and all broader suites pass. Baseline sharing suite: 14 passed, 62.52 s wall. Focused public lifecycle predecessor regression: 1 passed, 44.12 s wall.prepare/execcalls. Foreign-owner list disclosure and stale visibility no-op regressions also failed on their preceding candidates before repair.check-changedcomponents individually because its wrapper stops at the inherited env check. Production types, all 27 core test-type graphs, changed-file lint/format, Knip's production/full-tree/script export scans, all other ratchets, and repository guards pass. The max-lines owner ran separately from its bundled env check; no guard or baseline was edited.pnpm check:database-worker-ratchet --base a8c1182c16eb7fb0dc374416c7b0024cc56a4febpassed.pnpm check:madge-import-cycles: 0 cycles.git diff --checkpassed.sessions-sharing.test.tssessions-public-share.test.tssessions-sharing.authority.test.tssessions-sharing.identities.test.tssessions-sharing.profile-enumeration.test.tssession-metadata.admission.test.tssessions-rewind.storage.test.tssession-sharing-store.worker.test.tsTable times exclude compilation/imports; combined command wall time is above. Real SQLite worker and lifecycle boundaries are required to prove rollback, foreign commits, incarnation/source binding, and FIFO. The existing lifecycle suite exposed the logical-versus-physical fence regression; a mocked writer would miss it. No Gateway boots or timer waits were added. Hosted CI evidence is recorded in run 37021914949; the diagnosed single-job rerun and cancelled ancillary retries are described below.
DatabaseSync.prepare/execcalls across successful add/list/remove.hasMembershiptrue, dirties the projection, and verifies refusal and rollback. The readiness check runs before any additional request-authority callback.Overlap check found no blocking same-function work. Adjacent PRs #134006 (picker identity filtering), #161126 (category uncertain-outcome fencing), and #163378 (generic metadata patch workers) are unchanged by this patch. Suggestions remain with the already merged #163546.
Landing validation
Initial CI exposed a PR-caused steering-custody fixture omission. Commit
42bcd94a49ac1initializes the existing session projection before the real visibility RPC and drains projection reads before fixture database closure. The baseline failed locally; the repaired steering suite passes 17/17 and the sibling pending-input suite passes 33/33. Formatting, type-aware lint, and independent Codex P2 autoreview passed. Production behavior and authority-loss assertions are unchanged.The inherited
worker-turn-launcher.claim-recovery.test.tstype error reproduced independently on trusted main. Main fixed it in90897637d32e0; conflict-free merge commit2bfe0afba3ba9incorporates that fix. The reviewed PR delta is unchanged. Post-integration gateway-other types pass, as do 29 steering, sharing-authority, and public-share cases (109.79 s wrapper wall, including compiler preparation). ClawSweeper completed the exact-head review at 2026-10-02 14:48 UTC with no findings or security concerns.CI run 37021914949, job
110887306857, reportedAgentDatabaseRegistryChangedErrorin the concurrent repository-worktree restore case. Investigation traced the exception todirectSessionReqinitializing its projection before calling the requested handler; neither the sharing-management guard nor the concurrent restore has executed at that point. All failing-stack owners and fixture code are identical to merge base2aa2bd669e3aa18f9e7f36cb7c7c3ad6b862a236. The new resident sharing guard binds its selected physical source rather than a new registry-wide snapshot. The fixture retains a live Gateway on one state root while a direct-handler case applies nested state; switching the existing single-path registry memo during a worker read is a plausible pre-existing race, not a confirmed causal trace from the failed run. No causal path from this PR's changed code was found.Repeated comparisons ran the complete worktree file five times alone and five times with
server.sessions.create.accounts.test.tsusing two workers, on both the pinned PR head and exact merge base. PR: 10/10 commands, 165/165 cases passed. Base: 9/10 commands, 164/165 cases passed; one different case, existing managed-worktree initial/follow-up turns, timed out waiting for a WebSocket response. The registry-failure case passed in every run. No registry error reproduced across the 20 commands. These local results do not prove that the intermittent failure is fixed. Following this bounded investigation, the single-job rerun passed with its dependent gate: CI run 37021914949 attempt 2 completed successfully with 66 completed jobs and no failures. No production fix is claimed for the unreproduced registry race.Dependency-review status history shows a transient “Security review has not completed” state, followed three seconds later by “No dependency changes require review.” The current status is successful, and this PR changes no manifest or lockfile. Cancelled auto-response and PR-context runs were each rerun once; both second attempts succeeded. No check, timeout, assertion, registry guard, or budget was weakened.