feat: show compaction state and result instead of a generic Working #7714
Closedrobertnisipeanu(GitHub profile, opens in a new tab)wants to merge 4 commits into
main fromrefs/pull/7714/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/server/src/provider/Layers/CodexAdapter.ts line 1787Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -1718,8 +1763,20 @@1763+ // instead of an uncleared running. Threads never observed default to1764+ // open so an attach mid-turn keeps today's behavior.1765+ const turnOpenByThread = new Map<string, boolean>();1766+17181767 // Fork into the session scope, not the calling fiber. `forkChild` makes17191768 // this a child of `startSession`, and Effect interrupts a fiber's17201769 // children when it completes, so the consumer died on return and every17211770 // runtime event the session emitted afterwards was dropped.17221771 const eventFiber = yield* Stream.runForEach(runtime.events, (event) =>17231772 Effect.gen(function* () {17241773 yield* writeNativeEvent(event);1725- const runtimeEvents = mapToRuntimeEvents(event, event.threadId);1774+ if (event.kind === "notification" && event.method === "turn/started") {1775+ turnOpenByThread.set(String(event.threadId), true);1776+ }1777+ const runtimeEvents = mapToRuntimeEvents(event, event.threadId, {1778+ turnOpen: turnOpenByThread.get(String(event.threadId)) !== false,1779+ });1780+ if (event.kind === "notification" && event.method === "turn/completed") {1781+ turnOpenByThread.set(String(event.threadId), false);1782+ }apps/server/src/provider/Layers/ClaudeAdapter.ts line 3192Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -3115,10 +3155,20 @@3155+ data: message,3156+ },3157+ });3158+ }31153159 yield* offerRuntimeEvent({31163160 ...base,31173161 type: "session.state.changed",31183162 payload: {3119- state: message.status === "compacting" ? "waiting" : "running",3163+ state:3164+ message.status === "compacting"3165+ ? "compacting"3166+ : context.turnState3167+ ? "running"3168+ : "ready",31203169 reason: `status:${message.status ?? "active"}`,31213170 detail: message,31223171 },31233172 });31243173 return;3174+ }apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts line 1686Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -1607,3 +1652,20 @@16071652 : status === "ready"16081653 ? null16091654 : (thread.session?.lastError ?? null);1655+ // The compacting state raises the detail. Lifecycle events that keep1656+ // the session busy without saying anything about compaction — a1657+ // completed turn the compaction outlived, or a session/thread start1658+ // notification landing mid-work — carry an in-flight detail forward.1659+ // Everything else writes the session without one, which is what1660+ // clears it.1661+ const statusDetail =1662+ event.type === "session.state.changed"1663+ ? event.payload.state === "compacting"1664+ ? ("compacting" as const)1665+ : undefined1666+ : (event.type === "turn.completed" ||1667+ event.type === "session.started" ||1668+ event.type === "thread.started") &&1669+ status === "running"1670+ ? thread.session?.statusDetail1671+ : undefined;
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XL
- apps/server/src/provider/Layers/OpenCodeAdapter.ts line 864OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -839,3 +844,21 @@839844 },840845 });841846 }847+848+ // `time.compacting` appears while OpenCode compacts the session and849+ // disappears when it finishes; report the transitions. The falling850+ // edge lands on ready when compaction outlived its turn so the851+ // state clears itself.852+ const compacting = event.properties.info.time?.compacting !== undefined;853+ if (compacting !== context.compacting) {854+ context.compacting = compacting;855+ yield* emit({856+ ...(yield* buildEventBase({857+ threadId: context.session.threadId,858+ turnId,859+ raw: event,860+ })),861+ type: "session.state.changed",862+ payload: compacting863+ ? { state: "compacting", reason: "session:compacting" }864+ : { state: turnId ? "running" : "ready", reason: "session:compaction-ended" },
- apps/mobile/src/lib/threadActivity.ts line 1388Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -1286,3 +1346,4 @@12861346 type: "working",12871347 id: "working-indicator-row",12881348 createdAt: activeWorkStartedAt,1349+ compactingSince,
- apps/mobile/src/lib/threadActivity.ts line 1290Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1196,3 +1285,3 @@1196128511971286 const terminalAssistantMessageId = terminalAssistantMessageIdByTurn.get(turnId);11981287 const hiddenEntryIds = new Set(
- apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts line 1627OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -1585,4 +1619,9 @@15851619 case "turn.completed":15861620 return normalizeRuntimeTurnState(event.payload.state) === "failed"15871621 ? "error"1588- : "ready";1622+ : // Compaction outlives the turn that asked for it: stay busy1623+ // until the provider's own compaction-end signal lands the1624+ // session on ready.1625+ thread.session?.statusDetail === "compacting"1626+ ? "running"1627+ : "ready";
- apps/web/src/components/Sidebar.tsx line 842OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -839,4 +839,4 @@839839 const topStatus =840840 status === "working"841841 ? {842- label: "Working",842+ label: thread.session?.statusDetail === "compacting" ? "Compacting" : "Working",
- apps/web/src/components/chat/MessagesTimeline.tsx line 1156Resolvedby robertnisipeanu(GitHub profile, opens in a new tab)@@ -1121,3 +1127,17 @@11211127 );11221128 }112311291130+/**1131+ * Compaction result row — a thread lifecycle marker at the same level as the1132+ * "Worked for N" fold, never part of it.1133+ */1134+function CompactionTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "compaction" }> }) {1135+ return (1136+ <div className="border-b border-border/60 pb-2 pt-1">1137+ <div1138+ className={cn(1139+ "px-1 text-sm leading-relaxed tabular-nums",1140+ row.failed ? "text-destructive/90" : "text-muted-foreground",1141+ )}1142+ >1143+ {row.label}apps/mobile/src/features/threads/thread-list-v2-items.tsx line 428Resolvedby robertnisipeanu(GitHub profile, opens in a new tab)@@ -422,4 +422,6 @@422422 const selected = props.selected === true;423423424424 const status = resolveThreadListV2Status(thread);425- const statusLabel = STATUS_LABEL_BY_STATUS[status];425+ // Compaction can run on a ready session (a /compact whose turn already426+ // closed), so the overlay outranks the derived status.427+ const statusLabel =
- apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts line 1686Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -1613,3 +1662,20 @@16131662 : status === "ready"16141663 ? null16151664 : (thread.session?.lastError ?? null);1665+ // The compacting state raises the detail. Turn lifecycle and start1666+ // notifications say nothing about compaction, so they carry an1667+ // in-flight detail forward — a turn ending mid-compaction settles the1668+ // turn while the compacting overlay stays up. Terminal states1669+ // (error, stopped) and every other write clear it.1670+ const statusDetail =1671+ event.type === "session.state.changed"1672+ ? event.payload.state === "compacting"1673+ ? ("compacting" as const)1674+ : undefined1675+ : (event.type === "turn.completed" ||1676+ event.type === "session.started" ||1677+ event.type === "thread.started") &&1678+ status !== "error" &&1679+ status !== "stopped"1680+ ? thread.session?.statusDetail1681+ : undefined;apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts line 1729OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -1642,11 +1718,12 @@16421718 session: {16431719 threadId: thread.id,16441720 status,1721+ ...(statusDetail !== undefined ? { statusDetail } : {}),16451722 providerName: event.provider,16461723 ...(event.providerInstanceId !== undefined16471724 ? { providerInstanceId: event.providerInstanceId }16481725 : {}),16491726 runtimeMode: thread.session?.runtimeMode ?? "full-access",16501727 activeTurnId: nextActiveTurnId,16511728 lastError,1652- updatedAt: now,1729+ updatedAt: compactingSince ?? now,apps/web/src/components/Sidebar.logic.ts line 670Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -658,3 +660,4 @@658660 };659661 }660662663+ // Compaction overlays the turn lifecycle: it can run on a ready session (a
- apps/mobile/src/features/threads/ThreadRouteScreen.tsx line 779OutdatedResolvedby robertnisipeanu(GitHub profile, opens in a new tab)@@ -774,3 +774,6 @@774774 environmentLabel={selectedEnvironmentConnection?.environmentLabel ?? null}775775 selectedThreadFeed={composer.selectedThreadFeed}776776 activeWorkStartedAt={composer.activeWorkStartedAt}777+ compactingSince={778+ selectedThread.session?.statusDetail === "compacting"779+ ? selectedThread.session.updatedAtapps/mobile/src/features/threads/ThreadFeed.tsx line 1804OutdatedResolvedby robertnisipeanu(GitHub profile, opens in a new tab)@@ -1773,3 +1801,4 @@17731801 (entry: ThreadFeedEntry) => {17741802 switch (entry.type) {17751803 case "turn-fold":1804+ case "compaction":
- apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts lines 1675 to 1675OutdatedResolvedby robertnisipeanu(GitHub profile, opens in a new tab)@@ -1613,3 +1662,14 @@16131662 : status === "ready"16141663 ? null16151664 : (thread.session?.lastError ?? null);1665+ // The compacting state raises the detail. A turn completion and the1666+ // start notifications say nothing about compaction, so they carry an1667+ // in-flight detail forward — a turn ending mid-compaction settles the1668+ // turn while the compacting overlay stays up. A turn START clears it1669+ // on purpose: the new turn takes over the session's label, and a1670+ // provider still compacting re-raises the detail with its next1671+ // compacting signal. Terminal states (error, stopped) and every1672+ // other write clear it.1673+ const statusDetail =1674+ event.type === "session.state.changed"1675+ ? event.payload.state === "compacting"apps/server/src/provider/Layers/ClaudeAdapter.ts line 597Resolvedby robertnisipeanu(GitHub profile, opens in a new tab)@@ -583,3 +590,8 @@583590 });584591 }585592593+function isCompactionStatusMessage(message: SDKMessage): boolean {594+ return (595+ message.type === "system" &&596+ message.subtype === "status" &&597+ (message.status === "compacting" || message.compact_result !== undefined)
- apps/web/src/components/Sidebar.tsx line 846OutdatedResolvedby robertnisipeanu(GitHub profile, opens in a new tab)@@ -843,4 +843,4 @@843843 const topStatus =844844 status === "working"845845 ? {846- label: "Working",846+ label: thread.session?.statusDetail === "compacting" ? "Compacting" : "Working",apps/server/src/provider/Layers/OpenCodeAdapter.ts line 901Resolvedby robertnisipeanu(GitHub profile, opens in a new tab)@@ -841,0 +881,21 @@881+ payload: {882+ state: "compacted",883+ detail: event.properties,884+ },885+ });886+ if (context.compacting) {887+ context.compacting = false;888+ if (context.session.status !== "error") {889+ yield* emit({890+ ...(yield* buildEventBase({891+ threadId: context.session.threadId,892+ turnId,893+ raw: event,894+ })),895+ type: "session.state.changed",896+ payload: {897+ state: turnId ? "running" : "ready",898+ reason: "session:compacted",899+ },900+ });901+ }
- apps/web/src/components/Sidebar.tsx lines 1493 to 1493OutdatedResolvedby robertnisipeanu(GitHub profile, opens in a new tab)@@ -1474,4 +1488,6 @@14741488 wrapper around the ticking duration would make14751489 screen readers announce every second. */}14761490 <span role="status">{topStatus.label}</span>1477- {status === "working" ? (1491+ {/* Compacting counts from the session's compaction1492+ clock, not from turn start. */}1493+ {isCompacting && thread.session ? (
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:
fe63a5b6-4214-42fb-8e56-eeb54987bb49You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
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