fix: stop agent crashing on Mongo errors during live loop
A Mongo auth/connection failure in getGitStates escaped uncaught and killed the agent process on the first screen frame, so collision detection never ran. Make git-state fusion best-effort (degrade to vision-only) and wrap the whole onScreenFrame loop so no per-frame Gemini/GitHub/Mongo error can crash the long-running agent. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaCFWMkYQmTcuPsxaaACft
This commit is contained in:
+19
-13
@@ -43,21 +43,27 @@ export class PodMan {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async onScreenFrame(engineerId: string, jpeg: Buffer): Promise<void> {
|
async onScreenFrame(engineerId: string, jpeg: Buffer): Promise<void> {
|
||||||
const ctx = await analyzeFrame(engineerId, this.podId, jpeg);
|
// Whole-frame guard: a Gemini/GitHub/Mongo failure on one frame must degrade
|
||||||
this.contexts.set(engineerId, ctx);
|
// gracefully, never crash the long-running live agent loop.
|
||||||
await recordObservation(ctx);
|
try {
|
||||||
|
const ctx = await analyzeFrame(engineerId, this.podId, jpeg);
|
||||||
|
this.contexts.set(engineerId, ctx);
|
||||||
|
await recordObservation(ctx);
|
||||||
|
|
||||||
// Fuse git ground truth: engineer_states written by scripts/podman-agent.mjs.
|
// Fuse git ground truth: engineer_states written by scripts/podman-agent.mjs.
|
||||||
// Keyed by name (matches --name arg), same as LiveKit participant identity.
|
// Keyed by name (matches --name arg), same as LiveKit participant identity.
|
||||||
const gitStates = await getGitStates(this.podId);
|
const gitStates = await getGitStates(this.podId);
|
||||||
for (const [id, c] of this.contexts) {
|
for (const [id, c] of this.contexts) {
|
||||||
const git = gitStates.get(id);
|
const git = gitStates.get(id);
|
||||||
if (git && git.changedFiles.length > 0) c.hasUnpushedChanges = true;
|
if (git && git.changedFiles.length > 0) c.hasUnpushedChanges = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const github = await getGithubState(); // cached
|
||||||
|
const collisions = detectCollisions([...this.contexts.values()], github);
|
||||||
|
for (const collision of collisions) await this.handle(collision);
|
||||||
|
} catch (err) {
|
||||||
|
console.warn(`[agent] frame from ${engineerId} skipped: ${(err as Error).message}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const github = await getGithubState(); // cached
|
|
||||||
const collisions = detectCollisions([...this.contexts.values()], github);
|
|
||||||
for (const collision of collisions) await this.handle(collision);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async handle(collision: Collision): Promise<void> {
|
private async handle(collision: Collision): Promise<void> {
|
||||||
|
|||||||
@@ -69,15 +69,21 @@ export async function getGitStates(podId: string): Promise<Map<string, GitState>
|
|||||||
recentCommit?: string | null;
|
recentCommit?: string | null;
|
||||||
gitUpdatedAt?: Date;
|
gitUpdatedAt?: Date;
|
||||||
}>('engineer_states');
|
}>('engineer_states');
|
||||||
const docs = await col.find({ podId }).toArray();
|
|
||||||
const map = new Map<string, GitState>();
|
const map = new Map<string, GitState>();
|
||||||
for (const doc of docs) {
|
try {
|
||||||
map.set(doc.name, {
|
const docs = await col.find({ podId }).toArray();
|
||||||
changedFiles: doc.changedFiles ?? [],
|
for (const doc of docs) {
|
||||||
branch: doc.branch ?? null,
|
map.set(doc.name, {
|
||||||
recentCommit: doc.recentCommit ?? null,
|
changedFiles: doc.changedFiles ?? [],
|
||||||
gitUpdatedAt: doc.gitUpdatedAt ?? null,
|
branch: doc.branch ?? null,
|
||||||
});
|
recentCommit: doc.recentCommit ?? null,
|
||||||
|
gitUpdatedAt: doc.gitUpdatedAt ?? null,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
// Best-effort: a Mongo hiccup degrades git fusion, it must not crash the
|
||||||
|
// live agent loop. Detection falls back to vision-only signals.
|
||||||
|
console.warn(`[memory] getGitStates failed: ${(err as Error).message}`);
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user