GeezerVison is showing github.com — fix(server): Claude subagents resumed after a missed launch get their… · AdEx-Partners-DE/t3code@c87221f
File treeExpand file treeCollapse file tree Open diff view settings apps/server/src/orchestration-v2 packages/provider-core/src/server
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts +8-5Lines changed: 8 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -11744,12 +11744,15 @@ describe("ClaudeAdapterV2 background wake turns", () => { | 11744 | 11744 | threadMessages(harness.events, member?.childThreadId).map((event) => event.message.text), | 11745 | 11745 | ["Reply with exactly: A1"], | 11746 | 11746 | ); | 11747 | | - assert.isFalse( | 11748 | | - harness.events.some( | 11749 | | - (event) => | 11750 | | - event.type === "app_thread.created" && | 11751 | | - event.appThread.id === coordinator?.childThreadId, | | 11747 | + // T3 may have missed the launch, so the recovered coordinator's | | 11748 | + // thread is created only if it does not exist yet. | | 11749 | + assert.deepEqual( | | 11750 | + harness.events.flatMap((event) => | | 11751 | + event.type === "app_thread.created" && event.appThread.id === coordinator?.childThreadId | | 11752 | + ? [event.createOnly] | | 11753 | + : [], | 11752 | 11754 | ), | | 11755 | + [true], | 11753 | 11756 | ); | 11754 | 11757 | }).pipe( | 11755 | 11758 | Effect.provide( | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts +10-8Lines changed: 10 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -4365,7 +4365,8 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* ( | 4365 | 4365 | // carry the launch call as parent_tool_use_id, which only the CLI's | 4366 | 4366 | // session storage still records. Registering the subagent as a | 4367 | 4367 | // finished run lets the resume reopen it like an in-session resume: | 4368 | | - // same child thread, launch prompt kept, the new prompt appended. | | 4368 | + // same child thread, launch prompt kept, the new prompt appended. The | | 4369 | + // reopen creates the child thread if T3 missed the launch. | 4369 | 4370 | const recoverResumedClaudeSubagent = Effect.fnUntraced(function* (resume: { | 4370 | 4371 | readonly context: ActiveClaudeTurnContext; | 4371 | 4372 | readonly nativeThreadId: string; | @@ -5071,13 +5072,14 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* ( | 5071 | 5072 | createdBy: "agent", | 5072 | 5073 | creationSource: "provider", | 5073 | 5074 | }); | 5074 | | - if (existingSubagent === undefined) { | 5075 | | - yield* emitProviderEvent({ | 5076 | | - type: "app_thread.created", | 5077 | | - driver: CLAUDE_PROVIDER, | 5078 | | - appThread: childThread, | 5079 | | - }); | 5080 | | - } | | 5075 | + // A subagent recovered on resume may have launched while T3 was | | 5076 | + // not listening, so its thread may not exist yet. | | 5077 | + yield* emitProviderEvent({ | | 5078 | + type: "app_thread.created", | | 5079 | + driver: CLAUDE_PROVIDER, | | 5080 | + appThread: childThread, | | 5081 | + ...(existingSubagent === undefined ? {} : { createOnly: true }), | | 5082 | + }); | 5081 | 5083 | subagent.childThread = childThread; | 5082 | 5084 | } | 5083 | 5085 |
| |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/ProviderEventIngestor.test.ts +14Lines changed: 14 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1670,6 +1670,20 @@ layer("ProviderEventIngestorV2", (it) => { | 1670 | 1670 | }), | 1671 | 1671 | [], | 1672 | 1672 | ); | | 1673 | + assert.deepEqual( | | 1674 | + yield* ingestor.ingestNormalized({ | | 1675 | + providerSessionId, | | 1676 | + providerInstanceId: modelSelection.instanceId, | | 1677 | + threadId: rootEvent.threadId, | | 1678 | + event: { | | 1679 | + type: "app_thread.created", | | 1680 | + driver: CODEX_DRIVER, | | 1681 | + appThread: { ...offered, title: "Recovered subagent" }, | | 1682 | + createOnly: true, | | 1683 | + }, | | 1684 | + }), | | 1685 | + [], | | 1686 | + ); | 1673 | 1687 | }), | 1674 | 1688 | ); | 1675 | 1689 |
| |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/ProviderEventIngestor.ts +3-2Lines changed: 3 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -544,8 +544,9 @@ export const layer: Layer.Layer< | 544 | 544 | ); | 545 | 545 | if ( | 546 | 546 | existing !== null && | 547 | | - existing.title === offered.title && | 548 | | - modelSelectionsEqual(existing.modelSelection, offered.modelSelection) | | 547 | + (input.event.createOnly === true || | | 548 | + (existing.title === offered.title && | | 549 | + modelSelectionsEqual(existing.modelSelection, offered.modelSelection))) | 549 | 550 | ) | 550 | 551 | return []; | 551 | 552 | const now = yield* DateTime.now; | |
Collapse file Copy file name to clipboardExpand all lines: packages/provider-core/src/server/ProviderAdapter.ts +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -80,6 +80,8 @@ export const ProviderAdapterV2Event = Schema.Union([ | 80 | 80 | type: Schema.Literal("app_thread.created"), | 81 | 81 | driver: ProviderDriverKind, | 82 | 82 | appThread: OrchestrationV2AppThread, | | 83 | + // Leaves an existing thread's metadata alone. | | 84 | + createOnly: Schema.optional(Schema.Boolean), | 83 | 85 | }), | 84 | 86 | Schema.Struct({ | 85 | 87 | type: Schema.Literal("provider_session.updated"), | |
|