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
24 changes: 23 additions & 1 deletion assistant/src/daemon/handlers/computer-use.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ function removeCuSessionReferences(
return;
}
ctx.cuSessions.delete(sessionId);
ctx.cuSessionMetadata.delete(sessionId);
// NOTE: cuSessionMetadata is intentionally NOT deleted here.
Comment thread
Jasonnnz marked this conversation as resolved.
// onTerminal fires before cu_session_finalized arrives from the client,
// so deleting metadata here would race with handleCuSessionFinalized
// which still needs to read it. Metadata is cleaned up explicitly at the
// end of handleCuSessionFinalized instead.
cuObservationSequenceBySession.delete(sessionId);
Comment thread
Jasonnnz marked this conversation as resolved.
ctx.cuObservationParseSequence.delete(sessionId);
for (const [sock, ids] of ctx.socketToCuSession) {
Expand All @@ -48,6 +52,9 @@ export function handleCuSessionCreate(
if (existingSession) {
existingSession.abort();
removeCuSessionReferences(ctx, msg.sessionId, existingSession);
// Clean up stale metadata from the replaced session; the new session
// will set its own metadata below if needed.
ctx.cuSessionMetadata.delete(msg.sessionId);
}

const config = getConfig();
Expand Down Expand Up @@ -113,6 +120,8 @@ export function handleCuSessionAbort(
}
session.abort();
removeCuSessionReferences(ctx, msg.sessionId, session);
// On explicit abort, clean up metadata too — no finalized event is guaranteed.
ctx.cuSessionMetadata.delete(msg.sessionId);
log.info({ sessionId: msg.sessionId }, 'Computer-use session aborted by client');
}

Expand Down Expand Up @@ -249,6 +258,16 @@ export function handleCuSessionFinalized(
...(msg.recording ? { recordingPath: msg.recording.localPath } : {}),
});

// Also append to the in-memory Session.messages so subsequent turns
// in the same session see the injected summary without a reload.
const activeSession = ctx.sessions.get(reportSessionId);
if (activeSession) {
activeSession.messages.push({
role: 'assistant',
content: [{ type: 'text', text: msg.summary }],
});
}

// If the reporting session has a connected client, stream the summary
// so it appears in real time.
if (reportSocket) {
Expand Down Expand Up @@ -277,6 +296,9 @@ export function handleCuSessionFinalized(

// Clean up all CU session state.
removeCuSessionReferences(ctx, msg.sessionId);
// Delete metadata last — after it has been consumed for summary injection
// above and after removeCuSessionReferences (which intentionally skips it).
ctx.cuSessionMetadata.delete(msg.sessionId);
}

export const computerUseHandlers = defineHandlers({
Expand Down
2 changes: 1 addition & 1 deletion clients/shared/IPC/IPCMessages.swift
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ extension IPCMemoryRecalled {
selectedCount: Int,
rerankApplied: Bool,
injectedTokens: Int,
latencyMs: Double,
latencyMs: Int,
topCandidates: [IPCMemoryRecalledCandidateDebug]
) {
self.init(
Expand Down
Loading