Skip to content

Commit ba56d9a

Browse files
committed
fix(core): wait for plugin activation before each session step
1 parent 13afea6 commit ba56d9a

2 files changed

Lines changed: 43 additions & 1 deletion

File tree

‎packages/core/src/session/runner/llm.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ const layer = Layer.effect(
199199
})
200200

201201
const prepareContext = Effect.fn("SessionRunner.prepareContext")(function* (sessionID: SessionSchema.ID) {
202+
// A plugin reload closes config-provided agents and models until activation settles,
203+
// so a Step that starts inside the reload would not find its agent.
204+
yield* plugins.awaitActivation
202205
const selected = yield* context.select(sessionID)
203206
// A blocked initial instruction baseline must leave admitted input pending.
204207
yield* InstructionState.prepare(db, bus, selected.instructions, sessionID)

‎packages/core/test/session-runner.test.ts‎

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ const makeRunnerState = (compaction?: SessionRunnerModel.Resolved["compaction"])
216216
systemRemoved: false,
217217
systemUnavailable: false,
218218
systemLoadHook: Effect.void,
219+
activationHook: Effect.void as Effect.Effect<void>,
219220
skillBaselines: new Map<Agent.ID, string>(),
220221
authorizations: new Array<Tool.Context>(),
221222
executions: new Array<string>(),
@@ -423,7 +424,7 @@ const layer = Layer.unwrap(
423424
Permission.node.replace(permission),
424425
Config.node.replace(config),
425426
PluginSupervisor.node.replace(Layer.empty),
426-
Plugin.node.replace(Layer.mock(Plugin.Service, { awaitActivation: Effect.void })),
427+
Plugin.node.replace(Layer.mock(Plugin.Service, { awaitActivation: Effect.suspend(() => state.activationHook) })),
427428
SessionModelTransport.node.replace(modelTransport),
428429
]
429430
const runnerLayer = AppNodeBuilder.build(SessionRunnerLLM.node, [
@@ -2204,6 +2205,44 @@ describe("SessionRunnerLLM", () => {
22042205
expect(yield* s.inbox).toEqual([])
22052206
})
22062207

2208+
scenario("waits for plugin activation before selecting the agent for the next Step", function* (s) {
2209+
const agents = yield* Agent.Service
2210+
yield* agents.transform((editor) =>
2211+
editor.update(Agent.ID.make("reviewer"), (agent) => {
2212+
agent.mode = "primary"
2213+
}),
2214+
)
2215+
yield* s.db
2216+
.update(SessionTable)
2217+
.set({ agent: "reviewer" })
2218+
.where(eq(SessionTable.id, sessionID))
2219+
.run()
2220+
.pipe(Effect.orDie)
2221+
yield* s.admit("Echo then finish")
2222+
yield* s.llm.push(
2223+
TestLLM.tool("call-reload", "echo", { text: "reload" }),
2224+
TestLLM.text("Done", "text-after-reload"),
2225+
)
2226+
const tools = yield* s.blockTools()
2227+
const run = yield* s.resume.pipe(Effect.forkChild)
2228+
yield* tools.started
2229+
2230+
const parked = yield* Deferred.make<void>()
2231+
const reloaded = yield* Deferred.make<void>()
2232+
s.activationHook = Deferred.succeed(parked, undefined).pipe(Effect.andThen(Deferred.await(reloaded)))
2233+
const closed = yield* agents.transform((editor) => editor.remove(Agent.ID.make("reviewer")))
2234+
yield* tools.release
2235+
yield* Deferred.await(parked).pipe(Effect.raceFirst(Fiber.join(run)))
2236+
2237+
expect(s.requests).toHaveLength(1)
2238+
yield* closed.dispose
2239+
yield* Deferred.succeed(reloaded, undefined)
2240+
yield* Fiber.join(run)
2241+
2242+
expect(s.requests).toHaveLength(2)
2243+
expect(yield* s.inbox).toEqual([])
2244+
})
2245+
22072246
scenario("rechecks compaction admitted during boundary context preparation", function* (s) {
22082247
yield* s.runPrompt("Earlier work")
22092248
yield* s.admit("STEER_A")

0 commit comments

Comments
 (0)