Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
bd3647f
test(server): scored model guidance outranks newer one-sample groups
ScriptedAlchemy Nov 16, 2026
49f3686
fix(server): rank model guidance by scored samples
ScriptedAlchemy Nov 16, 2026
4682d06
test(server): quality-neutral model options share one guidance group
ScriptedAlchemy Nov 16, 2026
dccd7b1
fix(server): group model guidance by output-quality options
ScriptedAlchemy Nov 16, 2026
7bea4a3
test(server): automated wakes are not judged as user prompts
ScriptedAlchemy Nov 16, 2026
952da84
fix(server): skip automated wakes instead of scoring them
ScriptedAlchemy Nov 16, 2026
656d10a
test(server): a failed evaluation records a bounded cause
ScriptedAlchemy Nov 16, 2026
548608b
fix(server): record why a model evaluation failed
ScriptedAlchemy Nov 16, 2026
aab869e
fix(server): keep model guidance types exact
ScriptedAlchemy Nov 16, 2026
4b73048
test(server): a settled delegated child never returns to model guidance
ScriptedAlchemy Nov 16, 2026
252509a
fix(server): score a turn again after its delegated children settle
ScriptedAlchemy Nov 16, 2026
8d05906
test(server): a child that settles mid-evaluation leaves the turn uns…
ScriptedAlchemy Nov 16, 2026
5c903ad
fix(server): retry a model evaluation when its snapshot goes stale
ScriptedAlchemy Nov 16, 2026
4d9dceb
test(server): a scored automated wake still feeds model guidance
ScriptedAlchemy Nov 16, 2026
d409383
fix(server): keep scored automated wakes out of model guidance
ScriptedAlchemy Nov 16, 2026
a8ff1d8
fix(server): use the model-evaluation event indexes for refresh lookups
ScriptedAlchemy Nov 16, 2026
6209231
test(server): thinking options are pooled with latency settings
ScriptedAlchemy Nov 16, 2026
54f81b4
fix(server): group model guidance by every reasoning option
ScriptedAlchemy Nov 16, 2026
53a53a5
test(server): a failed evaluation can store raw provider output
ScriptedAlchemy Nov 16, 2026
7dba64c
test(server): one event-stream error stops subagent evaluation refresh
ScriptedAlchemy Nov 16, 2026
0b8e9d8
fix(server): resume subagent evaluation refresh after a stream error
ScriptedAlchemy Nov 16, 2026
93825c5
fix(server): store a classified cause when model evaluation fails
ScriptedAlchemy Nov 16, 2026
a600d3d
test(server): type the dropped subscription as a domain stream error
ScriptedAlchemy Nov 16, 2026
978992f
test(server): the refresh test awaits the enqueue instead of yielding
ScriptedAlchemy Nov 16, 2026
6fef5a0
perf(server): evaluation lookups use the whole event index
ScriptedAlchemy Nov 16, 2026
787b466
test(server): behaviour options, settling children and unavailable ju…
ScriptedAlchemy Nov 16, 2026
e78b52e
fix(server): model guidance pools only quality-neutral options and re…
ScriptedAlchemy Nov 16, 2026
0e37cbc
revert(client-runtime): keep the reasoning option list where it was
ScriptedAlchemy Nov 16, 2026
8f44414
docs: model evaluations describe pooled options, wakes and delegated …
ScriptedAlchemy Nov 16, 2026
127af66
docs: model evaluations give the judge-scale reason its own sentence
ScriptedAlchemy Nov 16, 2026
293af03
fix(server): keep edited evidence out of evaluation retries
ScriptedAlchemy Nov 16, 2026
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { assert, it } from "@effect/vitest";
import { RunId, ThreadId, type OrchestrationV2DomainEvent } from "@t3tools/contracts";
import * as Deferred from "effect/Deferred";
import * as Effect from "effect/Effect";
import * as Fiber from "effect/Fiber";
import * as Queue from "effect/Queue";
import * as Stream from "effect/Stream";
import * as TestClock from "effect/testing/TestClock";

import * as Orchestrator from "../orchestration-v2/Orchestrator.ts";
import { followSettledSubagentRefreshes } from "./ModelEvaluationSubagentRefresh.ts";

const runId = RunId.make("parent-run");

const settledChild = {
type: "turn-item.updated",
threadId: ThreadId.make("parent-thread"),
runId,
payload: { type: "subagent", status: "completed", runId },
} as OrchestrationV2DomainEvent;

it.effect("keeps refreshing after the event stream fails", () =>
Effect.gen(function* () {
const events = yield* Queue.unbounded<OrchestrationV2DomainEvent>();
const started = yield* Deferred.make<void>();
const refreshed = yield* Deferred.make<RunId | undefined>();
let subscriptions = 0;
const fiber = yield* Effect.forkChild(
followSettledSubagentRefreshes({
evaluations: {
enqueueSettledSubagentRefreshes: (input) =>
input?.runId === undefined
? Effect.void
: Deferred.succeed(refreshed, input.runId).pipe(Effect.asVoid),
},
orchestrator: {
getLatestEventSequence: () => Deferred.succeed(started, undefined).pipe(Effect.as(0)),
streamDomainEventsAfter: () => {
subscriptions += 1;
return subscriptions === 1
? Stream.fail(
new Orchestrator.OrchestratorDomainEventStreamError({
cause: new Error("subscription dropped"),
}),
)
: Stream.fromQueue(events);
},
},
}),
);
yield* Deferred.await(started);
yield* TestClock.adjust("1 second");
yield* Queue.offer(events, settledChild);
assert.equal(yield* Deferred.await(refreshed), runId);
yield* Fiber.interrupt(fiber);
}),
);
94 changes: 94 additions & 0 deletions apps/server/src/modelEvaluations/ModelEvaluationSubagentRefresh.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import {
isOrchestrationV2WorkActive,
type OrchestrationV2DomainEvent,
type RunId,
type ThreadId,
} from "@t3tools/contracts";
import * as Context from "effect/Context";
import * as Duration from "effect/Duration";
import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
import * as Schedule from "effect/Schedule";
import type * as Scope from "effect/Scope";
import * as Stream from "effect/Stream";

import * as Orchestrator from "../orchestration-v2/Orchestrator.ts";
import { forkParked } from "../serverActivation.ts";
import * as ModelEvaluations from "./ModelEvaluations.ts";

export class ModelEvaluationSubagentRefresh extends Context.Service<
ModelEvaluationSubagentRefresh,
{
readonly start: () => Effect.Effect<void, never, Scope.Scope>;
}
>()("t3/modelEvaluations/ModelEvaluationSubagentRefresh") {}

const subscriptionBackoff = Schedule.exponential("1 second").pipe(
Schedule.modifyDelay(({ duration }) =>
Effect.succeed(Duration.min(duration, Duration.minutes(1))),
),
);

function settledSubagentRun(
event: OrchestrationV2DomainEvent,
): { readonly threadId: ThreadId; readonly runId: RunId } | undefined {
if (event.type !== "turn-item.updated" || event.payload.type !== "subagent") return undefined;
if (isOrchestrationV2WorkActive(event.payload.status)) return undefined;
const runId = event.runId ?? event.payload.runId;
if (runId === undefined || runId === null) return undefined;
return { threadId: event.threadId, runId };
}

export const followSettledSubagentRefreshes = Effect.fn("ModelEvaluationSubagentRefresh.follow")(
function* (input: {
readonly evaluations: Pick<
ModelEvaluations.ModelEvaluations["Service"],
"enqueueSettledSubagentRefreshes"
>;
readonly orchestrator: Pick<
Orchestrator.OrchestratorV2["Service"],
"getLatestEventSequence" | "streamDomainEventsAfter"
>;
}) {
yield* Effect.gen(function* () {
const after = yield* input.orchestrator.getLatestEventSequence();
yield* input.evaluations
.enqueueSettledSubagentRefreshes()
.pipe(
Effect.catchCause((cause) =>
Effect.logWarning("Could not refresh settled subagent evaluations", { cause }),
),
);
yield* Stream.runForEach(input.orchestrator.streamDomainEventsAfter(after), (event) => {
const run = settledSubagentRun(event);
if (run === undefined) return Effect.void;
return input.evaluations.enqueueSettledSubagentRefreshes({ runId: run.runId }).pipe(
Effect.catchCause((cause) =>
Effect.logWarning("Could not refresh a settled subagent evaluation", {
threadId: run.threadId,
runId: run.runId,
cause,
}),
),
);
});
}).pipe(
Effect.tapCause((cause) =>
Effect.logWarning("settled subagent evaluation refresh stopped", { cause }),
),
Effect.retry(subscriptionBackoff),
);
},
);

const make = Effect.gen(function* () {
const evaluations = yield* ModelEvaluations.ModelEvaluations;
const orchestrator = yield* Orchestrator.OrchestratorV2;

const start: ModelEvaluationSubagentRefresh["Service"]["start"] = () =>
forkParked(followSettledSubagentRefreshes({ evaluations, orchestrator }));

return { start } satisfies ModelEvaluationSubagentRefresh["Service"];
});

export const layer = Layer.effect(ModelEvaluationSubagentRefresh, make);
Loading
Loading