Skip to content

fix(gateway): keep session files readable after cache eviction - #178173

Merged
steipete merged 3 commits into
mainfrom
steipete/perf-micro-stress-per-turn-allocation-hillclimb-20260919
Oct 20, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/perf-micro-stress-per-turn-allocation-hillclimb-20260919

Conversation

@steipete

@steipete steipete commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Under many-session load, file previews, downloads, and session diffs can incorrectly fail with “Session workspace changed during file access.” The file authority reader consulted the evictable actor replica; unrelated reads could evict the row and make an unchanged workspace appear revoked. A 5,000-session streaming Gateway stress run reproduced this through sessions.diff.

User Impact

File access remains available when unrelated session reads evict display rows. Real workspace, library-selection, session-generation, and sharing changes still revoke access, including an already-issued download URL. Sandbox and host-workspace checks remain in place.

Why This Change Was Made

Use the existing retained session-entry predicate owner for file authority, then borrow that same current-entry reader for form uploads and file operations. HTTP delivery borrows the download grant's longer lifetime. Delete the duplicate cache-based authority reader and worktree-settlement reread.

Snapshot-dependent predicates need the full committed entry, whereas display consumers need list projections. Carry the full postimages already produced by native writes, worker receipts, recovery, actors, and transcript writers to the existing predicate owner. Do not add SQL reads, caches, a schema change, or configuration. Missing required snapshot evidence refuses the read; ordinary title, participant, and transcript updates preserve it.

Production delta: +186 / −125 = +61 lines. The deleted file-specific authority path is smaller; the remaining growth carries selected-snapshot evidence across the existing publishers so the repair preserves revocation instead of treating incomplete list rows as complete facts.

Evidence

  • Base reproduction: file preview after actual replica LRU eviction fails FORBIDDEN; an issued download returns 404 after eviction. The same tests pass with the fix, and a real workspace change still revokes the download.
  • Synthetic isolated Gateway functional stress: 5,000 sessions, 6,000 retained runs, 200 approvals, 100 disabled fixture cron jobs, 12 projects; 30 viewers and 20 concurrent streaming turns with real Code Mode read/exec calls. 180 foreground turns over 120 measured seconds passed, including mixed list/history/connect/diff RPCs and a final diff edit control. This is functional proof, not an A/B performance claim.
  • Focused tests: file sandbox and diff 37 passed; replacement-receipt owner 24 passed; transcript-report worker 13 passed; file worktree, retained-read lifetime, and form resources 26 passed; incognito files and worker transcript commits 18 passed; CLI history boundary 27 passed. One new fixture initially omitted required settlement arguments; corrected before the passing run.
  • CI fixture correction: file-policy tests now install the matching runtime config; repository tests use persisted entry facts rather than mocked readers without storage ownership. Their simulated Stop/reset operations now use the Gateway logical store scope. File-policy 41 passed / 1 platform skip, repository 16 passed; revocation still proves no dispatch and no writes.
  • Final HTTP disclosure trace on 47855e9228333d864a59b0ee670cca7ef04d00af (runtime patch unchanged on the current head): allowed after replica eviction 200 with <h1>boo</h1>\n; same URL after workspace revocation 404 / Not Found. A read-only role received 200 with synthetic host private bytes; after its role became sandbox-required, the same URL returned 404 / Not Found, without protected bytes. Real Gateway admission, persisted entries, and loopback HTTP delivery; 5 tests passed across the worktree and sandbox files. Temporary observation-only prints were removed after capture.
  • Changed-file formatting and lint passed. Independent staged reviews of the runtime fix and CI corrections are clean through P2.
  • Export-name collision guard passed; eager-import and PR-wrapper source-closure checks: 22 passed.

No allocation reduction is claimed. The earlier long stress run failed before producing a valid baseline; promotion, GC, and latency acceptance measurements remain separate work. Broad checks run in PR CI. No Testbox lease was allocated.

CI history and fixture correction

On head 47855e9228333d864a59b0ee670cca7ef04d00af, worker-turn-launcher.test.ts reports 33 passed / 1 failed at the stale-local-finally case: durable restart cleanup returns 0, while the test expects 1. The exact unchanged main parent 8fb3a2007922d5d73a3c72be6a8062aca073c72c produces the same result and assertion. The baseline run used the same worktree with the complete PR patch removed and its tracked tree verified equal to that pinned parent, then restored the patch. Upstream #178098 moved local claims to memory; this test still expects a durable row. This PR changes neither that test nor the placement claim owner.

The heartbeat Gateway restart case timed out at 90 seconds on that CI head. Its first server-start module evaluation consumed 13.74 seconds inside the behavior budget; the second import took 1.1 ms. Two-core/8 GB isolated Linux reproduction passed on both head and pinned parent (28.1 / 13.9 seconds initially; warmed head 14.1 seconds), so a passing replay was not used to declare the failure inherited.

The fixture now follows the existing Gateway-test convention: prepare server-start in beforeAll before starting the behavior timer. Both real Gateway starts, the catalog-owner restart, all route/delivery assertions, and the 90-second timeout remain unchanged. Focused corrected case passed in 16.0 seconds; formatting, lint, and independent review are clean. The shared hook timeout is 180 seconds, unchanged. This addresses a demonstrated timeout contributor; PR CI validates the new head. No CI rerun was requested.

On exact PR head d5f68bba59a10280dc1fe51dcee2cb49fac286c6, CI run 39390399994, job 118520893189 failed src/gateway/x-publication-owner-composition.e2e.test.ts at the anonymous public read (line 919): expected HTTP 200, received HTTP 503 with “This conversation is temporarily unavailable. Please retry.” The same single file on the exact unchanged PR parent 40ecdd3e3b82 reproduced the identical assertion and response. The pinned PR head passed. Both runs used the same isolated Linux sandbox, two CPU cores and 8 GB memory, with the complete PR patch reversed for baseline and restored afterward. This establishes the failure as inherited; the public representation cache/admission/read path is unchanged. No CI rerun was requested.

The same inherited worker-placement assertion recurred on d5f68bba59a10280dc1fe51dcee2cb49fac286c6 in job 118520893299 of run 39390399994. The test and placement owner are byte-identical between the proven baseline above and this head; the other seven files in that job passed (134 passing tests overall).

Final CI disposition

Exact-head CI run 39390399994 completed on d5f68bba59a10280dc1fe51dcee2cb49fac286c6. The only failed test jobs are the two inherited failures documented above; all remaining test jobs passed. The aggregate CI gate reflects those failures. Security-sensitive and dependency review gates passed, and the latest exact-head independent review has no actionable findings. Land under the standing inherited-failure exception; no CI reruns were requested.

@clawsweeper

clawsweeper Bot commented Oct 20, 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 gateway Gateway runtime agents Agent runtime and tooling size: L labels Oct 20, 2026
@steipete
steipete marked this pull request as ready for review October 20, 2026 06:45
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-20T08:04:55.708596Z d5f68bb New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: d5f68bba59a10280dc1fe51dcee2cb49fac286c6
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

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

Carefully review these changes before merging.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 20, 2026
@clawsweeper

clawsweeper Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Retain session-file authority independently of display-cache residency and forward committed snapshot facts through existing publication owners.

Example: Download preview.html after unrelated session reads evict its cached row.

  • Before: An unchanged workspace can produce FORBIDDEN or HTTP 404.
  • After: The download returns HTTP 200 with <h1>boo</h1>, then returns 404 if the workspace changes.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Useful, coherent repair with real HTTP boundary evidence and no actionable findings; exact-head CI remains incomplete.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (logs): Recorded production Gateway admission and real loopback HTTP delivery return expected bytes after eviction and reject retained grants after workspace or reader-policy changes; all changed production blobs match the proof revision.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Files and diffs can become unavailable under session-cache pressure even though workspace access has not changed.
Reason: The maintainer-authored direction restores an existing user contract and preserves the prior security boundary.

Merge readiness

✅ Ready for maintainer review

This PR fixes a source-confirmed cache-eviction failure while preserving live workspace and reader-policy checks; no actionable patch defect was found.

Priority: P2
Reviewed head: d5f68bba59a10280dc1fe51dcee2cb49fac286c6

Before merge

None.

Findings

None.

Agent review details

How this fits together

Gateway file, diff, and form-resource handlers consume session facts published by database and memory owners, then enforce current session and caller authority before filesystem access and HTTP disclosure.

flowchart LR
  A[Session writers] --> B[Committed publications]
  B --> C[Retained entry predicate]
  D[Gateway file request] --> C
  C --> E[Workspace and reader checks]
  E --> F[File response or retained download]
Loading

Technical review

Best possible solution:

Keep file authority in the existing retained predicate owner and preserve live revocation checks through HTTP delivery.

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

Current main contains the evictable-reader failure path, and the supplied baseline reproduction identifies FORBIDDEN previews and 404 downloads after actual LRU eviction; this read-only review ran no target code.

Is this the best way to solve the issue?

The patch repairs the lifetime mismatch using an existing authority owner, removes duplicate cache-based checks, and carries snapshot evidence across affected publishers without new storage or configuration.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit e1cb2b3 adds src/config/sessions/session-accessor.sqlite-entry-cache-publication-state.ts:243 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: e1cb2b3c22ac; files: src/config/sessions/session-accessor.sqlite-entry-cache-publication-state.ts)
  • Shakker: Raw commit c4ccdcb adds src/gateway/server-methods/session-file-read-authority.ts:67 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: c4ccdcb8b4d2; files: src/gateway/server-methods/session-file-read-authority.ts)
  • RoboClaw: Raw commit 5266c8d adds src/gateway/server-methods/session-file-read-authority.ts:12 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 5266c8d14862; files: src/gateway/server-methods/session-file-read-authority.ts)

PR surface

Source +61, Tests +257, Docs +5. Total +323 across 33 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 23 186 125 +61
Tests 9 311 54 +257
Docs 1 5 0 +5
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 33 502 179 +323

Review metrics

Metric Value Why it matters
Production versus tests Production +186/-125; tests +311/-54 Production growth forwards existing full postimages through shared publishers; tests cover eviction, retained HTTP lifetime, benign updates, and actual revocation.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Cache pressure can incorrectly deny file previews, downloads, and diffs while the underlying workspace remains valid.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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.

History

Review history (3 earlier review cycles)
  • reviewed 2026-10-20T07:01:02.344Z sha cd66d6cf8f38c7339185eb65adb1a1539d45e585 :: needs real behavior proof before merge. :: [P2] Migrate the remaining file suites to the retained-reader contract
  • reviewed 2026-10-20T07:20:28.689Z sha 47855e9 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-20T07:58:57.952Z sha 47855e9 :: needs maintainer review before merge. :: none

Reviewed October 20, 2026, 4:35 AM ET / 08:35 UTC (Revision 4).

@steipete
steipete force-pushed the steipete/perf-micro-stress-per-turn-allocation-hillclimb-20260919 branch from cd66d6c to 47855e9 Compare October 20, 2026 07:13
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Corrected the stale file test fixtures exposed by CI: matching runtime configuration and real persisted session facts now supply retained authority. File-policy tests: 41 passed / 1 platform skip; repository tests: 16 passed. No production change in the correction; independent review is clean through P2.

@clawsweeper

clawsweeper Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 20, 2026
@steipete

steipete commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Final HTTP disclosure proof on 47855e9228333d864a59b0ee670cca7ef04d00af (the runtime patch is unchanged on the current head) passed through real handleGatewayRequest admission, persisted session entries, and handleArtifactDownloadHttpRequest on loopback HTTP. These are synthetic fixtures. Temporary observation-only print statements captured the values below; the tracked source was restored byte-for-byte afterward.

HTTP_PROOF {"case":"allowed after replica eviction","status":200,"body":"<h1>boo</h1>\n"}
HTTP_PROOF {"case":"same grant after workspace revocation","status":404,"body":"Not Found"}
HTTP_PROOF {"case":"allowed reader before role change","status":200,"body":"host private bytes"}
HTTP_PROOF {"case":"same grant after reader becomes forbidden","status":404,"body":"Not Found"}
Test Files  2 passed (2)
Tests       5 passed (5)

Command: node scripts/run-vitest.mjs src/gateway/server-methods/sessions-files.worktree.test.ts src/gateway/server-methods/sessions-files.sandbox.test.ts --maxWorkers=1.

The worktree case forces actual replica LRU eviction, serves the retained grant, then changes the worktree ID. The sandbox case admits the read-only role, serves its retained grant, then changes that role to require a sandbox before fetching the same URL. Both denied responses are asserted not to contain the protected fixture bytes. This is in-process Gateway admission plus actual HTTP delivery, not a claim of a separate WebSocket process proof.

@clawsweeper clawsweeper Bot added clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 20, 2026
@steipete
steipete force-pushed the steipete/perf-micro-stress-per-turn-allocation-hillclimb-20260919 branch from 47855e9 to d5f68bb Compare October 20, 2026 08:01
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

The final HTTP proof is in the body and the captured trace: permitted downloads return the expected bytes, while the same grant returns 404 after either a workspace change or a newly forbidden reader role.

The remaining heartbeat CI timeout now has a focused fixture correction using the repository's existing beforeAll server-compilation convention. Both actual Gateway starts, restart, route assertions, and the 90-second behavior budget remain unchanged. The corrected test passes; independent review is clean. The branch was rebased on current main with patch-identical runtime changes.

@clawsweeper

clawsweeper Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 20, 2026
@clawsweeper

clawsweeper Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 20, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

CI run 39390399994 on d5f68bb has two independently reproduced baseline failures:

  • src/gateway/x-publication-owner-composition.e2e.test.ts, job 118520893189: the anonymous read expects HTTP 200 but receives HTTP 503 at line 919. The exact unchanged PR parent 40ecdd3e3b82 fails the same assertion with the same response. The pinned PR head passes the focused file. This comparison used one isolated Linux sandbox with two CPU cores and 8 GB memory; the full PR patch was removed for base and restored afterward.
  • src/gateway/worker-environments/worker-turn-launcher.test.ts, job 118520893299: “does not let a stale local finally release a reclaimed run id” expects one durable cleanup row and receives zero. The same focused file failed identically on the PR and unchanged main 8fb3a2007922d5d73a3c72be6a8062aca073c72c (33 passed / 1 failed on each). The test and placement implementation are byte-identical from that baseline through this PR head. Upstream perf(gateway): eliminate local placement claim round trips #178098 moved local claims into memory.

No CI reruns were requested. The PR body includes the regression, real Gateway/HTTP revocation proof, focused checks, and independent reviews.

@steipete
steipete merged commit 6b5279a into main Oct 20, 2026
222 of 228 checks passed
@steipete
steipete deleted the steipete/perf-micro-stress-per-turn-allocation-hillclimb-20260919 branch October 20, 2026 08:42
steipete added a commit that referenced this pull request Oct 20, 2026
A metadata publication between the two worker-read batches can refresh the
selected row, leaving it resident before the fixture reaches revocation.
Install the unchanged sibling rows returned by the worker as one cache-owner
batch, and retain the metadata interleaving as regression coverage.

Keep the exact cache-miss, HTTP content, and revoked-download assertions.
Follow-up to the eviction coverage added in #178173.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 21, 2026
…law#178173)

* fix(gateway): retain workspace authority across session cache eviction

* test(gateway): use live session file authority in fixtures

* test(gateway): prepare heartbeat runtime before behavior timing
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 21, 2026
A metadata publication between the two worker-read batches can refresh the
selected row, leaving it resident before the fixture reaches revocation.
Install the unchanged sibling rows returned by the worker as one cache-owner
batch, and retain the metadata interleaving as regression coverage.

Keep the exact cache-miss, HTTP content, and revoked-download assertions.
Follow-up to the eviction coverage added in openclaw#178173.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling 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