-
Notifications
You must be signed in to change notification settings - Fork 75
fix(cursor): truncate toolResult bodies across compact reload #1044
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
code-yeongyu
merged 17 commits into
code-yeongyu:main
from
leeseunguk:fix/cursor-toolresult-truncate
Aug 29, 2026
Merged
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
a16d01e
fix(cursor): truncate toolResult bodies across compact reload
leeseunguk e7d7068
fix(cursor): bound tool results across compaction reloads
code-yeongyu d219d4d
fix(cursor): truncate tool results in request views
code-yeongyu 92ace3a
fix(cursor): bound serialized tool result history
code-yeongyu c837ee3
fix(cursor): bound escaped tool result payloads
code-yeongyu f2d1408
fix(cursor): coalesce emptied tool result parts
code-yeongyu 4dd0292
fix(cursor): budget tool result history envelopes
code-yeongyu 641fe3b
fix(cursor): measure tool result history on the wire
code-yeongyu 07db910
fix(cursor): bound converted tool result admission
code-yeongyu 1728316
fix(cursor): measure truncation with transport conversion
code-yeongyu b4f8cdd
Merge origin/main into pr-1044-work
code-yeongyu 949d663
fix(cursor): restore mainline tui files clobbered by earlier merge re…
code-yeongyu 216e74a
fix(ci): expose cursor history measurement from ai root
code-yeongyu 5b56b00
Merge origin/main into fix/cursor-toolresult-truncate
code-yeongyu c428d99
fix(ci): expose cursor agent through subpath
code-yeongyu 0c01ce7
fix(ci): isolate cursor history measurement
code-yeongyu e4fb83e
Merge remote-tracking branch 'origin/main' into fix/cursor-toolresult…
code-yeongyu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
packages/coding-agent/test/suite/regressions/1043-cursor-toolresult-truncate.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import type { AgentMessage } from "@earendil-works/pi-agent-core"; | ||
| import { | ||
| CURSOR_TOOL_RESULT_MAX_CHARS, | ||
| truncateToolResultBodies, | ||
| } from "../../../src/core/agent-session.ts"; | ||
| import { readFileSync } from "node:fs"; | ||
| import { join } from "node:path"; | ||
|
|
||
| function textMessage(role: AgentMessage["role"], text: string): AgentMessage { | ||
| return { role, content: [{ type: "text", text }] } as AgentMessage; | ||
| } | ||
|
|
||
| describe("1043 cursor toolResult truncate", () => { | ||
| it("caps long toolResult text and leaves other roles", () => { | ||
| const messages = [ | ||
| textMessage("user", "진행해"), | ||
| textMessage("assistant", "ok".repeat(5000)), | ||
| textMessage("toolResult", "x".repeat(40_000)), | ||
| ]; | ||
| const { messages: next, changed } = truncateToolResultBodies(messages, 2000); | ||
| expect(changed).toBe(true); | ||
| expect(next?.[0].content).toEqual([{ type: "text", text: "진행해" }]); | ||
| expect((next?.[1].content[0] as { text: string }).text.length).toBe(10_000); | ||
| const toolText = (next?.[2].content[0] as { text: string }).text; | ||
| expect(toolText.startsWith("x".repeat(2000))).toBe(true); | ||
| expect(toolText.length).toBeLessThanOrEqual(2000 + 32); | ||
| expect(toolText.length).not.toBe(40_000); | ||
| }); | ||
|
|
||
| it("is a no-op when every toolResult is already short", () => { | ||
| const messages = [textMessage("toolResult", "ok")]; | ||
| const { changed } = truncateToolResultBodies(messages, CURSOR_TOOL_RESULT_MAX_CHARS); | ||
| expect(changed).toBe(false); | ||
| }); | ||
|
|
||
| it("Cursor admission truncates before the compact skip return", () => { | ||
|
code-yeongyu marked this conversation as resolved.
Outdated
|
||
| const src = readFileSync(join(import.meta.dirname, "../../../src/core/agent-session.ts"), "utf8"); | ||
| const start = src.indexOf("const compactBeforeNextAdmission = async"); | ||
| expect(start).toBeGreaterThanOrEqual(0); | ||
| const slice = src.slice(start, start + 1800); | ||
| const truncateAt = slice.indexOf("_truncateCursorToolResultBodies"); | ||
| const skipAt = slice.indexOf("return truncated"); | ||
| expect(truncateAt).toBeGreaterThanOrEqual(0); | ||
| expect(skipAt).toBeGreaterThan(truncateAt); | ||
| }); | ||
|
|
||
| it("re-truncates after compact reloads sessionContext.messages", () => { | ||
| const src = readFileSync(join(import.meta.dirname, "../../../src/core/agent-session.ts"), "utf8"); | ||
| const assign = "this.agent.state.messages = [...sessionContext.messages, ...preservedPendingMessages];"; | ||
| const i = src.indexOf(assign); | ||
| expect(i).toBeGreaterThanOrEqual(0); | ||
| expect(src.slice(i, i + 400)).toContain("_reapplyCursorToolTruncateAfterReload"); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.