Skip to content

refactor(gateway): sharing member authority from prepared facts (S33 cohort 2) - #163572

Merged
steipete merged 3 commits into
mainfrom
dbasync/s33b
Oct 2, 2026
Merged

steipete merged 3 commits into
mainfrom
dbasync/s33b

Conversation

@steipete

@steipete steipete commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

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 gateway passed.
  • pnpm test over 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.
  • The member-flow negative control failed on the base with five caller-thread prepared statements; the final flow observes zero prepare/exec calls. Foreign-owner list disclosure and stale visibility no-op regressions also failed on their preceding candidates before repair.
  • Executed all selected check-changed components 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 a8c1182c16eb7fb0dc374416c7b0024cc56a4feb passed. pnpm check:madge-import-cycles: 0 cycles. git diff --check passed.
  • Independent Codex autoreview through P2: scoped-clean. Both accepted findings—fresh-row list authorization and fresh-row visibility no-op decisions—were fixed and received regressions before the clean final review.
Focused suite Passed Vitest test time
sessions-sharing.test.ts 14 29.16 s
sessions-public-share.test.ts 9 15.21 s
sessions-sharing.authority.test.ts 3 5.66 s
sessions-sharing.identities.test.ts 3 5.89 s
sessions-sharing.profile-enumeration.test.ts 2 2.75 s
session-metadata.admission.test.ts 14 21.96 s
sessions-rewind.storage.test.ts 26 98.74 s
session-sharing-store.worker.test.ts 15 18.51 s

Table 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.

  • SQL-free grant callbacks: the durable management guard reads current prepared profile and sharing facts, requires projected target readiness, and checks the retained physical source. The existing collaboration worker invokes the guard at transaction and commit admission and rereads expected authoritative rows in its synchronous transaction. The member-flow regression observes zero caller-thread DatabaseSync.prepare/exec calls across successful add/list/remove.
  • Dirty membership never authorizes: the commit regression leaves hasMembership true, dirties the projection, and verifies refusal and rollback. The readiness check runs before any additional request-authority callback.
  • Revocation refuses: actual commit-grant tests revoke the caller or manager role before commit and verify unchanged stored membership. A preparation barrier replaces the session under the same key and verifies the replacement is untouched. Foreign-owner-write regressions preserve actual-row authorization for public-share publication, member-list disclosure, and visibility updates, including no-ops.
  • Inherited gate: env-name budget 477/476 inherited from improve(agents): explain unknown tool outcomes and assert append-only request history #163379; this PR adds 0 names. The standalone script fails identically on the unchanged index and candidate; before/after name sets are both 477 with no additions or removals. The budget remains unchanged.

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 42bcd94a49ac1 initializes 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.ts type error reproduced independently on trusted main. Main fixed it in 90897637d32e0; conflict-free merge commit 2bfe0afba3ba9 incorporates 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, reported AgentDatabaseRegistryChangedError in the concurrent repository-worktree restore case. Investigation traced the exception to directSessionReq initializing 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 base 2aa2bd669e3aa18f9e7f36cb7c7c3ad6b862a236. 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.ts using 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.

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.
@clawsweeper

clawsweeper Bot commented Oct 2, 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.

@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components. This comment is informational because the PR author has repository Maintain or Admin access.

  • Current SHA: 2bfe0afba3ba9bb5d957fb3f80471adf48a76200
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/gateway/server-methods/sessions-sharing-authority.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.

Carefully review these changes before merging.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: L labels Oct 2, 2026
@steipete

steipete commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 2, 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 2, 2026
@clawsweeper

clawsweeper Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed October 2, 2026, 10:58 AM ET / 14:58 UTC (Revision 4).

ClawSweeper review

What this changes

Sharing-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
Reviewed head: 2bfe0afba3ba9bb5d957fb3f80471adf48a76200

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A coherent implementation with strong production-boundary evidence and no actionable findings; the separate CI gate remains unresolved.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): Reported runs exercise the changed production sharing handlers through real SQLite readers and writers, with successful member flows and observable rollback after commit-time revocation, dirty facts, and session replacement. Inspected regressions also cover fresh-row disclosure and visibility decisions. No stored-data model changes require migration proof; this review did not execute tests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): Reported runs exercise the changed production sharing handlers through real SQLite readers and writers, with successful member flows and observable rollback after commit-time revocation, dirty facts, and session replacement. Inspected regressions also cover fresh-row disclosure and visibility decisions. No stored-data model changes require migration proof; this review did not execute tests.
Evidence reviewed 9 items Pinned introduced change: Reviewed the complete introduced diff from pinned base 2aa2bd6 to original head 2bfe0af. The production changes are confined to sharing authority and its handlers; there are no dependency, schema, configuration, or publishing changes.
Current main still needs the cutover: Fetched main retains requireCurrentManagedTarget and assertCurrentSharingManager using synchronous target and role resolution. The merged suggestion-list work at #163546 covers a separate handler and does not supersede this change.
Authority remains live through final effects: The shared access owner checks caller, routing, projection readiness, physical source, session identity, and lifecycle revision. It repeats those checks around request-authority callbacks. Member writers retain transaction and commit admission checks plus authoritative expected-row validation; list disclosure and entry-patch callbacks validate the fresh stored row.
Findings None None.
Security None None.

How this fits together

Gateway 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]
Loading

Before merge

  • Complete next step (P2) - Attribute the registry-discovery failure in the concurrent worktree-restore case from job 110887306857 and resolve the failed exact-head CI gate through the native landing workflow.
Agent review details

Security

None.

PR surface

Source +78, Tests +275, Docs +10. Total +363 across 10 files.

View PR surface stats
Area Files Added Removed Net
Source 2 326 248 +78
Tests 7 346 71 +275
Docs 1 10 0 +10
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 682 319 +363

Review metrics

Metric Value Why it matters
Production versus regression growth Net production +78 lines; net tests/support +275 lines Production growth supports retained authority and source checks; regressions cover worker rollback, replacement, disclosure, and lifecycle contracts.

Technical review

Best 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.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded internal worker-access improvement with meaningful authorization coverage and no demonstrated urgent user-facing regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): Reported runs exercise the changed production sharing handlers through real SQLite readers and writers, with successful member flows and observable rollback after commit-time revocation, dirty facts, and session replacement. Inspected regressions also cover fresh-row disclosure and visibility decisions. No stored-data model changes require migration proof; this review did not execute tests.
  • proof: sufficient: Contributor real behavior proof is sufficient. Reported runs exercise the changed production sharing handlers through real SQLite readers and writers, with successful member flows and observable rollback after commit-time revocation, dirty facts, and session replacement. Inspected regressions also cover fresh-row disclosure and visibility decisions. No stored-data model changes require migration proof; this review did not execute tests.

Evidence

What I checked:

  • Pinned introduced change: Reviewed the complete introduced diff from pinned base 2aa2bd6 to original head 2bfe0af. The production changes are confined to sharing authority and its handlers; there are no dependency, schema, configuration, or publishing changes. (2bfe0afba3ba)
  • Current main still needs the cutover: Fetched main retains requireCurrentManagedTarget and assertCurrentSharingManager using synchronous target and role resolution. The merged suggestion-list work at refactor(sessions): finish suggestion list worker reads #163546 covers a separate handler and does not supersede this change. (src/gateway/server-methods/sessions-sharing-authority.ts:18, 918153ea3355)
  • Authority remains live through final effects: The shared access owner checks caller, routing, projection readiness, physical source, session identity, and lifecycle revision. It repeats those checks around request-authority callbacks. Member writers retain transaction and commit admission checks plus authoritative expected-row validation; list disclosure and entry-patch callbacks validate the fresh stored row. (src/gateway/server-methods/sessions-sharing-authority.ts:193, 2bfe0afba3ba)
  • Production-boundary authority evidence: The captured PR body reports successful real SQLite worker runs and negative controls. Inspected regressions exercise successful add/list/remove without caller-thread SQL, commit-time caller and manager-role revocation, dirty membership rollback, replacement during preparation, and fresh-row authorization for publication, disclosure, and visibility. These use production handlers and persistence owners with injected barriers rather than mocked persistence. (src/gateway/server-methods/sessions-sharing.authority.test.ts:73, 2bfe0afba3ba)
  • Existing-state compatibility: The introduced changes preserve existing member-write commands, expected-entry checks, serialized fields, public RPCs, incognito ownership, and lifecycle fences. No stored-data model or migration changes are introduced. The new documentation explicitly records unchanged permission, retention, schema, and update contracts. Public docs: docs/reference/database-schemas/worker-access.md. (docs/reference/database-schemas/worker-access.md:1024, 2bfe0afba3ba)
  • Exact-head CI failure: GitHub confirms job 110887306857 failed its Node test step on the reviewed head, and the current openclaw/ci-gate remains failed. The captured body identifies a registry-discovery failure in the concurrent worktree-restore case and reports that its main comparison passed, so inherited-failure attribution is not established. The job-log download was blocked by the host's storage-domain allowlist; this review did not independently inspect that failure trace. (2bfe0afba3ba)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Vincent Koc: 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 (3 earlier review cycles)
  • reviewed 2026-10-02T14:29:48.363Z sha 6404a12 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-02T14:39:39.477Z sha 42bcd94 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-02T14:48:25.356Z sha 2bfe0af :: needs maintainer review before merge. :: none

@steipete

steipete commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@steipete

steipete commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Oct 2, 2026
@steipete
steipete merged commit 8ecd925 into main Oct 2, 2026
217 of 221 checks passed
@steipete
steipete deleted the dbasync/s33b branch October 2, 2026 15:22
@steipete

steipete commented Oct 2, 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 3, 2026
…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
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. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. security-sensitive-changed size: L 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