fix(server): Codex /compact binds to its own turn, not a resumed turn that starts first #35372
Openphon-t(GitHub profile, opens in a new tab)wants to merge 4 commits into
main fromrefs/pull/35372/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
- @@ -4939,3 +4937,17 @@49394937 nativeTurnId: payload.turn.id,49404938 startedAt: codexTimestamp(payload.turn.startedAt),49414939 });4940+ },4941+ );4942+4943+ // A turn held for a pending compaction is classified by its first item: a4944+ // contextCompaction item makes it the compaction run; anything else, or the4945+ // turn ending itemless, releases it to the unclaimed-turn handling.4946+ const classifyHeldTurnStart = Effect.fn("CodexAdapterV2.classifyHeldTurnStart")(4947+ function* (input: { readonly turnId: string; readonly isCompactionItem: boolean }) {4948+ const held = heldTurnStarts.get(input.turnId);4949+ if (held === undefined) return;4950+ heldTurnStarts.delete(input.turnId);4951+ if (input.isCompactionItem) {4952+ const pendingCompaction = (yield* Ref.get(pendingCompactions)).get(held.threadId);4953+ if (pendingCompaction !== undefined) {
- @@ -7661,8 +7747,12 @@76617747 compactThread: Effect.fn("CodexAdapterV2.compactThread")(76627748 function* (turnInput) {76637749 const threadId = yield* getNativeThreadId(turnInput.providerThread);7664- yield* Ref.update(pendingRootTurns, (current) =>7750+ yield* Ref.update(pendingCompactions, (current) =>76657751 new Map(current).set(threadId, turnInput),76667752 );7667- // Clear on interruption; a late turn/started must not be adopted after an interrupted start.7753+ // On failure or interruption, a late compaction item must not be adopted7754+ // and held turns go back to normal. Codex's interrupted reply is not a7755+ // failure: the compaction item still decides.76687756 yield* client.request("thread/compact/start", { threadId }).pipe(7757+ Effect.asVoid,7758+ Effect.catchIf(isCompactionInterruptedError, () => Effect.void),
phon-t(GitHub profile, opens in a new tab) linked this to fix #18833
tanstack-source added labelsbug
github-actions[bot](GitHub profile, opens in a new tab) added labelsneeds-rebase
Pushed0328960
- @@ -3826,0 +3936,21 @@3936+ };3937+3938+ it.effect.each(["accepted", "interrupted", "hook-stopped"] as const)(3939+ "binds the compaction turn after an interrupted resumed turn (%s)",3940+ (startOutcome) =>3941+ Effect.scoped(3942+ Effect.gen(function* () {3943+ const harness = yield* makeCodexReplayHarness(3944+ compactionAfterResumedTurnTranscript(startOutcome),3945+ );3946+ assert.isDefined(harness.runtime.compactThread);3947+ yield* harness.runtime.compactThread!(3948+ makeCodexTestTurnInput({3949+ threadId: harness.threadId,3950+ providerThread: harness.providerThread,3951+ now: yield* DateTime.now,3952+ attemptId: RunAttemptId.make("compact-attempt"),3953+ text: "/compact",3954+ }),3955+ );3956+ yield* harness.firstTerminal;@@ -5160,0 +5217,21 @@5217+ if (pendingRootTurn !== undefined) {5218+ yield* registerRootTurn({5219+ turnInput: pendingRootTurn,5220+ nativeTurnId: payload.turn.id,5221+ startedAt: codexTimestamp(payload.turn.startedAt),5222+ });5223+ yield* Ref.update(pendingRootTurns, (current) => {5224+ const updated = new Map(current);5225+ updated.delete(payload.threadId);5226+ return updated;5227+ });5228+ return;5229+ }5230+ // A pending compaction must not adopt whichever turn starts first; hold5231+ // the turn until its first item says whether it is the compaction turn.5232+ if ((yield* Ref.get(pendingCompactions)).has(payload.threadId)) {5233+ heldTurnStarts.set(payload.turn.id, {5234+ threadId: payload.threadId,5235+ turn: payload.turn,5236+ });5237+ return;
Pushedb49294a
github-actions[bot](GitHub profile, opens in a new tab) removed labelsneeds-rebase
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes