Skip to content

fix(agents): refresh bootstrap snapshot when workspace files change - #72406

Merged
vincentkoc merged 2 commits into
mainfrom
clownfish/ghcrawl-207042-agentic-merge
Apr 27, 2026
Merged

vincentkoc merged 2 commits into
mainfrom
clownfish/ghcrawl-207042-agentic-merge

Conversation

@vincentkoc

Copy link
Copy Markdown
Member

Summary

  • Repairs and validates the narrow cache-refresh path from Fix main-session workspace reload after on-disk bootstrap/context updates #64871 so long-lived sessions see on-disk workspace bootstrap/context updates on later turns.
  • Keeps the existing cache object identity when file contents are unchanged where practical.
  • Addresses or explicitly documents the Greptile P2 performance tradeoff around per-turn workspace file reads.

Credit

Based on the contributor work by @aimqwest in #64871. Related earlier cache-staleness work was proposed by @mikejuyoon in #43901.

Validation

  • pnpm check:changed
  • Codex /review clean before merge consideration

ProjectClownfish replacement details:

[email protected] check /tmp/projectclownfish-fix-6h51Pt/openclaw-openclaw
pnpm check:no-conflict-markers && pnpm tool-display:check && pnpm check:host-env-policy:swift && pnpm tsgo && node scripts/prepare-extension-package-boundary-artifacts.mjs && pnpm lint && pnpm lint:webhook:no-low-level-body-read && pnpm lint:auth:no-pairing-store-group && pnpm lint:auth:pairing-account-scope

[email protected] check:no-conflict-markers /tmp/projectclownfish-fix-6h51Pt/openclaw-openclaw
node scripts/check-no-conflict-markers.mjs

[email protected] tool-display:check /tmp/projectclownfish-fix-6h51Pt/openclaw-openclaw
node --import tsx scripts/tool-display.ts --check

tool-display snapshot is up to date

[email protected] check:host-env-policy:swift /tmp/projectclownfish-fix-6h51Pt/openclaw-openclaw
node scripts/generate-host-env-security-policy-swift.mjs --check

OK apps/macos/Sources/OpenClaw/HostEnvSecurityPolicy.generated.swift

[email protected] tsgo /tmp/projectclownfish-fix-6h51Pt/openclaw-openclaw
node scripts/run-tsgo.mjs

[email protected] lint /tmp/projectclownfish-fix-6h51Pt/openclaw-openclaw
node scripts/run-oxlint.mjs

::error file=src/channels/plugins/config-writes.ts,line=15,endLine=15,col=53,endColumn=62,title=typescript-eslint(no-unnecessary-type-arguments)::This is the default value for this type parameter, so it can be omitted.
::error file=src/channels/plugins/config-writes.ts,line=16,endLine=16,col=55,endColumn=64,title=typescript-eslint(no-unnecessary-type-arguments)::This is the default value for this type parameter, so it can be omitted.
::error file=src/channels/plugins/config-writes.ts,line=17,endLine=17,col=81,endColumn=90,title=typescript-eslint(no-unnecessary-type-arguments)::This is the default value for this type parameter, so it can be omitted.

Found 0 warnings and 3 errors.
 ELIFECYCLE  Command failed with exit code 1.
 ELIFECYCLE  Command failed with exit code 1.

@aisle-research-bot

aisle-research-bot Bot commented Apr 26, 2026 •

Copy link
Copy Markdown

🔒 Aisle Security Analysis

We found 1 potential security issue(s) in this PR:

# Severity Title
1 🟡 Medium Hook-injected bootstrap files can preempt workspace policy files due to first-wins deduplication
1. 🟡 Hook-injected bootstrap files can preempt workspace policy files due to first-wins deduplication
Property Value
Severity Medium
CWE CWE-840
Location src/agents/bootstrap-files.ts:148-173

Description

resolveBootstrapFilesForRun() loads workspace bootstrap files and then calls applyBootstrapHookOverrides(), allowing hooks to arbitrarily reorder or prepend entries. sanitizeBootstrapFiles() then deduplicates by a workspace-relative key and keeps the first occurrence, dropping later duplicates.

If a hook injects a duplicate path for a trusted workspace bootstrap file (e.g., AGENTS.md, SOUL.md) before the workspace’s own entry, the hook-provided content will be kept and the workspace file will be discarded. This enables prompt/policy injection via hooks and can change agent behavior (e.g., disabling safety rules) even when the workspace contains the intended guidance.

Vulnerable logic:

const updated = await applyBootstrapHookOverrides({ files: bootstrapFiles, ... });
...
const dedupeKey = path.normalize(path.relative(workspaceRoot, resolvedPath));
if (seenPaths.has(dedupeKey)) {
  continue; // later (workspace) duplicate is dropped
}
seenPaths.add(dedupeKey);
sanitized.push({ ...file, path: resolvedPath });

The added test only covers a hook that appends duplicates; it does not prevent a hook from prepending duplicates (or reordering), which would invert precedence.

Recommendation

Enforce deterministic precedence so trusted workspace files cannot be overridden by hook-injected duplicates.

Options:

  1. Prefer workspace files over hooks (recommended if hooks are less trusted): after hooks run, re-merge so workspace entries win.

  2. Last-wins dedupe (if later entries should override earlier): when a duplicate key is seen, replace the existing entry rather than skipping.

Example: last-wins while preserving final order:

const indexByKey = new Map<string, number>();
for (const file of files) {
  ...
  const key = path.normalize(path.relative(workspaceRoot, resolvedPath));
  const prior = indexByKey.get(key);
  const sanitizedEntry = { ...file, path: resolvedPath };
  if (prior === undefined) {
    indexByKey.set(key, sanitized.length);
    sanitized.push(sanitizedEntry);
  } else {
    sanitized[prior] = sanitizedEntry; // replace instead of dropping
  }
}

Also consider separating hook-injected files from workspace policy files entirely, or explicitly preventing hooks from modifying critical filenames (e.g., AGENTS.md) unless explicitly allowed by configuration.


Analyzed PR: #72406 at commit ff9dfa8

Last updated on: 2026-04-27T06:37:37Z

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S maintainer Maintainer-authored PR labels Apr 26, 2026
@greptile-apps

greptile-apps Bot commented Apr 26, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR changes getOrLoadBootstrapFiles from a pure cache-hit/miss pattern to an always-reload pattern: it calls loadWorkspaceBootstrapFiles on every invocation, then uses a field-by-field equality check (bootstrapFilesEqual) to preserve array reference identity when file contents are unchanged. The integration test in workspace.bootstrap-cache.test.ts validates the end-to-end refresh path with real filesystem writes and mtime bumps, covering the scenario described in #64871.

Confidence Score: 5/5

Safe to merge; logic is correct, tests are well-structured, and the performance tradeoff is already documented.

No P0 or P1 issues found. The bootstrapFilesEqual comparison correctly covers all four fields of WorkspaceBootstrapFile. Order-sensitivity is safe because loadWorkspaceBootstrapFiles returns files in a hardcoded, deterministic order. The one variable-length case (MEMORY.md skipped when absent) is handled correctly by the previous.length !== next.length guard. The per-turn disk call cost is mitigated by the existing inode/mtime cache in readWorkspaceFileWithGuards. Tests cover identity preservation, content-change detection, independent session keys, and the clear+refresh path.

No files require special attention.

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

Copy link
Copy Markdown

Thank you for preserving the contributor credit from #64871 and for opening this narrow replacement PR.

I appreciate the explicit attribution to @aimqwest as the author of the canonical source PR. Please keep that credit visible in the final merged PR body and any related changelog/release notes.

I also support any maintainer refinements needed to address the cache-refresh/security tradeoffs while preserving the original objective: ensuring long-lived sessions can detect legitimate on-disk bootstrap/context updates without requiring a full session reset.

Copy link
Copy Markdown

I opened #72495 as a narrow follow-up for the cache-identity portion of the security feedback here: it adds ctimeMs to the guarded workspace file cache identity and includes a regression test for same-inode, same-size, restored-mtime edits.

I intentionally did not change the broader per-turn refresh behavior in #72406, since disabling refresh by default would cut against the original objective from #64871. That part seems better treated as a maintainer policy/design decision around trusted workspace assumptions, while #72495 handles the stale-cache bypass directly.

@aimqwest

Copy link
Copy Markdown

For clarity, AIMQWEST CORPORATION’s contribution here is limited to the technical bootstrap/cache-refresh code path discussed in #64871 and #72406. No AIMQWEST private workspace content, Seven Directives doctrine, 7DEA framework IP, AIMQWEST books, trademarks, or proprietary commercial materials are contributed or licensed through this PR beyond the specific code changes submitted to this repository under the repository’s applicable contribution/license terms.

This clarification is intended only to preserve scope and attribution boundaries while supporting the maintainer-led implementation path.

@vincentkoc
vincentkoc force-pushed the clownfish/ghcrawl-207042-agentic-merge branch from 6c3b993 to ff9dfa8 Compare April 27, 2026 06:35
@vincentkoc
vincentkoc merged commit 015f7dc into main Apr 27, 2026
67 checks passed
@vincentkoc
vincentkoc deleted the clownfish/ghcrawl-207042-agentic-merge branch April 27, 2026 06:39
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
…penclaw#72406)

* fix(agents): refresh bootstrap snapshot when workspace files change

* fix(clownfish): address review for ghcrawl-207042-agentic-merge (1)
globalcaos pushed a commit to globalcaos/tinkerclaw that referenced this pull request May 13, 2026
…penclaw#72406)

* fix(agents): refresh bootstrap snapshot when workspace files change

* fix(clownfish): address review for ghcrawl-207042-agentic-merge (1)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
…penclaw#72406)

* fix(agents): refresh bootstrap snapshot when workspace files change

* fix(clownfish): address review for ghcrawl-207042-agentic-merge (1)
jameslcowan pushed a commit to jameslcowan/openclaw that referenced this pull request Jun 2, 2026
…penclaw#72406)

* fix(agents): refresh bootstrap snapshot when workspace files change

* fix(clownfish): address review for ghcrawl-207042-agentic-merge (1)
sablehead pushed a commit to sablehead/openclaw that referenced this pull request Jun 10, 2026
…penclaw#72406)

* fix(agents): refresh bootstrap snapshot when workspace files change

* fix(clownfish): address review for ghcrawl-207042-agentic-merge (1)
vixco pushed a commit to vixco/openclaw that referenced this pull request Aug 16, 2026
…penclaw#72406)

* fix(agents): refresh bootstrap snapshot when workspace files change

* fix(clownfish): address review for ghcrawl-207042-agentic-merge (1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling clawsweeper Tracked by ClawSweeper automation maintainer Maintainer-authored PR size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants