mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-19 00:03:13 +03:00
fix(core): wait for plugin activation before each runner step (#51133)
Co-authored-by: Daniel Smolsky <dannysmo@gmail.com>
This commit is contained in:
committed by
GitHub
Unverified
parent
7d3dd861cc
commit
b64cc80db3
@@ -114,6 +114,7 @@ const layer = Layer.effect(
|
||||
if (pending?.type === "compaction") {
|
||||
const compacted = yield* restore(
|
||||
Effect.gen(function* () {
|
||||
yield* plugins.awaitActivation
|
||||
const selected = yield* context.select(sessionID)
|
||||
const model = yield* context.resolveModel(selected.session)
|
||||
// Preview updates without admitting them after the already-delivered compaction marker.
|
||||
@@ -193,6 +194,8 @@ const layer = Layer.effect(
|
||||
})
|
||||
|
||||
const prepareContext = Effect.fn("SessionRunner.prepareContext")(function* (sessionID: SessionSchema.ID) {
|
||||
// Plugins can reload mid-turn; each step and retry must read the settled agents, models and skills.
|
||||
yield* plugins.awaitActivation
|
||||
const selected = yield* context.select(sessionID)
|
||||
// A blocked initial instruction baseline must leave admitted input pending.
|
||||
yield* InstructionState.prepare(db, bus, selected.instructions, sessionID)
|
||||
@@ -246,7 +249,11 @@ const layer = Layer.effect(
|
||||
assistantMessageID,
|
||||
agent: loaded.agent.id,
|
||||
model: loaded.model,
|
||||
prepared,
|
||||
prepared: {
|
||||
...prepared,
|
||||
// A tool call can arrive during a reload; its permission check reads the session's agent.
|
||||
executeTool: (call) => plugins.awaitActivation.pipe(Effect.andThen(prepared.executeTool(call))),
|
||||
},
|
||||
retry: (cause, error, proposed) =>
|
||||
retry.decide({
|
||||
cause,
|
||||
|
||||
@@ -215,6 +215,7 @@ const makeRunnerState = (compaction?: SessionRunnerModel.Resolved["compaction"])
|
||||
systemRemoved: false,
|
||||
systemUnavailable: false,
|
||||
systemLoadHook: Effect.void,
|
||||
activationHook: Effect.void,
|
||||
skillBaselines: new Map<Agent.ID, string>(),
|
||||
authorizations: new Array<Tool.Context>(),
|
||||
executions: new Array<string>(),
|
||||
@@ -422,7 +423,7 @@ const layer = Layer.unwrap(
|
||||
Permission.node.replace(permission),
|
||||
Config.node.replace(config),
|
||||
PluginSupervisor.node.replace(Layer.empty),
|
||||
Plugin.node.replace(Layer.mock(Plugin.Service, { awaitActivation: Effect.void })),
|
||||
Plugin.node.replace(Layer.mock(Plugin.Service, { awaitActivation: Effect.suspend(() => state.activationHook) })),
|
||||
SessionModelTransport.node.replace(modelTransport),
|
||||
]
|
||||
const runnerLayer = AppNodeBuilder.build(SessionRunnerLLM.node, [
|
||||
@@ -2664,6 +2665,26 @@ describe("SessionRunnerLLM", () => {
|
||||
}
|
||||
}
|
||||
|
||||
scenario("waits for plugin activation before each step and tool call", function* (s) {
|
||||
const waits: Array<[number, number]> = []
|
||||
s.activationHook = Effect.sync(() => {
|
||||
waits.push([s.requests.length, s.executions.length])
|
||||
})
|
||||
yield* s.llm.push(
|
||||
TestLLM.tool("call-activation", "echo", { text: "echo" }),
|
||||
TestLLM.text("Done", "text-after-activation"),
|
||||
)
|
||||
yield* s.runPrompt("Question")
|
||||
|
||||
// Model requests and tool executions seen at each wait: drain entry, step 1, the tool call, step 2.
|
||||
expect(waits).toEqual([
|
||||
[0, 0],
|
||||
[0, 0],
|
||||
[1, 0],
|
||||
[1, 1],
|
||||
])
|
||||
})
|
||||
|
||||
scenario("restarts compaction drafts after transient failures and unsuccessful finishes", function* (s) {
|
||||
yield* s.llm.push(TestLLM.text("Earlier answer", "text-manual-failure-history"))
|
||||
yield* s.runPrompt("Earlier question")
|
||||
|
||||
Reference in New Issue
Block a user