v2: fix agent-runner lifecycle and session DB reliability
- Use DELETE journal mode for session DBs instead of WAL. WAL doesn't sync reliably across Docker volume mounts (VirtioFS), causing dropped writes and duplicate deliveries. - Add 20s idle detection to end the query stream. The concurrent poll tracks SDK activity via a new 'activity' provider event. When no SDK events arrive for 20s and no messages are pending, the stream ends and the poll loop continues. - Add touchProcessing heartbeat so the host can distinguish active agents from idle ones by checking status_changed recency. - Catch query errors in the poll loop and write error responses to messages_out instead of crashing the process. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -200,6 +200,9 @@ export class ClaudeProvider implements AgentProvider {
|
||||
if (aborted) return;
|
||||
messageCount++;
|
||||
|
||||
// Yield activity for every SDK event so the poll loop knows the agent is working
|
||||
yield { type: 'activity' };
|
||||
|
||||
if (message.type === 'system' && message.subtype === 'init') {
|
||||
yield { type: 'init', sessionId: message.session_id };
|
||||
} else if (message.type === 'result') {
|
||||
@@ -213,7 +216,6 @@ export class ClaudeProvider implements AgentProvider {
|
||||
const tn = message as { summary?: string };
|
||||
yield { type: 'progress', message: tn.summary || 'Task notification' };
|
||||
}
|
||||
// All other message types are logged but not emitted
|
||||
}
|
||||
log(`Query completed after ${messageCount} SDK messages`);
|
||||
}
|
||||
|
||||
@@ -20,9 +20,11 @@ export class MockProvider implements AgentProvider {
|
||||
|
||||
const events: AsyncIterable<ProviderEvent> = {
|
||||
async *[Symbol.asyncIterator]() {
|
||||
yield { type: 'activity' };
|
||||
yield { type: 'init', sessionId: `mock-session-${Date.now()}` };
|
||||
|
||||
// Process initial prompt
|
||||
yield { type: 'activity' };
|
||||
yield { type: 'result', text: responseFactory(input.prompt) };
|
||||
|
||||
// Process any pushed follow-ups
|
||||
|
||||
@@ -53,4 +53,5 @@ export type ProviderEvent =
|
||||
| { type: 'init'; sessionId: string }
|
||||
| { type: 'result'; text: string | null }
|
||||
| { type: 'error'; message: string; retryable: boolean; classification?: string }
|
||||
| { type: 'progress'; message: string };
|
||||
| { type: 'progress'; message: string }
|
||||
| { type: 'activity' };
|
||||
|
||||
Reference in New Issue
Block a user