@@ -510,7 +510,7 @@ describe("orchestration v2 provider switching", () => { |
510 | 510 | capabilities: ClaudeProviderCapabilitiesV2, |
511 | 511 | modelSelection: CLAUDE_MODEL_SELECTION, |
512 | 512 | responseByRunOrdinal: scenario.includes("target-estimate") |
513 | | - ? { 2: "x".repeat(10_000) } |
| 513 | + ? { 2: "x".repeat(64_000) } |
514 | 514 | : {}, |
515 | 515 | capturedTurns, |
516 | 516 | ...(scenario.includes("retry") || scenario.includes("unsent") ? { failStartOnce } : {}), |
@@ -1230,6 +1230,106 @@ describe("orchestration v2 provider switching", () => { |
1230 | 1230 | ), |
1231 | 1231 | ); |
1232 | 1232 |
|
| 1233 | + it.live("keeps a native session whose stored prose is far below an unreported window", () => |
| 1234 | + Effect.scoped( |
| 1235 | + Effect.gen(function* () { |
| 1236 | + const cwd = yield* checkpointWorkspace("handoff-estimate-headroom"); |
| 1237 | + const capturedTurns = yield* Ref.make<ReadonlyArray<CapturedTurn>>([]); |
| 1238 | + const generation = yield* Ref.make(0); |
| 1239 | + // About 112 KB of ordinary English is about 25k tokens: a quarter of a 128k window. |
| 1240 | + const prose = "The quick brown fox jumps over the lazy dog. ".repeat(2_500); |
| 1241 | + const layerRegistry = ProviderAdapterRegistry.layerFromAdapters([ |
| 1242 | + makeTestAdapter({ |
| 1243 | + instanceId: CODEX_MODEL_SELECTION.instanceId, |
| 1244 | + driver: CODEX_DRIVER, |
| 1245 | + capabilities: CodexProviderCapabilitiesV2, |
| 1246 | + modelSelection: CODEX_MODEL_SELECTION, |
| 1247 | + responseByRunOrdinal: { 2: "Source work" }, |
| 1248 | + capturedTurns, |
| 1249 | + }), |
| 1250 | + // No window and no usage, like an ACP registry agent that sends no usage_update. |
| 1251 | + makeTestAdapter({ |
| 1252 | + instanceId: CLAUDE_MODEL_SELECTION.instanceId, |
| 1253 | + driver: CLAUDE_DRIVER, |
| 1254 | + capabilities: ClaudeProviderCapabilitiesV2, |
| 1255 | + modelSelection: CLAUDE_MODEL_SELECTION, |
| 1256 | + responseByRunOrdinal: { 1: prose }, |
| 1257 | + capturedTurns, |
| 1258 | + nativeThreadGeneration: generation, |
| 1259 | + }), |
| 1260 | + ]); |
| 1261 | + yield* Effect.gen(function* () { |
| 1262 | + const orchestrator = yield* Orchestrator.OrchestratorV2; |
| 1263 | + const worker = yield* EffectWorker.OrchestrationEffectWorkerV2; |
| 1264 | + const dispatch = (ordinal: number, text: string, selection: ModelSelection) => |
| 1265 | + orchestrator.dispatch({ |
| 1266 | + type: "message.dispatch", |
| 1267 | + commandId: CommandId.make(`headroom:${ordinal}`), |
| 1268 | + threadId, |
| 1269 | + messageId: MessageId.make(`headroom:${ordinal}`), |
| 1270 | + createdBy: "user", |
| 1271 | + creationSource: "web", |
| 1272 | + text, |
| 1273 | + attachments: [], |
| 1274 | + modelSelection: selection, |
| 1275 | + dispatchMode: { type: "start_immediately" }, |
| 1276 | + }); |
| 1277 | + const wait = (ordinal: number) => |
| 1278 | + orchestrator.streamStoredEvents.pipe( |
| 1279 | + Stream.filter( |
| 1280 | + ({ event }) => |
| 1281 | + event.type === "run.updated" && |
| 1282 | + event.payload.ordinal === ordinal && |
| 1283 | + (event.payload.status === "completed" || event.payload.status === "failed"), |
| 1284 | + ), |
| 1285 | + Stream.runHead, |
| 1286 | + Effect.andThen(worker.drain()), |
| 1287 | + ); |
| 1288 | + yield* orchestrator.dispatch({ |
| 1289 | + type: "thread.create", |
| 1290 | + commandId: CommandId.make("headroom:create"), |
| 1291 | + threadId, |
| 1292 | + projectId, |
| 1293 | + createdBy: "user", |
| 1294 | + creationSource: "web", |
| 1295 | + title: "Handoff estimate headroom", |
| 1296 | + modelSelection: CLAUDE_MODEL_SELECTION, |
| 1297 | + runtimeMode: "full-access", |
| 1298 | + interactionMode: "default", |
| 1299 | + branch: null, |
| 1300 | + worktreePath: null, |
| 1301 | + }); |
| 1302 | + yield* dispatch(1, "Write the long report", CLAUDE_MODEL_SELECTION); |
| 1303 | + yield* wait(1); |
| 1304 | + yield* dispatch(2, "Continue elsewhere", CODEX_MODEL_SELECTION); |
| 1305 | + yield* wait(2); |
| 1306 | + yield* dispatch(3, "Back to the first provider", CLAUDE_MODEL_SELECTION); |
| 1307 | + yield* wait(3); |
| 1308 | + assert.equal( |
| 1309 | + (yield* orchestrator.getThreadProjection(threadId)).runs.at(-1)?.status, |
| 1310 | + "completed", |
| 1311 | + ); |
| 1312 | + // A second generation means T3 discarded the native session as full. |
| 1313 | + assert.equal(yield* Ref.get(generation), 1); |
| 1314 | + }).pipe( |
| 1315 | + Effect.provide( |
| 1316 | + ProviderReplayHarness.layerWithRegistry( |
| 1317 | + { |
| 1318 | + name: "handoff-estimate-headroom", |
| 1319 | + runtimePolicyOverride: { |
| 1320 | + cwd, |
| 1321 | + approvalPolicy: "never", |
| 1322 | + sandboxPolicy: { type: "readOnly" }, |
| 1323 | + }, |
| 1324 | + }, |
| 1325 | + layerRegistry, |
| 1326 | + ), |
| 1327 | + ), |
| 1328 | + ); |
| 1329 | + }), |
| 1330 | + ), |
| 1331 | + ); |
| 1332 | + |
1233 | 1333 | it.live.each(["native", "legacy"] as const)( |
1234 | 1334 | "starts a replacement native thread as new after the resume fallback with %s attempts", |
1235 | 1335 | (attempts) => |
|