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:
Ramis
2026-06-27 20:31:38 -07:00
parent fe37f35522
commit 6a6fbca9e0
2 changed files with 33 additions and 21 deletions
+6
View File
@@ -43,6 +43,9 @@ export class PodMan {
} }
async onScreenFrame(engineerId: string, jpeg: Buffer): Promise<void> { async onScreenFrame(engineerId: string, jpeg: Buffer): Promise<void> {
// Whole-frame guard: a Gemini/GitHub/Mongo failure on one frame must degrade
// gracefully, never crash the long-running live agent loop.
try {
const ctx = await analyzeFrame(engineerId, this.podId, jpeg); const ctx = await analyzeFrame(engineerId, this.podId, jpeg);
this.contexts.set(engineerId, ctx); this.contexts.set(engineerId, ctx);
await recordObservation(ctx); await recordObservation(ctx);
@@ -58,6 +61,9 @@ export class PodMan {
const github = await getGithubState(); // cached const github = await getGithubState(); // cached
const collisions = detectCollisions([...this.contexts.values()], github); const collisions = detectCollisions([...this.contexts.values()], github);
for (const collision of collisions) await this.handle(collision); for (const collision of collisions) await this.handle(collision);
} catch (err) {
console.warn(`[agent] frame from ${engineerId} skipped: ${(err as Error).message}`);
}
} }
private async handle(collision: Collision): Promise<void> { private async handle(collision: Collision): Promise<void> {
+7 -1
View File
@@ -69,8 +69,9 @@ 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>();
try {
const docs = await col.find({ podId }).toArray();
for (const doc of docs) { for (const doc of docs) {
map.set(doc.name, { map.set(doc.name, {
changedFiles: doc.changedFiles ?? [], changedFiles: doc.changedFiles ?? [],
@@ -79,6 +80,11 @@ export async function getGitStates(podId: string): Promise<Map<string, GitState>
gitUpdatedAt: doc.gitUpdatedAt ?? 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;
} }