Repository navigation
fix(agents): refresh bootstrap snapshot when workspace files change - #72406
Conversation
🔒 Aisle Security AnalysisWe found 1 potential security issue(s) in this PR:
1. 🟡 Hook-injected bootstrap files can preempt workspace policy files due to first-wins deduplication
Description
If a hook injects a duplicate path for a trusted workspace bootstrap file (e.g., 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. RecommendationEnforce deterministic precedence so trusted workspace files cannot be overridden by hook-injected duplicates. Options:
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., Analyzed PR: #72406 at commit Last updated on: 2026-04-27T06:37:37Z |
Greptile SummaryThis PR changes Confidence Score: 5/5Safe 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 |
|
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. |
|
I opened #72495 as a narrow follow-up for the cache-identity portion of the security feedback here: it adds 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. |
|
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. |
2043866 to
6c3b993
Compare
6c3b993 to
ff9dfa8
Compare
…penclaw#72406) * fix(agents): refresh bootstrap snapshot when workspace files change * fix(clownfish): address review for ghcrawl-207042-agentic-merge (1)
…penclaw#72406) * fix(agents): refresh bootstrap snapshot when workspace files change * fix(clownfish): address review for ghcrawl-207042-agentic-merge (1)
…penclaw#72406) * fix(agents): refresh bootstrap snapshot when workspace files change * fix(clownfish): address review for ghcrawl-207042-agentic-merge (1)
…penclaw#72406) * fix(agents): refresh bootstrap snapshot when workspace files change * fix(clownfish): address review for ghcrawl-207042-agentic-merge (1)
…penclaw#72406) * fix(agents): refresh bootstrap snapshot when workspace files change * fix(clownfish): address review for ghcrawl-207042-agentic-merge (1)
…penclaw#72406) * fix(agents): refresh bootstrap snapshot when workspace files change * fix(clownfish): address review for ghcrawl-207042-agentic-merge (1)
Summary
Credit
Based on the contributor work by @aimqwest in #64871. Related earlier cache-staleness work was proposed by @mikejuyoon in #43901.
Validation
ProjectClownfish replacement details:
Finished in 939ms on 4 files using 4 threads.
tool-display snapshot is up to date
OK apps/macos/Sources/OpenClaw/HostEnvSecurityPolicy.generated.swift
::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.