fix(stream): omit prior reasoning from request history
This commit is contained in:
@@ -187,6 +187,51 @@ try {
|
||||
assert.equal(reasoning.code, 0, reasoning.stderr)
|
||||
assert.match(reasoning.stdout, new RegExp(marker))
|
||||
|
||||
console.log("[live-e2e] live multi-turn reasoning history")
|
||||
const multiTurn = await runRpc(extensionPath, async ({ send, waitFor, events, getStderr }) => {
|
||||
const countThinkingDeltas = (startIndex) =>
|
||||
events
|
||||
.slice(startIndex)
|
||||
.filter(
|
||||
(event) =>
|
||||
event.type === "message_update" &&
|
||||
event.assistantMessageEvent?.type === "thinking_delta" &&
|
||||
typeof event.assistantMessageEvent.delta === "string" &&
|
||||
event.assistantMessageEvent.delta.length > 0,
|
||||
).length
|
||||
|
||||
const firstStart = events.length
|
||||
send({
|
||||
id: "reasoning-turn-1",
|
||||
type: "prompt",
|
||||
message:
|
||||
"Reason step by step before answering. Calculate 37 * 41, then reply with only the number.",
|
||||
})
|
||||
await waitFor(
|
||||
(event) => event.type === "response" && event.id === "reasoning-turn-1" && event.success,
|
||||
)
|
||||
await waitFor((event) => event.type === "agent_settled")
|
||||
const firstThinkingDeltas = countThinkingDeltas(firstStart)
|
||||
|
||||
const secondStart = events.length
|
||||
send({
|
||||
id: "reasoning-turn-2",
|
||||
type: "prompt",
|
||||
message:
|
||||
"Now reason step by step again. Add 19 to your previous numeric result, then reply with only the number.",
|
||||
})
|
||||
await waitFor(
|
||||
(event) => event.type === "response" && event.id === "reasoning-turn-2" && event.success,
|
||||
)
|
||||
await waitFor((event) => event.type === "agent_settled" && events.indexOf(event) >= secondStart)
|
||||
const secondThinkingDeltas = countThinkingDeltas(secondStart)
|
||||
|
||||
return { firstThinkingDeltas, secondThinkingDeltas, stderr: getStderr() }
|
||||
})
|
||||
assert.ok(multiTurn.firstThinkingDeltas > 0, "first turn should stream reasoning")
|
||||
assert.ok(multiTurn.secondThinkingDeltas > 0, "follow-up turn should stream fresh reasoning")
|
||||
assert.doesNotMatch(multiTurn.stderr, /Bearer\s+\S+/i)
|
||||
|
||||
console.log("[live-e2e] live runtime refresh/status commands")
|
||||
const runtime = await runRpc(extensionPath, async ({ send, waitFor, getStderr }) => {
|
||||
send({ id: "commands", type: "get_commands" })
|
||||
|
||||
@@ -499,12 +499,49 @@ describe("messagesToCC()", () => {
|
||||
|
||||
assert.equal(objectAt(result, ["0", "role"]), "user")
|
||||
assert.equal(objectAt(result, ["1", "role"]), "assistant")
|
||||
assert.equal(objectAt(result, ["1", "content", "0", "type"]), "reasoning")
|
||||
assert.equal(objectAt(result, ["1", "content", "2", "type"]), "tool-call")
|
||||
assert.equal(objectAt(result, ["1", "content", "0", "type"]), "text")
|
||||
assert.equal(objectAt(result, ["1", "content", "1", "type"]), "tool-call")
|
||||
assert.equal(objectAt(result, ["1", "content", "2"]), undefined)
|
||||
assert.equal(objectAt(result, ["2", "role"]), "tool")
|
||||
assert.equal(objectAt(result, ["2", "content", "0", "output", "value"]), "hello\nworld")
|
||||
})
|
||||
|
||||
it("drops previous assistant reasoning while preserving text and tool calls", () => {
|
||||
const result = messagesToCC([
|
||||
{ role: "user", content: "first question" },
|
||||
{
|
||||
role: "assistant",
|
||||
content: [
|
||||
{ type: "thinking", thinking: "private reasoning from turn one" },
|
||||
{ type: "text", text: "first answer" },
|
||||
],
|
||||
},
|
||||
{ role: "user", content: "follow-up question" },
|
||||
])
|
||||
|
||||
assert.deepEqual(result, [
|
||||
{ role: "user", content: "first question" },
|
||||
{ role: "assistant", content: [{ type: "text", text: "first answer" }] },
|
||||
{ role: "user", content: "follow-up question" },
|
||||
])
|
||||
})
|
||||
|
||||
it("omits assistant turns that contain only previous reasoning", () => {
|
||||
const result = messagesToCC([
|
||||
{ role: "user", content: "first question" },
|
||||
{
|
||||
role: "assistant",
|
||||
content: [{ type: "thinking", thinking: "private reasoning" }],
|
||||
},
|
||||
{ role: "user", content: "follow-up question" },
|
||||
])
|
||||
|
||||
assert.deepEqual(result, [
|
||||
{ role: "user", content: "first question" },
|
||||
{ role: "user", content: "follow-up question" },
|
||||
])
|
||||
})
|
||||
|
||||
it("drops orphaned tool calls that have no matching tool result", () => {
|
||||
const result = messagesToCC([
|
||||
{ role: "user", content: "edit a file" },
|
||||
|
||||
Reference in New Issue
Block a user