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
35 changes: 12 additions & 23 deletions apps/server/src/orchestration-v2/Adapters/CursorAdapterV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,8 @@ interface ActiveCursorTurn {
readonly providerTurnId: OrchestrationV2ProviderTurn["id"];
readonly startedAt: DateTime.Utc;
readonly completed: Deferred.Deferred<void, never>;
// Item ordinals allocated in this turn. No later turn looks items up here.
readonly itemOrdinals: Map<string, number>;
readonly tools: Map<string, ActiveCursorToolCall>;
readonly subagents: Map<string, ActiveCursorSubagent>;
readonly assistant: ActiveCursorTextStream;
Expand Down Expand Up @@ -908,35 +910,21 @@ export function makeCursorAdapterV2(
const events = yield* Queue.unbounded<ProviderAdapterV2Event>();
const liveAgent = yield* Ref.make<CursorLiveAgent | null>(null);
const activeTurn = yield* Ref.make<ActiveCursorTurn | null>(null);
const itemOrdinals = yield* Ref.make(new Map<string, number>());
const nextItemOrdinalsByTurn = yield* Ref.make(new Map<string, number>());
const planIds = yield* Ref.make(new Map<string, OrchestrationV2PlanArtifact["id"]>());

const emitProviderEvent = (event: ProviderAdapterV2Event) =>
Queue.offer(events, event).pipe(Effect.asVoid);

const resolveItemOrdinal = Effect.fnUntraced(function* (
context: ActiveCursorTurn,
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.run.runId) ?? 0) + 1;
const updated = new Map(current);
updated.set(context.run.runId, next);
return [next, updated];
});
const ordinal = context.input.providerTurnOrdinal * 100 + nextWithinTurn;
yield* Ref.update(itemOrdinals, (current) => {
const updated = new Map(current);
updated.set(nativeItemId, ordinal);
return updated;
const resolveItemOrdinal = (context: ActiveCursorTurn, 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 ordinal;
});

const resolvePlanId = Effect.fnUntraced(function* (
context: ActiveCursorTurn,
Expand Down Expand Up @@ -2242,6 +2230,7 @@ export function makeCursorAdapterV2(
providerTurnId,
startedAt,
completed,
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 backend behavior: reusing a native item ID in a later turn now assigns a new turn-local ordinal. Could you add a focused adapter test covering repeated IDs across turns and stable ordinals within a turn? The existing two-turn test does not assert ordinals. This needs a test-file change, so no inline fix is applicable.

Posted via Macroscope — Effect Service Conventions

tools: new Map(),
subagents: new Map(),
assistant: {
Expand Down
Loading