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> {
|
||||
const ctx = await analyzeFrame(engineerId, this.podId, jpeg);
|
||||
this.contexts.set(engineerId, ctx);
|
||||
await recordObservation(ctx);
|
||||
// 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);
|
||||
this.contexts.set(engineerId, ctx);
|
||||
await recordObservation(ctx);
|
||||
|
||||
// Fuse git ground truth: engineer_states written by scripts/podman-agent.mjs.
|
||||
// Keyed by name (matches --name arg), same as LiveKit participant identity.
|
||||
const gitStates = await getGitStates(this.podId);
|
||||
for (const [id, c] of this.contexts) {
|
||||
const git = gitStates.get(id);
|
||||
if (git && git.changedFiles.length > 0) c.hasUnpushedChanges = true;
|
||||
// Fuse git ground truth: engineer_states written by scripts/podman-agent.mjs.
|
||||
// Keyed by name (matches --name arg), same as LiveKit participant identity.
|
||||
const gitStates = await getGitStates(this.podId);
|
||||
for (const [id, c] of this.contexts) {
|
||||
const git = gitStates.get(id);
|
||||
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> {
|
||||
|
||||
@@ -69,15 +69,21 @@ export async function getGitStates(podId: string): Promise<Map<string, GitState>
|
||||
recentCommit?: string | null;
|
||||
gitUpdatedAt?: Date;
|
||||
}>('engineer_states');
|
||||
const docs = await col.find({ podId }).toArray();
|
||||
const map = new Map<string, GitState>();
|
||||
for (const doc of docs) {
|
||||
map.set(doc.name, {
|
||||
changedFiles: doc.changedFiles ?? [],
|
||||
branch: doc.branch ?? null,
|
||||
recentCommit: doc.recentCommit ?? null,
|
||||
gitUpdatedAt: doc.gitUpdatedAt ?? null,
|
||||
});
|
||||
try {
|
||||
const docs = await col.find({ podId }).toArray();
|
||||
for (const doc of docs) {
|
||||
map.set(doc.name, {
|
||||
changedFiles: doc.changedFiles ?? [],
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user