fix(rules-injector): retry storage writes after cleanup race
The full Bun suite can remove the shared rules-injector storage directory between a parent-directory check and the file write. Save operations now create the directory immediately before writing and retry once if ENOENT still wins the race. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -37,10 +37,6 @@ export function saveInjectedRules(
|
|||||||
sessionID: string,
|
sessionID: string,
|
||||||
data: { contentHashes: Set<string>; realPaths: Set<string> }
|
data: { contentHashes: Set<string>; realPaths: Set<string> }
|
||||||
): void {
|
): void {
|
||||||
if (!existsSync(RULES_INJECTOR_STORAGE)) {
|
|
||||||
mkdirSync(RULES_INJECTOR_STORAGE, { recursive: true });
|
|
||||||
}
|
|
||||||
|
|
||||||
const storageData: InjectedRulesData = {
|
const storageData: InjectedRulesData = {
|
||||||
sessionID,
|
sessionID,
|
||||||
injectedHashes: [...data.contentHashes],
|
injectedHashes: [...data.contentHashes],
|
||||||
@@ -48,7 +44,16 @@ export function saveInjectedRules(
|
|||||||
updatedAt: Date.now(),
|
updatedAt: Date.now(),
|
||||||
};
|
};
|
||||||
|
|
||||||
writeFileSync(getStoragePath(sessionID), JSON.stringify(storageData, null, 2));
|
mkdirSync(RULES_INJECTOR_STORAGE, { recursive: true });
|
||||||
|
try {
|
||||||
|
writeFileSync(getStoragePath(sessionID), JSON.stringify(storageData, null, 2));
|
||||||
|
} catch (error) {
|
||||||
|
if (!(error instanceof Error) || !("code" in error) || error.code !== "ENOENT") {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
mkdirSync(RULES_INJECTOR_STORAGE, { recursive: true });
|
||||||
|
writeFileSync(getStoragePath(sessionID), JSON.stringify(storageData, null, 2));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function clearInjectedRules(sessionID: string): void {
|
export function clearInjectedRules(sessionID: string): void {
|
||||||
|
|||||||
Reference in New Issue
Block a user