Skip to content

Fix main-session workspace reload after on-disk bootstrap/context updates - #64871

Closed
aimqwest wants to merge 1 commit into
openclaw:mainfrom
aimqwest:aimqwest_codex/0358-main-session-workspace-reload
Closed

aimqwest wants to merge 1 commit into
openclaw:mainfrom
aimqwest:aimqwest_codex/0358-main-session-workspace-reload

Conversation

@aimqwest

Copy link
Copy Markdown

Objective
Fix a long-lived session bug where on-disk workspace bootstrap/context updates were not reflected in subsequent turns for the same session unless the bootstrap snapshot was explicitly cleared or the session was reset.

Deploy-source proof
This change is for openclaw/openclaw and is based on the local reproduction and validation branch aimqwest_codex/0358-main-session-workspace-reload pushed to aimqwest/openclaw. There is no deployment claim in this PR; the source proof is the code diff plus the local validation artifacts listed below.

Problem
getOrLoadBootstrapFiles cached workspace bootstrap files forever per sessionKey. After the first turn, later turns in the same long-lived session reused that cached snapshot without checking whether AGENTS.md, SOUL.md, MEMORY.md, TOOLS.md, or other bootstrap files had changed on disk.

Root cause
The session bootstrap cache was keyed only by sessionKey and treated the first loaded file set as authoritative for the life of that session. loadWorkspaceBootstrapFiles already has file-identity-aware reads, but bootstrap-cache.ts never reloaded the file set to see whether it had changed.

Fix

  • reload the workspace bootstrap file set on each access for an existing session key
  • compare the fresh file list to the cached snapshot
  • reuse the cached snapshot object only when the file set is unchanged
  • replace the cached snapshot when content/path/missing-state differs

This keeps the session-local snapshot stable when nothing changed, while allowing same-session bootstrap refresh after on-disk workspace updates.

Tests

  • updated src/agents/bootstrap-cache.test.ts
  • added regression coverage for unchanged content reusing the cached snapshot object
  • added regression coverage for changed bootstrap content refreshing the session snapshot
  • preserved coverage for session isolation and explicit snapshot clearing

Why scope is intentionally narrow
This PR only adjusts bootstrap snapshot refresh semantics and the directly related unit tests. It does not change workspace file discovery rules, hook behavior, session routing, or any product-specific workspace content.

Files changed

  • src/agents/bootstrap-cache.ts
  • src/agents/bootstrap-cache.test.ts

Validation

  • pnpm exec vitest run --config vitest.config.ts src/agents/bootstrap-cache.test.ts src/agents/workspace.bootstrap-cache.test.ts — pass
  • pnpm build — pass
  • git diff --check — pass
  • pnpm check — blocked by unrelated existing lint failures in src/channels/plugins/config-writes.ts on this checkout; see evidence file
  • local same-session sentinel validation on a live OpenClaw runtime — pass

Evidence files

  • /tmp/codex0357_live_reload_baseline.json
  • /tmp/codex0357_live_reload_after_add.json
  • /tmp/codex0357_live_reload_after_remove.json
  • /tmp/codex0357_hotreload_same_session.json
  • /tmp/codex0358_pnpm_check.txt

Scope statement
Focused runtime bug fix only. No AIMQWEST-private workspace content, no docs bundle, no unrelated refactors.

AI assistance

  • AI-assisted: yes
  • Testing: targeted tests + build + live runtime reproduction/verification

Evidence: /tmp/codex0357_live_reload_baseline.json /tmp/codex0357_live_reload_after_add.json /tmp/codex0357_live_reload_after_remove.json /tmp/codex0357_hotreload_same_session.json /tmp/codex0358_pnpm_check.txt

Scope: dev.7dea.ai/api-dev.7dea.ai only (no app.7dea.ai/api.7dea.ai)
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Apr 11, 2026
@greptile-apps

greptile-apps Bot commented Apr 11, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a long-lived session bug where workspace bootstrap files (AGENTS.md, SOUL.md, etc.) were cached forever after the first load, so on-disk updates were invisible to subsequent turns in the same session. The fix reloads files on every access, compares the fresh result against the cached snapshot using a field-by-field equality check, and returns the existing object reference only when the content is unchanged — preserving object-identity stability for downstream consumers.

The equality helpers correctly cover all four WorkspaceBootstrapFile fields, index-based comparison is safe because loadWorkspaceBootstrapFiles returns entries in a fixed order, and the missing/undefined content edge case is handled correctly. The one behavioral trade-off is that loadWorkspaceBootstrapFiles (up to 8 file reads per call) now runs unconditionally on every turn instead of only on the first, which is noted as a P2 suggestion inline.

Confidence Score: 5/5

Safe to merge — the fix is correct, tests cover the new semantics, and the only open item is a P2 performance note about disk reads per turn.

All findings are P2 (style/performance) with no correctness, data-integrity, or security concerns. The equality logic is complete and correct, session isolation is preserved, and the test suite adequately covers the changed behavior.

No files require special attention.

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

Comment:
**Cache no longer avoids disk I/O**

`loadWorkspaceBootstrapFiles` now runs unconditionally on every call — reading up to 8 workspace files from disk per turn. Before this PR the cache short-circuited at the `Map` lookup, so subsequent turns paid O(1); now every turn pays O(disk reads), and the `Map` only preserves object-reference identity when content is unchanged.

For typical home-directory markdown files the OS page-cache keeps individual reads fast, but the semantics change is worth being explicit about: this is no longer a "load-once" cache; it is a "compare-on-every-access" refresh loop. If per-turn latency becomes a concern, a lightweight mtime-check or debounced TTL window (e.g. re-read at most once per N seconds) would restore disk-I/O avoidance without giving up change detection.

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

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

Comment on lines +31 to 37
const files = await loadWorkspaceBootstrapFiles(params.workspaceDir);
const existing = cache.get(params.sessionKey);
if (existing) {
if (existing && bootstrapSnapshotEquals(existing, files)) {
return existing;
}

const files = await loadWorkspaceBootstrapFiles(params.workspaceDir);
cache.set(params.sessionKey, files);
return files;

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 Cache no longer avoids disk I/O

loadWorkspaceBootstrapFiles now runs unconditionally on every call — reading up to 8 workspace files from disk per turn. Before this PR the cache short-circuited at the Map lookup, so subsequent turns paid O(1); now every turn pays O(disk reads), and the Map only preserves object-reference identity when content is unchanged.

For typical home-directory markdown files the OS page-cache keeps individual reads fast, but the semantics change is worth being explicit about: this is no longer a "load-once" cache; it is a "compare-on-every-access" refresh loop. If per-turn latency becomes a concern, a lightweight mtime-check or debounced TTL window (e.g. re-read at most once per N seconds) would restore disk-I/O avoidance without giving up change detection.

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

Comment:
**Cache no longer avoids disk I/O**

`loadWorkspaceBootstrapFiles` now runs unconditionally on every call — reading up to 8 workspace files from disk per turn. Before this PR the cache short-circuited at the `Map` lookup, so subsequent turns paid O(1); now every turn pays O(disk reads), and the `Map` only preserves object-reference identity when content is unchanged.

For typical home-directory markdown files the OS page-cache keeps individual reads fast, but the semantics change is worth being explicit about: this is no longer a "load-once" cache; it is a "compare-on-every-access" refresh loop. If per-turn latency becomes a concern, a lightweight mtime-check or debounced TTL window (e.g. re-read at most once per N seconds) would restore disk-I/O avoidance without giving up change detection.

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

@aimqwest

Copy link
Copy Markdown
Author

Maintainer handoff: this PR is intentionally narrow.

It fixes a long-lived main-session reload issue where on-disk bootstrap/context file updates were not reflected on later turns without a fresh session. The change keeps the existing behavior surface small, adds focused regression coverage for same-session reload, and does not include any private/local workspace content.

Current status:

  • PR is clean and mergeable
  • CI is green
  • Scope is limited to the reload/cache path relevant to workspace bootstrap/context refresh

Happy to adjust if you’d prefer a different reload boundary, but this should be ready for maintainer review/merge.

@aimqwest

Copy link
Copy Markdown
Author

@joshavant Friendly nudge when you have a moment: this PR is clean, CI is green, and the maintainer handoff summary is already in-thread above. #64871

@vincentkoc

Copy link
Copy Markdown
Member

ProjectClownfish could not safely update this branch, so it opened a narrow replacement PR instead.

Replacement PR: #72406
Source PR: #64871
Contributor credit is preserved in the replacement PR body and changelog plan.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants