Skip to content

fix: stop stale file writes after session database replacement - #202644

Merged
vincentkoc merged 3 commits into
mainfrom
fix-ci-retained-database-identity-20261121
Nov 20, 2026
Merged

vincentkoc merged 3 commits into
mainfrom
fix-ci-retained-database-identity-20261121

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

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

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.

@vincentkoc vincentkoc self-assigned this Nov 20, 2026
@clawsweeper

clawsweeper Bot commented Nov 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: M labels Nov 20, 2026
@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 Nov 20, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. 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 Nov 20, 2026
@clawsweeper

clawsweeper Bot commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

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

  • Before: The retained tool changes completion.txt from "original\n" to "completed\n".
  • After: The write fails with SESSION_DELIVERY_GENERATION_UNAVAILABLE and preserves "original\n".

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The source repair is coherent with no actionable findings, but required shipped-entry-point proof is absent and failing CI attribution remains incomplete.
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) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A retained background session can modify host files after its original session database has been replaced.
Reason: The existing regression defines the storage invariant, and maintainer authorship supplies direction for restoring it without changing admitted-call permission behavior.

Regression provenance

Possible 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
Reviewed head: 106f70f194fe5d4ddace1972b1cf112a9dc22104

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Supply redacted Gateway logs or terminal output showing a real agent's retained file write refused after database replacement, with the original bytes preserved.
Agent review details

How this fits together

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

Technical review

Best 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

  • Host file mutation admission keeps the original intent (c23cb9f: Remove authority rechecks from already-started calls while preserving cancellation, filesystem containment, and storage fences.)
  • Worker-prepared generation effects and adapter propagation changes intended behavior with a stated reason (b1a2aa2: Move physical-identity and native-revision preparation off the Gateway thread while retaining final effect checks.)
  • Shared in-place host writer keeps the original intent (a9b5e2e: Preserve original file bytes after failed writes without replacing the inode or hard links.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit b1a2aa2 adds src/config/sessions/session-delivery-generation.ts:553 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: b1a2aa2c3f32; files: src/config/sessions/session-delivery-generation.ts)
  • Vincent Koc: Raw commit 625945b adds src/agents/embedded-agent-runner/run/attempt-tool-prepare.ts:19 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 625945b7ae01; files: src/agents/embedded-agent-runner/run/attempt-tool-prepare.ts)

PR surface

Source +168, Tests +100, Docs -2. Total +266 across 24 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 19 239 71 +168
Tests 4 106 6 +100
Docs 1 6 8 -2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 24 351 85 +266

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 P2: Stale file mutations after database replacement are a concrete integrity regression with a limited trigger.
  • add merge-risk: 🚨 compatibility: The optional storage-preparation member reaches SDK-exported source-authority types; existing signatures remain compatible, and this maintainer-authored repair supplies direction for the additive change.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: Stale file mutations after database replacement are a concrete integrity regression with a limited trigger.
  • merge-risk: 🚨 compatibility: The optional storage-preparation member reaches SDK-exported source-authority types; existing signatures remain compatible, and this maintainer-authored repair supplies direction for the additive change.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Provide the missing Gateway behavior evidence with IPs, API keys, phone numbers, and non-public endpoints redacted.
  • Classify the failing exact-head checks using inspectable failure output and matching baseline evidence where applicable.

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 20, 2026, 1:29 PM ET / 18:29 UTC.

@vincentkoc
vincentkoc marked this pull request as ready for review November 20, 2026 18:48
@github-actions

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: a7b20c4e814b81133eed786ecacccf183529b77d
  • Maintainer: @vincentkoc
  • Repository role: admin

These security sensitive changes were made:

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

Carefully review these changes before merging.

@vincentkoc
vincentkoc merged commit d14c98b into main Nov 20, 2026
324 of 337 checks passed
@vincentkoc
vincentkoc deleted the fix-ci-retained-database-identity-20261121 branch November 20, 2026 19:21
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 21, 2026
…law#202644)

* fix: stop stale file writes after session database replacement

* test(gateway): accept either current-owner retirement refusal
tideclaw-bot pushed a commit that referenced this pull request Nov 24, 2026
* 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)
tideclaw-bot added a commit that referenced this pull request Nov 24, 2026
Backport only the existing E2E assertion from d14c98b (#202644); the unrelated production refactor is out of scope.

Co-authored-by: RomneyDa <[email protected]>
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 merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. security-sensitive-changed size: M 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