Repository navigation
fix: stop stale file writes after session database replacement - #202644
Conversation
|
🦞👀 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. |
Baseline-Refresh: 8f3f33cf8b2404dc2d7ba0959b1640003e353c2a
|
Codex review: needs maintainer review before merge. What this changesThis PR prevents retained session tools from modifying host files after their session database is replaced. Example: A background session retains its write tool while its SQLite database is replaced.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Regression provenancePossible regression — probable (reviewed change; failure trace). No predecessor PR is attributed. Merge readiness✅ Ready for maintainer review Keep this PR open: it repairs a verified current-main storage-fence regression, and source review found no actionable introduced defect. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherSession-generation ownership supplies database custody to admitted agent tools; host filesystem owners consume that custody before write, edit, create, and delete effects. flowchart TD
A[Background session] --> B[Tool admission]
B --> C[Session generation owner]
C --> D[Session worker identity validation]
D --> E[Retained storage assertion]
E --> F[Host filesystem mutation]
Technical reviewBest possible solution: Keep storage custody in the existing generation owner and enforce it through the shared file writers while preserving permission admission semantics. Do we have a high-confidence way to reproduce the issue? The existing regression swaps the physical database before invoking a retained write tool, and linked main CI independently records the resulting wrong file bytes; this review ran no target code. Is this the best way to solve the issue? The change restores the missing storage boundary using existing generation, worker, adapter, and filesystem owners without restoring ambient permission rechecks or introducing persistent state. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 302e9154aeb2. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +168, Tests +100, Docs -2. Total +266 across 24 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
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 November 20, 2026, 1:29 PM ET / 18:29 UTC. |
|
|
Merged via explicitly authorized admin squash with attributed pre-existing CI failures.
|
…law#202644) * fix: stop stale file writes after session database replacement * test(gateway): accept either current-owner retirement refusal
* fix: keep agent temporary files in owned scratch * fix: preserve sandbox temp access and queued isolation custody (cherry picked from commit f91bc99) Release adaptation: keep the staged #202815 Git shim implementation and independently assert both Git shim execution and writable owned temp in its merged Docker/Podman fixture. Use the beta.3 isolated custody configuration (896f33d52174), not ambient sandbox inventory. Companions: #193677 scratch expiry owner is present (99ba844); #202815 is present-equivalent (7d33d1a). #202122 is independent Git/scratch clone reclamation, #202428 is CLI history ownership, #202644 is host file-write authority, and #202874 is workspace cleanup scheduling; none prerequisite. Other later same-path commits concern separate template, sandbox, prompt, sharing, or run-lifecycle policy; see the lane companion audit. Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit a4070bc5b669308210b62a0b80b92c16af768b34)
Backport only the existing E2E assertion from d14c98b (#202644); the unrelated production refactor is out of scope. Co-authored-by: RomneyDa <[email protected]>
What Problem This Solves
Replacing an agent's session database could leave tools from a retained background session able to modify files. The existing database-replacement regression on main demonstrated the stale write.
User Impact
Retained sessions refuse host file mutations after their database is replaced. Already-admitted calls keep the existing permission-change behavior. No configuration or migration is required.
Why This Change Was Made
Carry explicit storage preparation from the session-generation owner through tool admission and host write, edit, and patch operations. The session worker validates the physical database; the final mutation check uses the retained in-memory admission. This restores the storage fence without synchronous filesystem/SQL probes or ambient permission rechecks.
The write owner also absorbs redundant outer directory creation. The remaining adapters preserve the same storage capability.
Evidence
Existing main failures: https://github.com/openclaw/openclaw/actions/runs/44773320124/job/136417317466 and https://github.com/openclaw/openclaw/actions/runs/44783201838/job/136452097158.
Reproduced on base
1129d4c0716c7dcc6fba86753ec214584ec8ebd1: replacing the database let the retained write changeoriginaltocompleted.Fixed production admission regression passes on isolated Linux/Node 24.22.1: the write reports
SESSION_DELIVERY_GENERATION_UNAVAILABLE, and the original file remains intact. The other 33 session-event cases passed unchanged.16 host-write integrity tests, 15 source-authority tests, native generation checks including the no-main-thread-probes case, and 62 Gateway, session-event handoff, cron admission, and harness lifetime tests passed.
Four compiler scopes and formatting of all 24 changed files passed. The final source change after those runtime checks only renames a shadowed local variable.
Local ClawSweeper reviewed the complete committed range
1129d4c0716c7dcc6fba86753ec214584ec8ebd1..106f70f194fe5d4ddace1972b1cf112a9dc22104with high reasoning: no actionable correctness findings; security cleared. The reviewer did not execute tests.Exact-head CI on the original candidate passed the build and final lint checks: https://github.com/openclaw/openclaw/actions/runs/44790529249.
Refreshed onto
31ce94f0ad89639e4cf3a0b77edddb0a010f6aaabecause the UI comparison used newer baseline inputs. The full database patch is byte-identical before and after the native refresh.Corrected the X retirement assertion to accept either existing owner guard, retaining checks for no child creation, no extra public share, and no success reply.
Local ClawSweeper reviewed the complete refreshed range
31ce94f0ad89639e4cf3a0b77edddb0a010f6aaa..a7b20c4e814b81133eed786ecacccf183529b77dat high reasoning: no actionable correctness or security findings. The reviewer did not run tests.Exact refreshed-head CI passed the UI differential and the X production-owner test (1/1): https://github.com/openclaw/openclaw/actions/runs/44794144114. Production/test types, core/general lint, and dependency checks passed.
The exact-head manual CI run completed with five failing test jobs plus its aggregate gate. Four test jobs match stale admitted-call expectations repaired in #202655. The remaining real-Gateway test rejected the synthetic key correctly but took 2.745 seconds against its 2-second limit (job https://github.com/openclaw/openclaw/actions/runs/44794144114/job/136490200232). That Save/auth/probe path performs a zero-tool isolated completion and does not call the changed session/file storage hook; its source inputs are unchanged by this patch. The latency cause remains unresolved; no threshold was raised and no repair is claimed. Normal PR CI 44796218464 has also completed: 53 successful jobs, 25 skips, five test failures and the failed aggregate gate. Four node jobs have the same stale admitted-call expectations repaired in PR202655. The fifth is route asset requests: plugin and skill readiness timeouts plus 32 requests against a 31-request skill-settings limit. These browser tests use mocked Gateway responses and do not execute this storage admission path. The complete UI and scripts/lib trees and all four failing node test files are identical between baseline and the tested two-parent merge. Their causes remain visible; this PR claims no fix for those browser failures.