Skip to content

fix(agents): harden workspace bootstrap cache identity - #72495

Closed
aimqwest wants to merge 2 commits into
openclaw:mainfrom
aimqwest:aimqwest_code/codex0183-workspace-cache-ctime
Closed

aimqwest wants to merge 2 commits into
openclaw:mainfrom
aimqwest:aimqwest_code/codex0183-workspace-cache-ctime

Conversation

@aimqwest

Copy link
Copy Markdown

Objective
Harden the guarded workspace bootstrap file cache identity so an equal-size in-place edit with restored mtime cannot keep stale bootstrap instructions cached. This is the narrow cache-identity follow-up to the security tradeoff surfaced on #72406 and preserves the same long-lived-session refresh objective from #64871.

Deploy-source proof
Branch aimqwest_code/codex0183-workspace-cache-ctime is based on openclaw/openclaw main at 9b79eef75091a8444af822229de00727ba9bcf67. No deployment surface is touched or claimed.

Files changed

  • CHANGELOG.md
  • src/agents/workspace.ts
  • src/agents/workspace.bootstrap-cache.test.ts

Validation

  • pnpm test src/agents/workspace.bootstrap-cache.test.ts - pass, 8 tests
  • pnpm test src/agents/bootstrap-cache.test.ts src/agents/workspace.bootstrap-cache.test.ts - pass, 13 tests
  • pnpm exec oxfmt --check --threads=1 src/agents/workspace.ts src/agents/workspace.bootstrap-cache.test.ts - pass
  • git diff --check - pass
  • pnpm check:changed - pass, lanes core, coreTests, docs
  • Diff credential-pattern scan - pass, no matches

Evidence files

  • /tmp/codex0183_openclaw_ctime_validation.txt
  • /tmp/codex0183_pr72406_failed_logs.txt

Scope statement
OpenClaw workspace bootstrap cache only. No deployment, no production runtime touch, and no AIMQWEST-private workspace content.

Evidence: /tmp/codex0183_openclaw_ctime_validation.txt
Scope: OpenClaw workspace bootstrap cache only (no AIMQWEST-private content)
@greptile-apps

greptile-apps Bot commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds stat.ctimeMs to the workspace bootstrap file cache identity in workspaceFileIdentity, closing the attack vector where an equal-size in-place edit with a restored mtime could keep stale content cached indefinitely. The change is minimal and correct: ctime is kernel-managed and cannot be arbitrarily reset via utimes, making it a reliable discriminator that mtime alone cannot provide.

Confidence Score: 4/5

Safe to merge; single P2 finding is a test-reliability edge case on coarse-timestamp filesystems, not a production defect.

The production change is a correct, well-scoped one-liner. The only concern is that the new test's ctimeMs inequality assertion can fail spuriously on filesystems with 1-second timestamp granularity, which is a P2 style/reliability concern and does not block merging.

src/agents/workspace.bootstrap-cache.test.ts — the ctimeMs inequality assertion at line 106 may be flaky in coarse-timestamp CI environments.

Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/agents/workspace.bootstrap-cache.test.ts
Line: 106

Comment:
**ctime assertion may be flaky on coarse-timestamp filesystems**

`ctimeMs` is compared directly with `toBe` after a same-process `utimes` call. On filesystems with 1-second `ctime` granularity (e.g. tmpfs on some CI hosts, older ext3 mounts, certain Docker/container overlayfs layers) the two `ctime` samples can land in the same tick if the write + restore complete within the same wall-clock second, causing the assertion to fail spuriously even though the production fix is correct.

Consider asserting with a tolerance, or recording `Date.now()` before and after and skipping the assertion when elapsed time is < 1 ms (indicating the timestamps cannot have changed).

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "fix(agents): harden workspace bootstrap ..." | Re-trigger Greptile

expect(updatedStat.ino).toBe(originalStat.ino);
expect(updatedStat.size).toBe(originalStat.size);
expect(updatedStat.mtimeMs).toBe(originalStat.mtimeMs);
expect(updatedStat.ctimeMs).not.toBe(originalStat.ctimeMs);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 ctime assertion may be flaky on coarse-timestamp filesystems

ctimeMs is compared directly with toBe after a same-process utimes call. On filesystems with 1-second ctime granularity (e.g. tmpfs on some CI hosts, older ext3 mounts, certain Docker/container overlayfs layers) the two ctime samples can land in the same tick if the write + restore complete within the same wall-clock second, causing the assertion to fail spuriously even though the production fix is correct.

Consider asserting with a tolerance, or recording Date.now() before and after and skipping the assertion when elapsed time is < 1 ms (indicating the timestamps cannot have changed).

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/workspace.bootstrap-cache.test.ts
Line: 106

Comment:
**ctime assertion may be flaky on coarse-timestamp filesystems**

`ctimeMs` is compared directly with `toBe` after a same-process `utimes` call. On filesystems with 1-second `ctime` granularity (e.g. tmpfs on some CI hosts, older ext3 mounts, certain Docker/container overlayfs layers) the two `ctime` samples can land in the same tick if the write + restore complete within the same wall-clock second, causing the assertion to fail spuriously even though the production fix is correct.

Consider asserting with a tolerance, or recording `Date.now()` before and after and skipping the assertion when elapsed time is < 1 ms (indicating the timestamps cannot have changed).

How can I resolve this? If you propose a fix, please make it concise.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjusted the regression test to avoid relying on direct ctimeMs inequality on coarse-timestamp filesystems. The test now focuses on the observable cache-invalidation behavior: same inode/size/restored mtime edit still reloads the updated bootstrap content. Validation passed locally.

Evidence: pnpm test src/agents/workspace.bootstrap-cache.test.ts; pnpm test src/agents/bootstrap-cache.test.ts src/agents/workspace.bootstrap-cache.test.ts; pnpm exec oxfmt --check --threads=1 src/agents/workspace.ts src/agents/workspace.bootstrap-cache.test.ts; git diff --check; pnpm check:changed

Scope: OpenClaw PR openclaw#72495 branch only; no 7DEA app/api surfaces touched
@clawsweeper

clawsweeper Bot commented Apr 27, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Keep open: current main and v2026.6.11 still use a guarded workspace file identity without ctimeMs, so the narrow cache-hardening change remains useful. This PR is not merge-ready because it still edits release-owned CHANGELOG.md, GitHub reports the branch as conflicting, and the external contributor has not attached inspectable after-fix real behavior proof.

Root-cause cluster
Relationship: canonical
Canonical: #72495
Summary: This PR is the canonical remaining item for the narrow guarded workspace file identity ctimeMs hardening; related merged work fixed broader same-session bootstrap refresh semantics but left the mtime-only identity in current main.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Canonical path: Close this stale PR. The latest review rated it F, the branch still lacks merge-ready proof, and there has been no human follow-up after the durable review.

So I’m closing this here because the remaining work is already tracked in the canonical issue.

Review details

Best possible solution:

Close this stale PR. The latest review rated it F, the branch still lacks merge-ready proof, and there has been no human follow-up after the durable review.

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

Yes, source-reproducible: current main and v2026.6.11 key cached workspace file content without ctimeMs, so an equal-size edit with restored mtime can collide with the existing cache identity. I did not run a live runtime repro in this read-only review.

Is this the best way to solve the issue?

Yes after cleanup: adding metadata-change time to the existing guarded identity is narrower than removing the cache or hashing every read. The submitted branch still needs conflict resolution, changelog removal, and inspectable proof before merge.

Security review:

Security review cleared: Security review cleared: the diff hardens local workspace cache identity and does not change dependencies, workflows, lockfiles, scripts, permissions, downloaded code, or secret handling.

AGENTS.md: found and applied where relevant.

What I checked:

  • stale F-rated PR: PR was opened 2026-04-27T01:56:00Z, is older than 60 days, and the latest review rated it F.
  • proof blocker: real behavior proof is missing and proof tier is F, so this branch is not merge-ready without contributor follow-up.
  • no human follow-up: live comments and timeline hydrated by apply contain no non-automation activity after the ClawSweeper review.

Likely related people:

  • steipete: History shows Peter Steinberger introduced the boundary-safe workspace read/cache identity and earlier per-session bootstrap cache plumbing in the same area. (role: introduced guarded identity behavior and adjacent bootstrap cache owner; confidence: high; commits: 242188b7b14c, 40db3fef4915, e7a49319324c; files: src/agents/workspace.ts, src/agents/bootstrap-cache.ts, src/agents/bootstrap-files.ts)
  • vincentkoc: Merged the related same-session bootstrap refresh work that changed bootstrap-cache.ts, bootstrap-files.ts, and adjacent tests while leaving the lower file identity unchanged. (role: recent adjacent area contributor and merger; confidence: high; commits: 015f7dc7472d; files: src/agents/bootstrap-cache.ts, src/agents/bootstrap-files.ts, src/agents/workspace.bootstrap-cache.test.ts)
  • yozakura-ava: Recently merged a bounded bootstrap snapshot cache cap in the same cache owner area. (role: recent adjacent cache contributor; confidence: medium; commits: 144405e56278; files: src/agents/bootstrap-cache.ts, src/agents/bootstrap-cache.test.ts)

Codex review notes: model internal, reasoning high; reviewed against 36dd9ee3c3c1.

@clawsweeper clawsweeper Bot added 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. P2 Normal backlog priority with limited blast radius. labels May 20, 2026
@clawsweeper

clawsweeper Bot commented May 20, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper PR egg

🎁 Pass real behavior proof to wake the egg and unlock a hatchable treat.

Where did the egg go?
  • The egg game starts only after the PR passes the real-behavior proof check.
  • Before that, no creature or rarity is rolled. The treat waits for real proof.
  • This is still just collectible flavor: proof affects review readiness, not creature quality.

@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. label May 20, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Jun 14, 2026

Copy link
Copy Markdown
Author

Thanks for the stale notice. This PR is still active, but I am not treating it as merge-ready in its current state.

Next update will address the outstanding reviewer/bot asks before requesting re-review:

  • refresh the branch against current openclaw/openclaw:main
  • remove the release-owned CHANGELOG.md entry from the PR
  • attach inspectable, redacted real-behavior proof showing the equal-size/restored-mtime workspace bootstrap reload after the patch

No deployment/runtime impact is claimed for this PR.

@clawsweeper clawsweeper Bot added status: 🛠️ actively grinding The PR author has acted after the latest ClawSweeper review and work remains. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jun 14, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the stale Marked as stale due to inactivity label Jun 15, 2026
@clawsweeper clawsweeper Bot added status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed status: 🛠️ actively grinding The PR author has acted after the latest ClawSweeper review and work remains. 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. labels Jun 15, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added stale Marked as stale due to inactivity triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Jul 18, 2026
@clawsweeper

clawsweeper Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper status: review started.

I am starting a fresh review of this pull request: fix(agents): harden workspace bootstrap cache identity This is item 1/1 in the current shard. Shard 0/1.

This placeholder means the worker is alive and reading the current context. I will edit this same comment with the actual review when the claws are done clicking.

Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted.

@openclaw-barnacle openclaw-barnacle Bot removed the stale Marked as stale due to inactivity label Jul 19, 2026
@steipete

Copy link
Copy Markdown
Contributor

Closing per ClawSweeper review verdict stalled_unproven_pr (decision packet 2026-07-18T07:19:26.973Z). This item was part of the audited close backlog (openclaw/clawsweeper#920) stranded by an apply-lane defect, drained manually after re-verification. If this is wrong, reopen and ClawSweeper will re-review.

@steipete steipete closed this Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: XS status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants