MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / poll

Function poll

source code/tasks/RemoteAgentTask/RemoteAgentTask.tsx:554–792  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

552 // at end of run; scanning only the delta (response.newEvents) is O(new).
553 let cachedReviewContent: string | null = null;
554 const poll = async (): Promise<void> => {
555 if (!isRunning) return;
556 try {
557 const appState = context.getAppState();
558 const task = appState.tasks?.[taskId] as RemoteAgentTaskState | undefined;
559 if (!task || task.status !== 'running') {
560 // Task was killed externally (TaskStopTool) or already terminal.
561 // Session left alive so the claude.ai URL stays valid — the run_hunt.sh
562 // post_stage() calls land as assistant events there, and the user may
563 // want to revisit them after closing the terminal. TTL reaps it.
564 return;
565 }
566 const response = await pollRemoteSessionEvents(task.sessionId, lastEventId);
567 lastEventId = response.lastEventId;
568 const logGrew = response.newEvents.length > 0;
569 if (logGrew) {
570 accumulatedLog = [...accumulatedLog, ...response.newEvents];
571 const deltaText = response.newEvents.map(msg => {
572 if (msg.type === 'assistant') {
573 return msg.message.content.filter(block => block.type === 'text').map(block => 'text' in block ? block.text : '').join('\n');
574 }
575 return jsonStringify(msg);
576 }).join('\n');
577 if (deltaText) {
578 appendTaskOutput(taskId, deltaText + '\n');
579 }
580 }
581 if (response.sessionStatus === 'archived') {
582 updateTaskState<RemoteAgentTaskState>(taskId, context.setAppState, t => t.status === 'running' ? {
583 ...t,
584 status: 'completed',
585 endTime: Date.now()
586 } : t);
587 enqueueRemoteNotification(taskId, task.title, 'completed', context.setAppState, task.toolUseId);
588 void evictTaskOutput(taskId);
589 void removeRemoteAgentMetadata(taskId);
590 return;
591 }
592 const checker = completionCheckers.get(task.remoteTaskType);
593 if (checker) {
594 const completionResult = await checker(task.remoteTaskMetadata);
595 if (completionResult !== null) {
596 updateTaskState<RemoteAgentTaskState>(taskId, context.setAppState, t => t.status === 'running' ? {
597 ...t,
598 status: 'completed',
599 endTime: Date.now()
600 } : t);
601 enqueueRemoteNotification(taskId, completionResult, 'completed', context.setAppState, task.toolUseId);
602 void evictTaskOutput(taskId);
603 void removeRemoteAgentMetadata(taskId);
604 return;
605 }
606 }
607
608 // Ultraplan: result(success) fires after every CCR turn, so it must not
609 // drive completion — startDetachedPoll owns that via ExitPlanMode scan.
610 // Long-running monitors (autofix-pr) emit result per notification cycle,
611 // so the same skip applies.

Callers 1

Calls 14

pollRemoteSessionEventsFunction · 0.85
jsonStringifyFunction · 0.85
appendTaskOutputFunction · 0.85
evictTaskOutputFunction · 0.85
extractReviewTagFromLogFunction · 0.85
extractTodoListFromLogFunction · 0.85
extractReviewFromLogFunction · 0.85
updateTaskStateFunction · 0.50

Tested by

no test coverage detected