fix(server): Stop reaches background commands older than the recent window #16867
Closedvoltcrash(GitHub profile, opens in a new tab)wants to merge 7 commits into
main fromrefs/pull/16867/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
- @@ -1910,7 +1910,8 @@19101910 rowLimit: THREAD_HISTORY_SNAPSHOT_ROW_LIMIT,19111911 })19121912 .pipe(1913- Effect.map((snapshot) =>1914- projectThreadProjectionForWire(1913+ Effect.map(1914+ (snapshot) =>1915+ // Measure the budget on wire items, as the stream snapshot does.19151916 buildBoundedThreadProjection({1916- projection: snapshot.projection,1917+ projection: projectThreadProjectionForWire(snapshot.projection),apps/server/src/orchestration-v2/ProjectionStore.ts line 5260Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -4881,3 +4881,10 @@48814881 : {}),48824882 ...(historyAnchor === undefined ? {} : { historyAnchor }),48834883 });4884+ // Background work outlives its turn: a dev server started many turns4885+ // ago still runs, and Stop finds it in turnItems. Carry the thread's4886+ // unfinished background items into the recent window without making4887+ // them visible rows; older history pages show them in place.4888+ const pendingBackgroundItems =4889+ historyAnchor === undefined4890+ ? yield* selectShellPendingTurnItemRows([threadId]).pipe(
coderabbitai[bot](GitHub profile, opens in a new tab) requested changes
apps/server/src/orchestration-v2/ProjectionStore.ts lines 5258 to 5262Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -4881,3 +4881,12 @@48814881 : {}),48824882 ...(historyAnchor === undefined ? {} : { historyAnchor }),48834883 });4884+ // Background work outlives its turn: a dev server started many turns4885+ // ago still runs, and Stop finds it in turnItems. Carry the thread's4886+ // unfinished background items into the recent window without making4887+ // them visible rows; older history pages show them in place.4888+ const pendingBackgroundItems =4889+ historyAnchor === undefined4890+ ? yield* selectShellPendingTurnItemRows([threadId]).pipe(4891+ Effect.flatMap(decodeRows(decodeTurnItemPayload, threadId)),4892+ )apps/server/src/orchestration-v2/threadHistoryPaging.ts lines 461 to 465Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -434,13 +425,8 @@434- // Reserve bytes for small interrupt-request dependencies that may sit outside435- // the recent window but are required for visibility of results inside it.436- const dependencyReserve = (() => {437- // Upper bound: all request items in the full projection. Window selection438- // uses this reserve so the final contribution stays under the cap.439- let reserve = 0;440- for (const item of controlProjection.turnItems) {441- if (item.type === "run_interrupt_request") {442- reserve += bytesOfJson(item);443- }444- }445- return reserve;446- })();425+ // Reserve bytes for dependencies that may sit outside the recent window.426+ // Upper bound: every candidate in the full projection. Window selection uses427+ // this reserve so the final contribution stays under the cap.428+ const dependencyCandidates = windowIndependentTurnItems(controlProjection);429+ let dependencyReserve = 0;430+ for (const item of dependencyCandidates) {431+ dependencyReserve += bytesOfJson(item);432+ }apps/server/src/ws.ts lines 1904 to 1908Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -1910,7 +1910,8 @@19101910 rowLimit: THREAD_HISTORY_SNAPSHOT_ROW_LIMIT,19111911 })19121912 .pipe(1913- Effect.map((snapshot) =>1914- projectThreadProjectionForWire(1913+ Effect.map(1914+ (snapshot) =>1915+ // Measure the budget on wire items, as the stream snapshot does.19151916 buildBoundedThreadProjection({1916- projection: snapshot.projection,1917+ projection: projectThreadProjectionForWire(snapshot.projection),coderabbitai[bot](GitHub profile, opens in a new tab) approved these changes
juliusmarminge added labelsmacroscope-review
- apps/server/src/orchestration-v2/ProjectionStore.ts line 5193OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -5149,3 +5187,7 @@51495187 -- this the shell reports Waiting for work no one will finish,51505188 -- matching the item_count query's exclusion above.51515189 AND (i.run_id IS NULL OR r.status <> 'rolled_back')5190+ -- Persistent monitors are never pending work; skip decoding them.5191+ AND NOT (5192+ i.type = 'dynamic_tool'5193+ AND json_type(i.payload_json, '$.input.persistent') = 'true'
juliusmarminge assignedjuliusmarminge
juliusmarminge closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed