GeezerVison is showing github.com — fix(server): Codex session release ends the work its dead process lef… · pingdotgg/t3code@69cb6b5
File treeExpand file treeCollapse file tree Open diff view settings apps/server/src/orchestration-v2
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -7850,6 +7850,8 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* ( | 7850 | 7850 | providerSessionId: input.providerSessionId, | 7851 | 7851 | providerSession: session, | 7852 | 7852 | events: Stream.fromEffectRepeat(Queue.take(events)), | | 7853 | + // The app-server is this session's child process; its commands and subagents die with it. | | 7854 | + backgroundTasksEndWithProcess: true, | 7853 | 7855 | canReuseContextUsage: canReuseCodexContextUsage, | 7854 | 7856 | normalizeThreadLoadModelSelection: normalizeCodexThreadLoadModelSelection, | 7855 | 7857 | // Idle release can beat delayed subagent resumes: Codex reports them completed between turns with no resume-expected signal. | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/RunExecutionService.test.ts -56Lines changed: 0 additions & 56 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -3566,62 +3566,6 @@ it.effect("ends a running root command when the provider stream fails mid-turn", | 3566 | 3566 | }), | 3567 | 3567 | ); | 3568 | 3568 |
| 3569 | | -it.effect("ends a subagent that outlived its root when the provider stream fails", () => | 3570 | | - Effect.gen(function* () { | 3571 | | - const providerInstanceId = ProviderInstanceId.make("codex"); | 3572 | | - const { finalEvents } = yield* captureRootRunTermination({ | 3573 | | - key: "stream-error-outlived-subagent", | 3574 | | - shouldFinalizeRun: () => Effect.succeed(true), | 3575 | | - events: (ids) => | 3576 | | - Stream.make( | 3577 | | - { | 3578 | | - type: "subagent.updated" as const, | 3579 | | - driver, | 3580 | | - subagent: makeRunOwnedSubagentFixture({ | 3581 | | - ids, | 3582 | | - providerInstanceId, | 3583 | | - childThreadId: ids.childThreadId, | 3584 | | - driver, | 3585 | | - status: "running", | 3586 | | - }), | 3587 | | - }, | 3588 | | - { | 3589 | | - type: "turn_item.updated" as const, | 3590 | | - driver, | 3591 | | - turnItem: makeRunOwnedSubagentTurnItemFixture({ | 3592 | | - ids, | 3593 | | - providerInstanceId, | 3594 | | - childThreadId: ids.childThreadId, | 3595 | | - driver, | 3596 | | - status: "running", | 3597 | | - }), | 3598 | | - }, | 3599 | | - rootTerminalEvent(ids, "completed"), | 3600 | | - ).pipe( | 3601 | | - Stream.concat( | 3602 | | - Stream.fail( | 3603 | | - new ProviderAdapter.ProviderAdapterEventStreamError({ | 3604 | | - driver, | 3605 | | - providerSessionId: ProviderSessionId.make("session:stream-error-outlived-subagent"), | 3606 | | - cause: "provider process exited", | 3607 | | - }), | 3608 | | - ), | 3609 | | - ), | 3610 | | - ), | 3611 | | - }); | 3612 | | - assert.deepEqual( | 3613 | | - finalEvents.flatMap((event) => | 3614 | | - event.type === "run.updated" || | 3615 | | - event.type === "subagent.updated" || | 3616 | | - event.type === "turn-item.updated" | 3617 | | - ? [`${event.type}:${event.payload.status}`] | 3618 | | - : [], | 3619 | | - ), | 3620 | | - ["run.updated:waiting", "subagent.updated:failed", "turn-item.updated:failed"], | 3621 | | - ); | 3622 | | - }), | 3623 | | -); | 3624 | | - | 3625 | 3569 | it.effect("does not interrupt a provider when ingestion fails before the root turn is known", () => | 3626 | 3570 | Effect.gen(function* () { | 3627 | 3571 | const interrupts = yield* Ref.make(0); | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/RunExecutionService.ts +9-43Lines changed: 9 additions & 43 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1192,7 +1192,7 @@ export const layer: Layer.Layer< | 1192 | 1192 | ReadonlySet<OrchestrationV2TurnItem["id"]> | 1193 | 1193 | >(new Set(inheritedBackgroundTurnItemsById.keys())); | 1194 | 1194 | const openRunOwnedSubagents = yield* Ref.make(emptyOpenRunOwnedSubagentProjection()); | 1195 | | - // Open root-thread commands and tools of this run; only an ingestion failure ends them. | | 1195 | + // Open root-thread commands and tools of this run; an ingestion failure that stops the provider ends them. | 1196 | 1196 | const openRootTurnItems = new Map<TurnItemId, OrchestrationV2TurnItem>(); | 1197 | 1197 | // The last stored root snapshot's pendingBackgroundWork; adapters that omit it leave it false. | 1198 | 1198 | let rootSnapshotPendingWork = false; | @@ -1884,46 +1884,7 @@ export const layer: Layer.Layer< | 1884 | 1884 | runId: input.run.id, | 1885 | 1885 | cause, | 1886 | 1886 | }); | 1887 | | - if (yield* Ref.get(rootRunFinalized)) { | 1888 | | - // The root settled earlier, but work that outlived it has no stream to end it. | 1889 | | - const allocateEventId = () => | 1890 | | - idAllocator.allocate.event({ threadId: input.run.threadId }); | 1891 | | - const open = yield* Ref.getAndSet( | 1892 | | - openRunOwnedSubagents, | 1893 | | - emptyOpenRunOwnedSubagentProjection(), | 1894 | | - ); | 1895 | | - const abandoned = [...openRootTurnItems.values()]; | 1896 | | - openRootTurnItems.clear(); | 1897 | | - const events = [ | 1898 | | - ...(yield* cascadeTerminalizeRunOwnedSubagents({ | 1899 | | - run: input.run, | 1900 | | - open, | 1901 | | - status: "failed", | 1902 | | - completedAt, | 1903 | | - allocateEventId, | 1904 | | - })), | 1905 | | - ...(yield* endAbandonedTurnItems({ | 1906 | | - run: input.run, | 1907 | | - items: abandoned, | 1908 | | - status: "failed", | 1909 | | - completedAt, | 1910 | | - allocateEventId, | 1911 | | - })), | 1912 | | - ]; | 1913 | | - if (events.length === 0) return; | 1914 | | - yield* eventSink.writeWithEffects({ effects: [], events }).pipe( | 1915 | | - Effect.andThen(refreshAfterTurn), | 1916 | | - Effect.catchCauseIf( | 1917 | | - (writeCause) => !Cause.hasInterruptsOnly(writeCause), | 1918 | | - (writeCause) => | 1919 | | - Effect.logWarning( | 1920 | | - "orchestration V2 failed to end work that outlived its run", | 1921 | | - { runId: input.run.id, cause: writeCause }, | 1922 | | - ), | 1923 | | - ), | 1924 | | - ); | 1925 | | - return; | 1926 | | - } | | 1887 | + if (yield* Ref.get(rootRunFinalized)) return; | 1927 | 1888 | const providerThread = yield* Ref.get(latestProviderThread); | 1928 | 1889 | // Stop background work too; the failed consumer cannot persist terminal events. | 1929 | 1890 | const abandonedProviderTurn = | @@ -1974,8 +1935,13 @@ export const layer: Layer.Layer< | 1974 | 1935 | expectedStatus: "running", | 1975 | 1936 | }, | 1976 | 1937 | openRunOwnedSubagents: openSubagents, | 1977 | | - abandonedTurnItems: [...openRootTurnItems.values()], | 1978 | | - ...(abandonedProviderTurn === null ? {} : { abandonedProviderTurn }), | | 1938 | + ...(abandonedProviderTurn === null | | 1939 | + ? {} | | 1940 | + : { | | 1941 | + abandonedProviderTurn, | | 1942 | + // The interrupt restarted the runtime, so these items cannot end. | | 1943 | + abandonedTurnItems: [...openRootTurnItems.values()], | | 1944 | + }), | 1979 | 1945 | completedAt, | 1980 | 1946 | terminal: makeFailedTerminalEvent( | 1981 | 1947 | makeProviderFailure({ | |
|