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 — fix(claude): scope model observations to the current attempt · pingdotgg/t3code@2c8dfed

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/server/src/orchestration-v2
    • Orchestrator.ts
    • ProjectionStore.test.ts
    • ProjectionStore.ts
    • ProviderEventIngestor.ts
    • SelectionRestart.integration.test.ts
  • packages/client-runtime/src/state
    • orchestrationV2Projection.test.ts
    • orchestrationV2Projection.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/Orchestrator.ts
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4967,6 +4967,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
49674967
);
49684968
const restartedRun: OrchestrationV2Run = {
49694969
...targetRun,
4970+
observedModel: undefined,
49704971
providerInstanceId: input.modelSelection.instanceId,
49714972
modelSelection: input.modelSelection,
49724973
providerThreadId: restartProviderThread.id,
Collapse file

‎apps/server/src/orchestration-v2/ProjectionStore.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/ProjectionStore.test.ts
+95Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,6 +1560,101 @@ it.layer(layerTest)("ProjectionStoreV2", (it) => {
15601560
assert.deepEqual(yield* store.getTurnStartHistory(threadId, [RunId.make("run:other")]), []);
15611561
}),
15621562
);
1563+
it.effect(
1564+
"records root model observations without overwriting lifecycle state or another attempt",
1565+
() =>
1566+
Effect.gen(function* () {
1567+
const store = yield* ProjectionStore.ProjectionStoreV2;
1568+
const threadId = yield* addRolledBackRecoveryCandidate("observed-model-attempt");
1569+
const now = yield* DateTime.now;
1570+
const original = (yield* store.getThreadProjection(threadId)).runs[0];
1571+
assert(original !== undefined && original.rootNodeId !== null);
1572+
const run = {
1573+
...original,
1574+
activeAttemptId: RunAttemptId.make("attempt-observed-first"),
1575+
status: "completed" as const,
1576+
completedAt: now,
1577+
};
1578+
yield* store.apply({
1579+
id: EventId.make("event-observed-completed"),
1580+
type: "run.updated",
1581+
threadId,
1582+
runId: run.id,
1583+
occurredAt: now,
1584+
payload: run,
1585+
});
1586+
const observation = {
1587+
id: EventId.make("event-observed-first"),
1588+
type: "provider-turn.updated" as const,
1589+
threadId,
1590+
runId: run.id,
1591+
occurredAt: now,
1592+
payload: {
1593+
id: ProviderTurnId.make("turn-observed-first"),
1594+
providerThreadId: ProviderThreadId.make("thread-observed-provider"),
1595+
nodeId: original.rootNodeId,
1596+
runAttemptId: run.activeAttemptId,
1597+
nativeTurnRef: null,
1598+
ordinal: 1,
1599+
status: "running" as const,
1600+
observedModel: "claude-sonnet-5-5",
1601+
startedAt: now,
1602+
completedAt: null,
1603+
},
1604+
};
1605+
yield* store.apply(observation);
1606+
const recorded = (yield* store.getThreadProjection(threadId)).runs[0];
1607+
assert.deepEqual(recorded, { ...run, observedModel: "claude-sonnet-5-5" });
1608+
1609+
yield* store.apply({
1610+
id: EventId.make("event-observed-stale-snapshot"),
1611+
type: "run.updated",
1612+
threadId,
1613+
runId: run.id,
1614+
occurredAt: now,
1615+
payload: { ...run, observedModel: "stale-snapshot-model" },
1616+
});
1617+
assert.deepEqual((yield* store.getThreadProjection(threadId)).runs[0], {
1618+
...run,
1619+
observedModel: "claude-sonnet-5-5",
1620+
});
1621+
1622+
const restarted = {
1623+
...run,
1624+
status: "starting" as const,
1625+
completedAt: null,
1626+
rootNodeId: NodeId.make("node-observed-second"),
1627+
activeAttemptId: RunAttemptId.make("attempt-observed-second"),
1628+
};
1629+
yield* store.apply({
1630+
id: EventId.make("event-observed-restart"),
1631+
type: "run.updated",
1632+
threadId,
1633+
runId: run.id,
1634+
occurredAt: now,
1635+
payload: restarted,
1636+
});
1637+
yield* store.apply({ ...observation, id: EventId.make("event-observed-late-first") });
1638+
assert.deepEqual((yield* store.getThreadProjection(threadId)).runs[0], restarted);
1639+
1640+
yield* store.apply({
1641+
...observation,
1642+
id: EventId.make("event-observed-second"),
1643+
payload: {
1644+
...observation.payload,
1645+
id: ProviderTurnId.make("turn-observed-second"),
1646+
ordinal: 2,
1647+
nodeId: restarted.rootNodeId,
1648+
runAttemptId: restarted.activeAttemptId,
1649+
observedModel: "claude-opus-5-5",
1650+
},
1651+
});
1652+
assert.deepEqual((yield* store.getThreadProjection(threadId)).runs[0], {
1653+
...restarted,
1654+
observedModel: "claude-opus-5-5",
1655+
});
1656+
}),
1657+
);
15631658
it.effect("preserves stored provider usage when a terminal update omits it", () =>
15641659
Effect.gen(function* () {
15651660
const projectionStore = yield* ProjectionStore.ProjectionStoreV2;
Collapse file

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

Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/ProjectionStore.ts
+42-9Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ function preserveRunRecordedFields(
697697
if (current === undefined) return next;
698698
return {
699699
...next,
700-
...(next.observedModel === undefined && current.observedModel !== undefined
700+
...(current.observedModel !== undefined && next.activeAttemptId === current.activeAttemptId
701701
? { observedModel: current.observedModel }
702702
: {}),
703703
...(next.delegatedCompletion === undefined && current.delegatedCompletion !== undefined
@@ -881,11 +881,22 @@ export function applyToProjection(
881881
: base.thread,
882882
providerThreads: upsertById(base.providerThreads, event.payload),
883883
};
884-
case "provider-turn.updated":
885-
return {
886-
...base,
887-
providerTurns: upsertProviderTurn(base.providerTurns, event.payload),
888-
};
884+
case "provider-turn.updated": {
885+
const turn = event.payload;
886+
const observedModel = turn.observedModel;
887+
const runs =
888+
observedModel === undefined || turn.tokenUsage !== undefined
889+
? base.runs
890+
: base.runs.map((run) =>
891+
run.rootNodeId === turn.nodeId &&
892+
run.activeAttemptId === turn.runAttemptId &&
893+
run.observedModel !== observedModel
894+
? { ...run, observedModel }
895+
: run,
896+
);
897+
898+
return { ...base, runs, providerTurns: upsertProviderTurn(base.providerTurns, turn) };
899+
}
889900
case "runtime-request.updated":
890901
return {
891902
...base,
@@ -1839,9 +1850,13 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
18391850
OR item.payload_json LIKE '%"viewedImagePath"%'
18401851
OR item.payload_json LIKE '%"toolName":"%delegate_task"%')`;
18411852

1842-
const keepRecordedRunField = (payload: Statement.Fragment, path: string) => sql`
1853+
const keepRecordedRunField = (
1854+
payload: Statement.Fragment,
1855+
path: string,
1856+
condition = sql`json_type(excluded.payload_json, ${path}) IS NULL`,
1857+
) => sql`
18431858
CASE
1844-
WHEN json_type(excluded.payload_json, ${path}) IS NULL
1859+
WHEN ${condition}
18451860
AND json_type(orchestration_v2_projection_runs.payload_json, ${path}) IS NOT NULL
18461861
THEN json_set(
18471862
${payload},
@@ -1979,7 +1994,12 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
19791994
completed_at = excluded.completed_at,
19801995
payload_json = ${keepRecordedRunField(
19811996
keepRecordedRunField(
1982-
keepRecordedRunField(sql`excluded.payload_json`, "$.observedModel"),
1997+
keepRecordedRunField(
1998+
sql`excluded.payload_json`,
1999+
"$.observedModel",
2000+
sql`json_extract(excluded.payload_json, '$.activeAttemptId') IS
2001+
json_extract(orchestration_v2_projection_runs.payload_json, '$.activeAttemptId')`,
2002+
),
19832003
"$.delegatedCompletion",
19842004
),
19852005
"$.restartCancelledBackgroundWork",
@@ -2353,6 +2373,19 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
23532373
completed_at = excluded.completed_at,
23542374
payload_json = excluded.payload_json
23552375
`;
2376+
if (
2377+
event.payload.observedModel !== undefined &&
2378+
event.payload.tokenUsage === undefined
2379+
) {
2380+
yield* sql`
2381+
UPDATE orchestration_v2_projection_runs
2382+
SET payload_json = json_set(payload_json, '$.observedModel', ${event.payload.observedModel})
2383+
WHERE thread_id = ${event.threadId}
2384+
AND json_extract(payload_json, '$.rootNodeId') = ${event.payload.nodeId}
2385+
AND json_extract(payload_json, '$.activeAttemptId') IS ${event.payload.runAttemptId}
2386+
AND json_extract(payload_json, '$.observedModel') IS NOT ${event.payload.observedModel}
2387+
`;
2388+
}
23562389
break;
23572390
}
23582391
case "runtime-request.updated": {
Collapse file

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

Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/ProviderEventIngestor.ts
+1-24Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -602,30 +602,8 @@ export const layer: Layer.Layer<
602602
})),
603603
];
604604
}
605-
case "provider_turn.updated": {
606-
const turn = input.event.providerTurn;
607-
const updates: OrchestrationV2DomainEvent[] = [];
608-
609-
// Usage frames repeat the observation; avoid a run read on every token update.
610-
if (turn.observedModel !== undefined && turn.tokenUsage === undefined) {
611-
const projection = yield* projections.getThreadRecords(input.threadId, ["runs"]);
612-
const run = projection.runs.find(
613-
(candidate) =>
614-
candidate.rootNodeId === turn.nodeId &&
615-
candidate.activeAttemptId === turn.runAttemptId,
616-
);
617-
if (run !== undefined && run.observedModel !== turn.observedModel) {
618-
updates.push(
619-
yield* makeDomainEvent(input, {
620-
type: "run.updated",
621-
runId: run.id,
622-
payload: { ...run, observedModel: turn.observedModel },
623-
}),
624-
);
625-
}
626-
}
605+
case "provider_turn.updated":
627606
return [
628-
...updates,
629607
...(["completed", "interrupted", "failed", "cancelled"].includes(
630608
input.event.providerTurn.status,
631609
)
@@ -642,7 +620,6 @@ export const layer: Layer.Layer<
642620
nodeId: input.event.providerTurn.nodeId,
643621
}),
644622
];
645-
}
646623
case "node.updated":
647624
// Adapters send an unchanged node again with each text delta. Compare with the
648625
// stored node, not the last one sent, because the server also writes nodes.
Collapse file

‎apps/server/src/orchestration-v2/SelectionRestart.integration.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/SelectionRestart.integration.test.ts
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ function makeRestartAdapter(
242242
strength: "strong",
243243
},
244244
ordinal: input.providerTurnOrdinal,
245+
observedModel: initialSelection.model,
245246
status: "running",
246247
startedAt: occurredAt,
247248
completedAt: null,
@@ -343,6 +344,7 @@ it.live("retries a failed selection restart session open before completing", ()
343344
yield* worker.drain();
344345
const activeProjection = yield* orchestrator.getThreadProjection(threadId);
345346
assert.isTrue(activeProjection.providerTurns.some((turn) => turn.status === "running"));
347+
assert.equal(activeProjection.runs[0]?.observedModel, initialSelection.model);
346348
const activeRunId = activeProjection.runs[0]?.id;
347349
if (activeRunId === undefined) {
348350
return yield* Effect.die("active restart test run is missing");
@@ -408,6 +410,7 @@ it.live("retries a failed selection restart session open before completing", ()
408410
);
409411
assert.equal(projection.runs.at(-1)?.modelSelection.model, replacementSelection.model);
410412
assert.equal(projection.runs.at(-1)?.status, "completed");
413+
assert.equal(projection.runs.at(-1)?.observedModel, undefined);
411414
assert.isTrue(captured.failedReplacementOpen);
412415
assert.equal(captured.closedSessionCount, 0);
413416
assert.deepEqual(
Collapse file

‎packages/client-runtime/src/state/orchestrationV2Projection.test.ts‎

Copy file name to clipboardExpand all lines: packages/client-runtime/src/state/orchestrationV2Projection.test.ts
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
NodeId,
1313
ProviderThreadId,
1414
ProviderTurnId,
15+
RunAttemptId,
1516
RunId,
1617
ThreadId,
1718
TurnItemId,
@@ -151,6 +152,16 @@ describe("applyOrchestrationV2ProjectionEvent", () => {
151152

152153
expect(next?.runs[0]?.observedModel).toBe("claude-sonnet-5-5");
153154
expect(next?.runs[0]?.modelSelection).toEqual(run.modelSelection);
155+
156+
const restarted = applyOrchestrationV2ProjectionEvent(next, {
157+
id: EventId.make("event-run-provenance-restart"),
158+
type: "run.updated",
159+
threadId,
160+
runId,
161+
occurredAt: now,
162+
payload: { ...run, activeAttemptId: RunAttemptId.make("attempt-reducer-new") },
163+
});
164+
expect(restarted?.runs[0]?.observedModel).toBeUndefined();
154165
});
155166

156167
it("keeps live token usage when the terminal provider turn omits it", () => {
Collapse file

‎packages/client-runtime/src/state/orchestrationV2Projection.ts‎

Copy file name to clipboardExpand all lines: packages/client-runtime/src/state/orchestrationV2Projection.ts
+14-1Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,8 @@ export function applyOrchestrationV2ProjectionEvent(
301301
case "run.updated": {
302302
const current = base.runs.find((run) => run.id === event.payload.id);
303303
const payload =
304-
event.payload.observedModel === undefined && current?.observedModel !== undefined
304+
current?.observedModel !== undefined &&
305+
event.payload.activeAttemptId === current.activeAttemptId
305306
? { ...event.payload, observedModel: current.observedModel }
306307
: event.payload;
307308
const next = { ...base, runs: upsertEntity(base.runs, payload) };
@@ -357,8 +358,20 @@ export function applyOrchestrationV2ProjectionEvent(
357358
const observedModel = event.payload.observedModel ?? current?.observedModel;
358359
const tokenUsage = event.payload.tokenUsage ?? current?.tokenUsage;
359360

361+
const runs =
362+
event.payload.observedModel === undefined || event.payload.tokenUsage !== undefined
363+
? base.runs
364+
: base.runs.map((run) =>
365+
run.rootNodeId === event.payload.nodeId &&
366+
run.activeAttemptId === event.payload.runAttemptId &&
367+
run.observedModel !== event.payload.observedModel
368+
? { ...run, observedModel: event.payload.observedModel }
369+
: run,
370+
);
371+
360372
return {
361373
...base,
374+
runs,
362375
providerTurns: upsertEntity(base.providerTurns, {
363376
...event.payload,
364377
...(observedModel === undefined ? {} : { observedModel }),

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.