Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 14 additions & 24 deletions apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2479,6 +2479,10 @@ interface ActiveClaudeTurnContext {
readonly providerTurnId: OrchestrationV2ProviderTurn["id"];
readonly providerTurnOrdinal: number;
readonly startedAt: DateTime.Utc;
// Item ordinals allocated in this turn. Later turns never look items up
// here: a subagent resumed from another turn keeps its ordinal on the
// session subagent registry.
readonly itemOrdinals: Map<string, number>;
readonly assistant: {
fallbackText: string;
fallbackNativeItemId: string;
Expand Down Expand Up @@ -2788,8 +2792,6 @@ export function makeClaudeAdapterV2(
const steeredTurns = yield* Ref.make(new Set<OrchestrationV2ProviderTurn["id"]>());
const queryContext = yield* Ref.make<ClaudeLiveQueryContext | null>(null);
const openedNativeThreads = yield* Ref.make(new Set<string>());
const itemOrdinals = yield* Ref.make(new Map<string, number>());
const nextItemOrdinalsByTurn = yield* Ref.make(new Map<string, number>());
const latestPlanByKind = yield* Ref.make(new Map<string, OrchestrationV2PlanArtifact>());
const planIdsByNativeItem = yield* Ref.make(
new Map<string, OrchestrationV2PlanArtifact["id"]>(),
Expand Down Expand Up @@ -3284,29 +3286,16 @@ export function makeClaudeAdapterV2(
}),
});

const resolveItemOrdinal = Effect.fnUntraced(function* (
context: ActiveClaudeTurnContext,
nativeItemId: string,
) {
const existing = (yield* Ref.get(itemOrdinals)).get(nativeItemId);
if (existing !== undefined) {
return existing;
}

const nextWithinTurn = yield* Ref.modify(nextItemOrdinalsByTurn, (current) => {
const next = (current.get(context.nativeTurnId) ?? 0) + 1;
const updated = new Map(current);
updated.set(context.nativeTurnId, next);
return [next, updated];
});
const nextOrdinal = context.input.providerTurnOrdinal * 100 + nextWithinTurn;
yield* Ref.update(itemOrdinals, (current) => {
const updated = new Map(current);
updated.set(nativeItemId, nextOrdinal);
return updated;
const resolveItemOrdinal = (context: ActiveClaudeTurnContext, nativeItemId: string) =>
Effect.sync(() => {
const existing = context.itemOrdinals.get(nativeItemId);
if (existing !== undefined) {
return existing;
}
const ordinal = context.input.providerTurnOrdinal * 100 + context.itemOrdinals.size + 1;
context.itemOrdinals.set(nativeItemId, ordinal);
return ordinal;
});
return nextOrdinal;
});

const providerTurnPayload = (input: {
readonly context: ActiveClaudeTurnContext;
Expand Down Expand Up @@ -6397,6 +6386,7 @@ export function makeClaudeAdapterV2(
providerTurnId,
providerTurnOrdinal,
startedAt,
itemOrdinals: new Map(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes ordinal allocation for native item IDs reused across turns: the fresh map now assigns an ordinal in the new turn rather than retaining the previous turn's value. Could you add focused adapter tests covering repeated IDs across turns and resumed subagents, asserting the emitted ordinals and ordering? The existing resume test checks routing but not ordinals.

Posted via Macroscope — Effect Service Conventions

assistant: {
fallbackText: "",
fallbackNativeItemId: `assistant:${turnInput.runId}`,
Expand Down
Loading