GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Merge updated fix/failed-dropped-turn-handoff · pingdotgg/t3code@dc1c913

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/server/src/orchestration-v2
    • ProviderTurnStartService.ts
    • RunExecutionService.ts
    • testkit
      • ProviderSwitch.integration.test.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/server/src/orchestration-v2/ProviderTurnStartService.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/ProviderTurnStartService.ts
+50-31Lines changed: 50 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import * as Option from "effect/Option";
3333
import * as Path from "effect/Path";
3434
import * as Predicate from "effect/Predicate";
3535
import * as Schema from "effect/Schema";
36+
import * as Semaphore from "effect/Semaphore";
3637

3738
import * as ServerConfig from "../config.ts";
3839
import {
@@ -1092,6 +1093,11 @@ export const layer: Layer.Layer<
10921093
const deliveredAttemptIds = new Set(
10931094
projection.providerTurns.filter(isDeliveredProviderTurn).map((turn) => turn.runAttemptId),
10941095
);
1096+
const droppedAttemptIds = new Set(
1097+
projection.providerTurns
1098+
.filter((turn) => !isDeliveredProviderTurn(turn))
1099+
.map((turn) => turn.runAttemptId),
1100+
);
10951101
const acceptedAttempts = projection.attempts.filter(
10961102
(source) =>
10971103
source.providerThreadId === providerThread.id && deliveredAttemptIds.has(source.id),
@@ -1162,7 +1168,9 @@ export const layer: Layer.Layer<
11621168
(source) =>
11631169
source.ordinal < run.ordinal &&
11641170
source.providerThreadId === providerThread.id &&
1165-
(source.status === "failed" || source.status === "interrupted") &&
1171+
(source.status === "failed" ||
1172+
source.status === "interrupted" ||
1173+
(source.status === "cancelled" && droppedAttemptIds.has(source.activeAttemptId))) &&
11661174
!deliveredAttemptIds.has(source.activeAttemptId),
11671175
);
11681176
const missedRunIds = new Set(missedRuns.map((source) => source.id));
@@ -2034,6 +2042,7 @@ export const layer: Layer.Layer<
20342042
});
20352043
let inlineDeliveredHandoffs: ReadonlyArray<OrchestrationV2ContextHandoff> = [];
20362044
let promptDroppedOnTerminal = false;
2045+
const inlineDeliveryLock = yield* Semaphore.make(1);
20372046
const retryHandoffIds = new Set(retryHandoff.handoffs.map((handoff) => handoff.id));
20382047
const startWithHandoffs = Effect.fn("ProviderTurnStartService.startWithHandoffs")(
20392048
function* (turnInput: Parameters<typeof session.startTurn>[0], compact = false) {
@@ -2120,32 +2129,39 @@ export const layer: Layer.Layer<
21202129
: Effect.void,
21212130
),
21222131
);
2123-
if (promptDroppedOnTerminal) return;
2124-
// After provider acceptance, failed delivery bookkeeping must not stop live ingestion.
2125-
const nativeThreadId = runningProviderThread.nativeThreadRef?.nativeId;
2126-
yield* Effect.forEach(
2127-
[
2128-
delivery.delivered,
2129-
...(sideChatContext === "" || sideChatHandoff === undefined || nativeThreadId == null
2130-
? []
2131-
: [
2132-
persistHandoff({
2133-
...sideChatHandoff,
2134-
toProviderThreadId: runningProviderThread.id,
2135-
delivery: { nativeThreadId, status: "inline" as const, itemIds: [] },
2136-
}),
2137-
]),
2138-
],
2139-
(record) =>
2140-
record.pipe(
2141-
Effect.catchCause(() =>
2142-
Effect.logWarning("Failed to record accepted context handoff delivery", {
2143-
runId: run.id,
2144-
deliveryStatus: "pending",
2145-
}),
2146-
),
2147-
),
2148-
{ discard: true },
2132+
// Serialize acceptance writes against dropped-terminal restoration so neither overwrites the other.
2133+
yield* inlineDeliveryLock.withPermits(1)(
2134+
Effect.gen(function* () {
2135+
if (promptDroppedOnTerminal) return;
2136+
// After provider acceptance, failed delivery bookkeeping must not stop live ingestion.
2137+
const nativeThreadId = runningProviderThread.nativeThreadRef?.nativeId;
2138+
yield* Effect.forEach(
2139+
[
2140+
delivery.delivered,
2141+
...(sideChatContext === "" ||
2142+
sideChatHandoff === undefined ||
2143+
nativeThreadId == null
2144+
? []
2145+
: [
2146+
persistHandoff({
2147+
...sideChatHandoff,
2148+
toProviderThreadId: runningProviderThread.id,
2149+
delivery: { nativeThreadId, status: "inline" as const, itemIds: [] },
2150+
}),
2151+
]),
2152+
],
2153+
(record) =>
2154+
record.pipe(
2155+
Effect.catchCause(() =>
2156+
Effect.logWarning("Failed to record accepted context handoff delivery", {
2157+
runId: run.id,
2158+
deliveryStatus: "pending",
2159+
}),
2160+
),
2161+
),
2162+
{ discard: true },
2163+
);
2164+
}),
21492165
);
21502166
},
21512167
Effect.mapError((cause) =>
@@ -2206,10 +2222,13 @@ export const layer: Layer.Layer<
22062222
hasUnpairedRunInterruptRequest: runControls.hasUnpairedRunInterruptRequest,
22072223
loadRunInterruptReason: runControls.loadRunInterruptReason,
22082224
hasWorkspaceMoved: runControls.hasWorkspaceMoved,
2209-
loadDroppedInlineHandoffs: () => {
2210-
promptDroppedOnTerminal = true;
2211-
return inlineDeliveredHandoffs;
2212-
},
2225+
loadDroppedInlineHandoffs: () =>
2226+
inlineDeliveryLock.withPermits(1)(
2227+
Effect.sync(() => {
2228+
promptDroppedOnTerminal = true;
2229+
return inlineDeliveredHandoffs;
2230+
}),
2231+
),
22132232
loadUnsettledWork: runControls.loadUnsettledWork,
22142233
message: {
22152234
messageId: message.id,

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.