The Open Framework for Building Agents
fix(eve): give dynamic model resolvers the index of the step they select for (#5130)
roboeve[bot]5cf30b61b3da
diff --git a/.changeset/dynamic-model-step-index.md b/.changeset/dynamic-model-step-index.mdnew file mode 100644index 000000000..69cbf13e5--- /dev/null+++ b/.changeset/dynamic-model-step-index.md@@ -0,0 +1,5 @@+---+"eve": patch+---++A dynamic model resolver's `step.started` event now carries the index of the step it selects a model for. From the second step of a turn on, it used to carry the previous step's index, so per-step work keyed on `stepIndex` was attributed to the wrong step.diff --git a/packages/eve/src/harness/model-call/run.ts b/packages/eve/src/harness/model-call/run.tsindex d26f464ea..bf3b63b63 100644--- a/packages/eve/src/harness/model-call/run.ts+++ b/packages/eve/src/harness/model-call/run.ts@@ -18,7 +18,7 @@ import {} from "#harness/hitl/index.js";import { stepStartedForResolvers } from "#harness/session-machine/resolver-events.js";import { startStep } from "#harness/session-machine/transitions.js";-import { activeTurnId } from "#harness/session-machine/view.js";+import { activeTurnId, nextStepIndex } from "#harness/session-machine/view.js";import { failBoundaryEvent, failModelSelection, type Step } from "#harness/step/context.js";import type { TurnInput } from "#harness/step/intake.js";import {@@ -194,7 +194,8 @@ async function selectModel(event: stepStartedForResolvers({modelId: step.session.agent.modelReference?.id ?? "dynamic",sequence: position.sequence,- stepIndex: position.stepIndex,+ // Selection runs before `startStep` records the step, so the position is still the last one.+ stepIndex: nextStepIndex(step.view().projection),turnId: activeTurnId(position),}),messages: validateHarnessModelMessages(step.projectHistory(withClientContext(prompt))),diff --git a/packages/eve/src/harness/tool-loop.test.ts b/packages/eve/src/harness/tool-loop.test.tsindex 4cbe312f2..550028dd4 100644--- a/packages/eve/src/harness/tool-loop.test.ts+++ b/packages/eve/src/harness/tool-loop.test.ts@@ -1491,7 +1491,7 @@ describe("createToolLoopHarness", () => {});// Regression for #5128: the resolver heard the previous step's index from the second step on.- it.fails("gives the dynamic model resolver the index of the step it selects for", async () => {+ it("gives the dynamic model resolver the index of the step it selects for", async () => {const addStep = (toolCallId: string) => {const toolCall = { input: {}, toolCallId, toolName: "add", type: "tool-call" };const toolResult = { ...toolCall, output: "42", type: "tool-result" };