Skip to content

fix(gateway): decide session-scoped read access once at admission - #206792

Merged
obviyus merged 2 commits into
mainfrom
fix/session-scoped-read-once
Nov 27, 2026
Merged

obviyus merged 2 commits into
mainfrom
fix/session-scoped-read-once

Conversation

@obviyus

@obviyus obviyus commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

retainSessionScopedRead() (session file, diff, branch, subscription, MCP app and canvas reads) decided visibility at admission and then re-decided it in assertCurrent() after every awaited step: it re-read the role actor, the sharing identity, the connect scopes, the startable-main rule from the live config and the invited membership. A read that was admitted could then fail with "Session … was not found" when the creator removed the invited person, or the role changed, while the read was running. Repo rule (AGENTS.md "Decide authority once", #206706): a started request finishes; only data fences may stop it. #206747 removed the newer membership re-read in isInvitedWorkspaceTarget and named this older guard as a follow-up.

Fix

  • Visibility, narrow-reader identity/scope and the startable-main rule are decided once, at admission, from the admission config and the membership captured then.
  • assertCurrent() keeps only data fences: request lifetime (abort signal, commit guard), session routing, and the retained row (isCurrentAtResponse: incarnation, lifecycle revision, access-relevant row fields, physical store).
  • No new hook, flag, state or refusal text. Production: session-scoped-read.ts +7/−14 against main.

User impact

  • An invited reader whose access is removed while a file/diff read is running gets that read's result; the next read is refused (same answer as admission at start, no widening).
  • Row changes during a read (reset, archive, workspace move, visibility change on the row) still refuse it, unchanged.

Tests

  • New finishes an admitted invited read after membership removal (server-methods.session-scoped-reads.test.ts): red on base 4d7e00b86313 (Session "agent:main:scoped-read" was not found), green on head; the follow-up read after removal is refused.
  • Deleted the changed case of separates a trusted solo operator from its sharing exemption: it asserted that swapping the operator actor mid-read refuses the read, i.e. the removed mid-request re-check.
  • sessions-read-invited.test.ts progressCard.get: it asserted that revoking the invitation during a card read refuses that read (CI round 1 red, the removed re-check). Now the in-flight read returns the card and the next read is hidden.
  • Pre-push: one ocx test run of the touched test plus every test that imports session-scoped-read.ts and the direct callers' tests; oxfmt, oxlint, pnpm check:changed.
  • no-operator-permission-read counts: unchanged (the file is not on any list; no listed site removed).

E2E (one-admission Q/R/S, real Gateway + real model)

  • Head b40d1bf3f5d3: Q pass, Q sentence pass, S pass. R fails identically on base 4d7e00b86313 (state: final, 3 tool ends after revoke): the shared proof's R check was changed on 11-27 to expect the not-yet-landed "stop on access loss" feature (stopReason: access-reduced, not present on main). This PR touches only session-scoped RPC reads, not chat runs, so R does not measure it. Same verdict on base and head.
  • That approved rule ("a writer that removes a named person's access stops the work that person started; all other changes apply to the next request") covers runs, subagents, exec and queued/owed work, not a read RPC. This PR is consistent with it: the read decides once; the next read sees the removal.

- Delete the post-admission visibility, role and membership re-check in retainSessionScopedRead; keep request lifetime, routing and row fences.

Co-authored-by: obviyus <[email protected]>
@clawsweeper

clawsweeper Bot commented Nov 27, 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 gateway Gateway runtime size: S labels Nov 27, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. impact:session-state Session, memory, transcript, context, or agent state can drift or corrupt. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 27, 2026
…r revocation

- The in-flight progressCard.get read now finishes; the next read after revocation stays hidden.

Co-authored-by: obviyus <[email protected]>
@clawsweeper

clawsweeper Bot commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR checks session-read access once at admission while retaining request-lifetime, routing, and session-row fences.

Example: An invited reader opens note.txt in agent:main:scoped-read, then loses membership while the read runs.

  • Before: The admitted read fails with a session-not-found error.
  • After: The admitted read completes, and the next read is refused.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The production repair is focused and source-supported, but changed-path runtime proof is absent and an affected consumer test fails on the reviewed head.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: An invited reader can receive a session-not-found error solely because membership changes after their read was admitted.
Reason: The maintainer-authored change restores the explicit admission-once contract without adding configuration, state, or a competing access owner.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep open: this maintainer-authored PR addresses a current admission-contract violation, with one affected consumer test still requiring repair.

Reviewed head: b40d1bf3f5d30a6c587efec0b48a53020b21fcca

Before merge

  • Update the progress-card test for admission-time access (P2) - Moving membership checks out of assertCurrent also changes progressCard.get, which invokes that guard after awaiting progressCardStore.get. Its existing regression pauses that read, removes membership, and still expects the admitted request to reject here. Exact-head CI fails with “promise resolved undefined instead of rejecting” in checks-node-changed-compact-large-40. Update this consumer test to assert the returned card and refusal of a subsequent request, while retaining its nonmember checks; restoring the production recheck would contradict the intended fix.

Findings

  • [P2] Update the progress-card test for admission-time access — src/gateway/server-methods/sessions-read-invited.test.ts:324
Agent review details

How this fits together

Gateway session-read handlers combine authenticated caller access and session membership with a retained session row, then consume that admission through asynchronous file, diff, subscription, and application reads.

flowchart TD
  A[Authenticated read request] --> B[Session read admission]
  C[Config and membership] --> B
  B --> D[Retained row and admitted access]
  D --> E[Asynchronous read]
  E --> F[Lifetime routing and row fences]
  F --> G[Response]
  H[Next request] --> B
Loading

Technical review

Best possible solution:

Keep the existing admission owner and data fences, and align the affected progress-card regression with completion of admitted reads and refusal of later reads.

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

Current-main source deterministically rereads membership after asynchronous reads, and the author reports the matching regression failing on base and passing on head; this read-only review executed no target code.

Is this the best way to solve the issue?

Moving policy decisions out of the repeated guard is the smallest repair using existing owners, and the removed actor-swap expectation contradicts the approved admission contract.

Full review comments:

  • [P2] Update the progress-card test for admission-time access — src/gateway/server-methods/sessions-read-invited.test.ts:324
    Moving membership checks out of assertCurrent also changes progressCard.get, which invokes that guard after awaiting progressCardStore.get. Its existing regression pauses that read, removes membership, and still expects the admitted request to reject here. Exact-head CI fails with “promise resolved undefined instead of rejecting” in checks-node-changed-compact-large-40. Update this consumer test to assert the returned card and refusal of a subsequent request, while retaining its nonmember checks; restoring the production recheck would contradict the intended fix.
    Confidence: 1

Overall correctness: patch is incorrect
Overall confidence: 0.97

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Repeated caller identity and visibility checks changes intended behavior with a stated reason (da27b33: The original owner retained caller identity and session visibility through I/O to bind narrow operations to the original caller; this PR explicitly replaces ongoing authority checks with admission-time decisions.)
  • Membership rereads before publication changes intended behavior with a stated reason (4daeb92: The earlier repair intentionally enforced current membership after asynchronous preparation; the newer maintainer-approved contract instead permits admitted work to finish.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test src/gateway/server-methods/sessions-read-invited.test.ts --maxWorkers=1
  • pnpm test src/gateway/server-methods.session-scoped-reads.test.ts --maxWorkers=1
  • git diff --check

What I checked:

Likely related people:

  • Vincent Koc: Raw commit da27b33 adds src/gateway/server-methods/session-scoped-read.ts:20 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: da27b336c0e9; files: src/gateway/server-methods/session-scoped-read.ts)

PR surface

Source -4, Tests +8. Total +4 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 15 19 -4
Tests 1 34 26 +8
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 49 45 +4

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

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 November 27, 2026, 11:05 AM ET / 16:05 UTC.

@obviyus

obviyus commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator Author

One-admission E2E (real isolated Gateway + gpt-5.5), verdicts per check:

Check base 4d7e00b86313 head 950a3dff9baa
R.running-turn-stops-on-access-loss false false
Q.queued-input-refused-visibly true true
Q.refusal-sentence-in-transcript true true
S.stop-cancels true true

R detail, base and head: state: final, stopReason: stop, toolEndsAfterRevoke: 3. The R check now expects the unlanded stop-on-access-loss feature (stopReason: access-reduced, absent on main); this PR changes only session-scoped RPC reads, so R is identical on both sides. Q (queued input refused visibly) and S (Stop cancels) pass on head.

@obviyus
obviyus merged commit aad2719 into main Nov 27, 2026
119 of 120 checks passed
@obviyus
obviyus deleted the fix/session-scoped-read-once branch November 27, 2026 16:26
@obviyus

obviyus commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator Author

Landed as aad2719. Session-scoped reads (files, diff, branches, subscriptions, MCP app, canvas, progress card) now decide visibility once at admission; an admitted read finishes after a membership or role change, and the next read is refused. Data fences (request lifetime, routing, row incarnation/revision) unchanged. Proof: regression test red on base / green on head, CI green on the exact head, clean local review, Q/S E2E pass (R identical on base and head).

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 28, 2026
…enclaw#206792)

## Problem

`retainSessionScopedRead()` (session file, diff, branch, subscription, MCP app and canvas reads) decided visibility at admission and then re-decided it in `assertCurrent()` after every awaited step: it re-read the role actor, the sharing identity, the connect scopes, the startable-main rule from the live config and the invited membership. A read that was admitted could then fail with "Session … was not found" when the creator removed the invited person, or the role changed, while the read was running. Repo rule (AGENTS.md "Decide authority once", openclaw#206706): a started request finishes; only data fences may stop it. openclaw#206747 removed the newer membership re-read in `isInvitedWorkspaceTarget` and named this older guard as a follow-up.

## Fix

- Visibility, narrow-reader identity/scope and the startable-main rule are decided once, at admission, from the admission config and the membership captured then.
- `assertCurrent()` keeps only data fences: request lifetime (abort signal, commit guard), session routing, and the retained row (`isCurrentAtResponse`: incarnation, lifecycle revision, access-relevant row fields, physical store).
- No new hook, flag, state or refusal text. Production: `session-scoped-read.ts` +7/−14 against main.

## User impact

- An invited reader whose access is removed while a file/diff read is running gets that read's result; the next read is refused (same answer as admission at start, no widening).
- Row changes during a read (reset, archive, workspace move, visibility change on the row) still refuse it, unchanged.

## Tests

- New `finishes an admitted invited read after membership removal` (`server-methods.session-scoped-reads.test.ts`): red on base `2626bc1ae892` (`Session "agent:main:scoped-read" was not found`), green on head; the follow-up read after removal is refused.
- Deleted the `changed` case of `separates a trusted solo operator from its sharing exemption`: it asserted that swapping the operator actor mid-read refuses the read, i.e. the removed mid-request re-check.
- `sessions-read-invited.test.ts` `progressCard.get`: it asserted that revoking the invitation during a card read refuses that read (CI round 1 red, the removed re-check). Now the in-flight read returns the card and the next read is hidden.
- Pre-push: one `ocx test` run of the touched test plus every test that imports `session-scoped-read.ts` and the direct callers' tests; oxfmt, oxlint, `pnpm check:changed`.
- `no-operator-permission-read` counts: unchanged (the file is not on any list; no listed site removed).

## E2E (one-admission Q/R/S, real Gateway + real model)

- Head `b40d1bf3f5d3`: Q pass, Q sentence pass, S pass. R fails identically on base `2626bc1ae892` (`state: final`, 3 tool ends after revoke): the shared proof's R check was changed on 11-27 to expect the not-yet-landed "stop on access loss" feature (`stopReason: access-reduced`, not present on `main`). This PR touches only session-scoped RPC reads, not chat runs, so R does not measure it. Same verdict on base and head.
- That approved rule ("a writer that removes a named person's access stops the work that person started; all other changes apply to the next request") covers runs, subagents, exec and queued/owed work, not a read RPC. This PR is consistent with it: the read decides once; the next read sees the removal.

Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime impact:session-state Session, memory, transcript, context, or agent state can drift or corrupt. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant