fix: don't nuke agent working dir

This commit is contained in:
Aarnav Tale
2026-03-30 14:02:39 -04:00
parent 838a2cd732
commit 73b5d5514e
+12 -4
View File
@@ -148,13 +148,21 @@ export async function createAgentManager(
try {
stdout = await runAgent(authKey);
} catch (err) {
if (stateExists) {
log.info("agent", "Agent failed with existing state, clearing and retrying");
if (!stateExists) {
throw err;
}
// Retry once with existing state (e.g. stale lock from a previous run)
log.info("agent", "Agent failed with existing state, retrying");
try {
const retryKey = await generateAuthKey();
stdout = await runAgent(retryKey);
} catch {
// Only clear identity as a last resort
log.warn("agent", "Retry failed, clearing state and starting fresh");
await rm(join(workDir, "tailscaled.state"), { force: true });
const freshKey = await generateAuthKey();
stdout = await runAgent(freshKey);
} else {
throw err;
}
}