diff --git a/packages/app-bundle/manifest.json b/packages/app-bundle/manifest.json index f61f9eff2..3bb012500 100644 --- a/packages/app-bundle/manifest.json +++ b/packages/app-bundle/manifest.json @@ -495,7 +495,7 @@ "packages/opencode/test/session/message-v2.test.ts": "90fbd916cea08ddb1de066dccf2677490b547afc5805aa36e55683b28fbb079f", "packages/opencode/test/session/mutation.test.ts": "ccb82b6858ac097d2af09a94497d05f6a0ff843b928a69e763fdb510905a10cd", "packages/opencode/test/session/processor-effect.test.ts": "51ebe1cb9b7b0e1d249472367491a1306b5add24ca8b04d5dc15b2b2fa1f1b56", - "packages/opencode/test/session/prompt.test.ts": "298c4d59c276bd3be14a9fb66dcd38f243ae8e9278be3bed0a4f1aac37d7e442", + "packages/opencode/test/session/prompt.test.ts": "6ce0cdde7b2391c87399d99282444a37f0a17d766c7fa833c650dff1a24d0a54", "packages/opencode/test/session/prose-guard.test.ts": "7239a758cbf27df4c3879fa9ee0374964559c1461773c2f5a85196f64632e6c4", "packages/opencode/test/session/receipt-privacy.test.ts": "6c8777edc280a061fec1a4d16e2504aec18bdf9cd6dd2cedc7a09ef8fc6c2ca0", "packages/opencode/test/session/retry.test.ts": "8136de9fed8d493c9703098b5f701674681ecf8a3f823268c039b819753d00e2", @@ -1104,7 +1104,7 @@ "packages/ui/src/v2/components/text-shimmer-v2.tsx" ], "exceptions": [], - "extracted_at": "2026-11-08T15:21:50.674Z", + "extracted_at": "2026-11-23T22:05:55.774Z", "per_package": { "packages/app": { "A": 314, diff --git a/packages/app-bundle/overlay/packages/opencode/test/session/prompt.test.ts b/packages/app-bundle/overlay/packages/opencode/test/session/prompt.test.ts index 8f1a4e1a7..e6d0c092f 100644 --- a/packages/app-bundle/overlay/packages/opencode/test/session/prompt.test.ts +++ b/packages/app-bundle/overlay/packages/opencode/test/session/prompt.test.ts @@ -665,6 +665,175 @@ it.instance("loop stops provider overflow instead of auto-compacting when disabl }), ) +// #2129 regression guards: auto-compaction must hand the turn back to the +// model, which answers the pending request in the same loop. The turn must not +// end on the compaction summary. The persisted records of both incidents cited +// in #2129 show the engine already does this (the "resent" message was the +// overflow replay below, not the user); these lock the behavior in. +const textOf = (parts: SessionV1.Part[]) => + parts + .filter((part): part is SessionV1.TextPart => part.type === "text") + .map((part) => part.text) + .join("") + +it.instance("loop answers the replayed request after auto-compacting a provider overflow (#2129)", () => + Effect.gen(function* () { + const { llm } = yield* useServerConfig(providerCfg) + const prompt = yield* SessionPrompt.Service + const sessions = yield* Session.Service + const chat = yield* sessions.create({ title: "Pinned" }) + + // An earlier, answered turn, so the overflow path has context to summarize + // and a request to replay. + yield* prompt.prompt({ + sessionID: chat.id, + agent: "build", + noReply: true, + parts: [{ type: "text", text: "earlier question" }], + }) + yield* llm.text("earlier answer") + yield* prompt.loop({ sessionID: chat.id }) + + yield* prompt.prompt({ + sessionID: chat.id, + agent: "build", + noReply: true, + parts: [{ type: "text", text: "present H1-H3" }], + }) + yield* llm.error(413, { error: { message: "request entity too large" } }) + yield* llm.text("summary of the session") + yield* llm.text("here are H1-H3") + + const result = yield* prompt.loop({ sessionID: chat.id }) + + // earlier turn, overflowed request, compaction summary, replayed request + expect(yield* llm.calls).toBe(4) + expect(result.info.role).toBe("assistant") + if (result.info.role === "assistant") { + expect(result.info.summary).toBeFalsy() + expect(result.info.finish).toBe("stop") + } + expect(textOf(result.parts)).toBe("here are H1-H3") + const hits = yield* llm.hits + expect(JSON.stringify(hits.at(-1)?.body)).toContain("present H1-H3") + expect(JSON.stringify(hits.at(-1)?.body)).toContain("summary of the session") + }), +) + +it.instance("loop continues the turn after auto-compacting at the context limit mid-task (#2129)", () => + Effect.gen(function* () { + const { llm } = yield* useServerConfig(providerCfg) + const prompt = yield* SessionPrompt.Service + const sessions = yield* Session.Service + const chat = yield* sessions.create({ + title: "Pinned", + permission: [{ permission: "*", pattern: "*", action: "allow" }], + }) + + yield* prompt.prompt({ + sessionID: chat.id, + agent: "build", + noReply: true, + parts: [{ type: "text", text: "present H1-H3" }], + }) + // A tool step whose usage crosses the usable context (90k of the test + // model's 100k) triggers auto-compaction in the middle of the turn. + yield* llm.push(reply().tool("first", { value: "first" }).usage({ input: 95_000, output: 10 })) + yield* llm.text("summary of the session") + yield* llm.text("here are H1-H3") + + const result = yield* prompt.loop({ sessionID: chat.id }) + const messages = yield* sessions.messages({ sessionID: chat.id }) + + // tool step, compaction summary, continued turn + expect(yield* llm.calls).toBe(3) + expect(messages.filter((message) => message.parts.some((part) => part.type === "compaction"))).toHaveLength(1) + expect(result.info.role).toBe("assistant") + if (result.info.role === "assistant") { + expect(result.info.summary).toBeFalsy() + expect(result.info.finish).toBe("stop") + } + expect(textOf(result.parts)).toBe("here are H1-H3") + // On this path (no replay) the request reaches the continued turn through + // the summary, followed by the engine's auto-continue instruction. + const last = JSON.stringify((yield* llm.hits).at(-1)?.body) + expect(last).toContain("summary of the session") + expect(last).toContain("Continue if you have next steps") + }), +) + +// #2136 regression guard: a long polling tool call (sleep, then read logs) +// returns with finish "tool-calls", and the loop must hand the result back to +// the model. A user message sent while the poll is still running is picked up +// by the same loop. This mirrors the incident's persisted record, where the +// loop resumed as soon as the 420 s sleep returned. +unix( + "loop continues after a polling bash call and picks up a message sent mid-poll (#2136)", + () => + Effect.gen(function* () { + const { dir, llm } = yield* useServerConfig(providerCfg) + const prompt = yield* SessionPrompt.Service + const sessions = yield* Session.Service + const chat = yield* sessions.create({ + title: "Pinned", + permission: [{ permission: "*", pattern: "*", action: "allow" }], + }) + + yield* prompt.prompt({ + sessionID: chat.id, + agent: "build", + noReply: true, + parts: [{ type: "text", text: "start the solves and poll them" }], + }) + yield* llm.tool("bash", { + command: "sleep 2; echo first-poll-ready", + timeout: 10_000, + workdir: path.resolve(dir), + }) + // A second poll with no user message during it: the loop must still hand + // its result back to the model rather than end the turn. + yield* llm.tool("bash", { + command: "sleep 1; echo second-poll-ready", + timeout: 10_000, + workdir: path.resolve(dir), + }) + yield* llm.text("next planned step") + + const run = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild) + yield* llm.wait(1) + yield* pollWithTimeout( + Effect.gen(function* () { + const msgs = yield* MessageV2.filterCompactedEffect(chat.id) + const running = msgs.some((msg) => + msg.parts.some((part) => part.type === "tool" && part.tool === "bash" && part.state.status === "running"), + ) + return running ? (true as const) : undefined + }), + "timed out waiting for the polling bash call to start", + ) + yield* prompt.prompt({ + sessionID: chat.id, + agent: "build", + noReply: true, + parts: [{ type: "text", text: "note sent mid-poll" }], + }) + + const result = yield* Fiber.join(run) + + expect(yield* llm.calls).toBe(3) + expect(result.info.role).toBe("assistant") + if (result.info.role === "assistant") expect(result.info.finish).toBe("stop") + expect(textOf(result.parts)).toBe("next planned step") + const hits = yield* llm.hits + const second = JSON.stringify(hits[1]?.body) + expect(second).toContain("first-poll-ready") + expect(second).toContain("note sent mid-poll") + expect(JSON.stringify(hits[2]?.body)).toContain("second-poll-ready") + }), + { git: true, config: cfg }, + 30_000, +) + noLLMServer.instance.skip( "prompt emits v2 prompted and synthetic events (v2 projector disabled)", () =>