feat: "waiting" status for threads with open background tasks (i.e. pr monitors) #4415
Closedt3dotgg(GitHub profile, opens in a new tab)wants to merge 4 commits into
main fromt3code/sidebar-waiting-stateopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts line 1454OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1382,11 +1436,19 @@13821436 case "turn.completed":13831437 return normalizeRuntimeTurnState(event.payload.state) === "failed"13841438 ? "error"1385- : "ready";1439+ : restingStatus;13861440 case "session.started":13871441 case "thread.started":13881442 // Provider thread/session start notifications can arrive during an13891443 // active or pending turn; preserve that lifecycle state.1390- return activeTurnId !== null ? "running" : hasPendingTurnStart ? "starting" : "ready";1444+ return activeTurnId !== null1445+ ? "running"1446+ : hasPendingTurnStart1447+ ? "starting"1448+ : restingStatus;13911449 }13921450 })();1451+ // A session leaving the resting/running loop can no longer be woken1452+ // by its tasks; drop them so a stale set never parks a future1453+ // session on Waiting.1454+ if (status === "stopped" || status === "error" || status === "interrupted") {apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts lines 762 to 771OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -748,0 +751,21 @@751+ // "ready" ("Done"): the agent stopped, but a task completion is expected to752+ // wake it, and flashing Done in between is a lie. Keyed by provider753+ // instance so a replaced session can neither inherit nor close a754+ // predecessor's tasks. Plain mutable state is safe: ingestion is a single755+ // serial worker. Terminal session statuses sweep the entry.756+ const openTasksByThreadId = new Map<ThreadId, { instanceKey: string; taskIds: Set<string> }>();757+758+ const taskInstanceKey = (event: ProviderRuntimeEvent) =>759+ event.providerInstanceId ?? event.provider;760+761+ /** Returns true when this task is the instance's first open task. */762+ const trackTaskStarted = (threadId: ThreadId, event: ProviderRuntimeEvent, taskId: string) => {763+ const instanceKey = taskInstanceKey(event);764+ const entry = openTasksByThreadId.get(threadId);765+ if (!entry || entry.instanceKey !== instanceKey) {766+ openTasksByThreadId.set(threadId, { instanceKey, taskIds: new Set([taskId]) });767+ return true;768+ }769+ entry.taskIds.add(taskId);770+ return false;771+ };
- apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts line 1853OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -1757,3 +1833,21 @@1833+ thread.session.activeTurnId === null &&1834+ (thread.session.providerInstanceId ?? thread.session.providerName) ===1835+ taskInstanceKey(event)1836+ ) {1837+ yield* orchestrationEngine.dispatch({1838+ type: "thread.session.set",1839+ commandId: yield* providerCommandId(event, "open-task-session-idle"),1840+ threadId: thread.id,1841+ session: {1842+ ...thread.session,1843+ status: "idle",1844+ lastError: null,1845+ updatedAt: now,1846+ },1847+ createdAt: now,1848+ });1849+ }17571850 }17581851 let taskTitle: string | undefined;17591852 if (event.type === "task.completed") {1853+ trackTaskCompleted(thread.id, event, event.payload.taskId);apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts line 1904Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -1756,0 +1829,21 @@1829+ // to "idle" now — the turn-completion path never saw the task.1830+ if (1831+ firstOpenTask &&1832+ thread.session?.status === "ready" &&1833+ thread.session.activeTurnId === null &&1834+ (thread.session.providerInstanceId ?? thread.session.providerName) ===1835+ taskInstanceKey(event)1836+ ) {1837+ yield* orchestrationEngine.dispatch({1838+ type: "thread.session.set",1839+ commandId: yield* providerCommandId(event, "open-task-session-idle"),1840+ threadId: thread.id,1841+ session: {1842+ ...thread.session,1843+ status: "idle",1844+ lastError: null,1845+ updatedAt: now,1846+ },1847+ createdAt: now,1848+ });1849+ }
t3dotgg(GitHub profile, opens in a new tab) changed the title
- apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts line 1907Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1757,3 +1867,21 @@1867+ firstOpenTask &&1868+ thread.session?.status === "ready" &&1869+ thread.session.activeTurnId === null &&1870+ sessionInstanceKeyFor(thread.session) === taskInstanceKey(event)1871+ ) {1872+ yield* orchestrationEngine.dispatch({1873+ type: "thread.session.set",1874+ commandId: yield* providerCommandId(event, "open-task-session-idle"),1875+ threadId: thread.id,1876+ session: {1877+ ...thread.session,1878+ status: "idle",1879+ lastError: null,1880+ updatedAt: now,1881+ },1882+ createdAt: now,1883+ });1884+ }17571885 }17581886 let taskTitle: string | undefined;17591887 if (event.type === "task.completed") {
- apps/web/src/components/SidebarV2.tsx line 909Resolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -897,4 +906,4 @@897906 wrapper around the ticking duration would make898907 screen readers announce every second. */}899908 <span role="status">{topStatus.label}</span>900- {status === "working" ? (909+ {status === "working" || status === "waiting" ? (
- apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts line 824Resolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -748,0 +798,21 @@798+ return false;799+ }800+ const wasEmpty = entry.taskIds.size === 0;801+ entry.taskIds.add(taskId);802+ return wasEmpty;803+ };804+805+ /** Returns true when this completion closed the instance's last open task. */806+ const trackTaskCompleted = (threadId: ThreadId, event: ProviderRuntimeEvent, taskId: string) => {807+ const instanceKey = taskInstanceKey(event);808+ const entry = openTasksByThreadId.get(threadId);809+ if (!entry) {810+ // Completion outrunning its start: tombstone it anyway, or the late811+ // start would open a phantom task and park the thread on Waiting for812+ // a completion that already happened.813+ openTasksByThreadId.set(threadId, {814+ instanceKey,815+ taskIds: new Set(),816+ closedTaskIds: new Set([taskId]),817+ });818+ return false;
juliusmarminge closed this
Sign in to join this conversation.


Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
91fb2c98-8548-4670-a2cd-2cbb6e8a3eeeYou can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share