Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 35 additions & 35 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/main/ipc/attachmentHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ export function registerAttachmentHandlers(attachments: AttachmentManager): void
if (typeof p !== 'string' || p.length === 0 || p.length > ATTACHMENT_LIMITS.pathMax) {
throw new Error('Invalid path');
}
if (p.includes('\0')) {
throw new Error('Invalid path');
}
}
return attachments.addFromPaths(id, paths, 'drop');
},
Expand Down
33 changes: 33 additions & 0 deletions src/main/managers/AgentManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,7 @@ export class AgentManager {
permMode: SessionPermissionMode,
): Promise<void> {
let attempt = 0;
let resumeDropped = false;
for (;;) {
try {
await this.runOnce(sessionId, prompt, abort, permMode);
Expand Down Expand Up @@ -1250,6 +1251,28 @@ export class AgentManager {
return;
}
const raw = err instanceof Error ? err.message : String(err);

// Corrupted-resume self-heal: the CLI's `[ede_diagnostic] … stop_reason=
// tool_use` result means the resumed transcript ends in a tool_use with
// no tool_result (a prior run died mid-tool). Resuming it fails the same
// way every turn, so drop the stored SDK session id once and retry with
// a fresh SDK session (Limboo's own transcript/history is unaffected).
const resumeCorrupted =
raw.includes('ede_diagnostic') ||
(raw.includes('returned an error result') && raw.includes('stop_reason=tool_use'));
if (resumeCorrupted && !resumeDropped && this.loadSdkSession(sessionId)) {
resumeDropped = true;
this.forgetSdkSession(sessionId);
this.diag(
'recovery',
'warning',
'Resumed transcript was corrupted — starting a fresh SDK session',
redact(raw),
sessionId,
);
continue; // retry — buildOptions no longer finds a resume id
}

const cls = classifyAgentError(redact(raw));
this.diag('recovery', cls.recoverable ? 'warning' : 'error', `Run error (${cls.outcome})`, redact(raw), sessionId);

Expand Down Expand Up @@ -2323,6 +2346,16 @@ export class AgentManager {
.run(sessionId, sdkSessionId, Date.now());
}

/**
* Drop the stored SDK session id so the next run starts a fresh SDK session
* instead of resuming. Used when the resumed transcript is corrupted (e.g. it
* ends in a tool_use with no tool_result after a mid-tool kill) — resuming it
* would fail identically on every turn.
*/
private forgetSdkSession(sessionId: string): void {
getDb().prepare('DELETE FROM agent_session_meta WHERE session_id = ?').run(sessionId);
}

/* ---------------------------------------------------------------- */
/* State + broadcast */
/* ---------------------------------------------------------------- */
Expand Down
10 changes: 9 additions & 1 deletion src/main/managers/voice/VoiceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export class VoiceManager {
private worker: UtilityProcess | null = null;
private workerReady = false;
private workerRestarts = 0;
/** Set when WE asked the worker to shut down, so its exit is not a crash. */
private expectedExit = false;
Comment on lines +54 to +55

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Map the relevant files and symbols first
ast-grep outline src/main/managers/voice/VoiceManager.ts --view expanded
printf '\n--- worker outline ---\n'
ast-grep outline src/main/voice/worker.ts --view expanded

# Show the relevant sections with line numbers
printf '\n--- VoiceManager.ts relevant lines ---\n'
sed -n '390,460p' src/main/managers/voice/VoiceManager.ts
printf '\n--- VoiceManager.ts idle/dispose lines ---\n'
sed -n '630,690p' src/main/managers/voice/VoiceManager.ts
printf '\n--- worker.ts shutdown handling ---\n'
sed -n '410,450p' src/main/voice/worker.ts

Repository: BotCoder254/limboo

Length of output: 10529


Guard against reusing a worker after shutdown is requested

ensureWorker() still treats the current worker as usable while an idle shutdown is already in flight, so new capture/TTS work can attach to a process that is about to exit. That exit is also counted as expectedExit, which hides the failure as a clean shutdown instead of a warning. Track a pending-shutdown state or refork before reusing the worker after shutdown has been requested.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/main/managers/voice/VoiceManager.ts` around lines 54 - 55, The worker
lifecycle in VoiceManager still allows ensureWorker() to reuse an existing
worker after shutdown has already been requested, which can attach new
capture/TTS work to a process that is about to exit. Update the worker state
handling around expectedExit and the shutdown path so that a pending idle
shutdown marks the worker as unavailable, and ensure ensureWorker() either
reforks or refuses reuse once shutdown has been requested. Also make sure the
resulting exit is not treated as a normal expectedExit if new work was still
pending.

private readonly loadedKinds = new Set<VoiceWorkerModelKind>();
private readonly loading = new Map<VoiceWorkerModelKind, Promise<void>>();
/** Signature of the VAD tuning the worker was loaded with. */
Expand Down Expand Up @@ -423,12 +425,16 @@ export class VoiceManager {
});
this.worker = proc;
this.workerReady = false;
this.expectedExit = false;
this.loadedKinds.clear();
this.loading.clear();

proc.on('message', (msg: VoiceWorkerResponse) => this.onWorkerMessage(msg));
proc.on('exit', (code) => {
logger.warn(`voice: worker exited with code ${code}`);
const expected = this.expectedExit && code === 0;
this.expectedExit = false;
if (expected) logger.info('voice: worker exited cleanly');
else logger.warn(`voice: worker exited with code ${code}`);
const wasReady = this.workerReady;
this.worker = null;
this.workerReady = false;
Expand Down Expand Up @@ -638,6 +644,7 @@ export class VoiceManager {
this.captureSessionId !== null || this.currentJob !== null || this.ttsQueue.length > 0;
if (!busy && this.worker) {
logger.info('voice: shutting down idle speech worker');
this.expectedExit = true;
this.post({ t: 'shutdown' });
}
}, WORKER_IDLE_MS);
Expand Down Expand Up @@ -666,6 +673,7 @@ export class VoiceManager {
this.unsubscribeAgent?.();
this.ttsQueue.length = 0;
if (this.worker) {
this.expectedExit = true;
this.post({ t: 'shutdown' });
this.worker = null;
}
Expand Down
Loading