Repository navigation
fix(server): surface ACP stderr when cursor-agent exits at session start #12625
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
juliusmarminge
merged 5 commits into
pingdotgg:main
from
cestercian:cursor/acp-stderr-cli-json-896c
Sep 19, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d0c1569
fix(server): surface ACP stderr when cursor-agent exits at session start
cestercian 69b3869
fix(server): bound async cli.json reads and redact sk-proj keys
cestercian 3137ec3
fix(server): drop the cli.json key detector and duplicate exit formatter
juliusmarminge c8d3b42
test(server): drop the cli.json fixture the trimmed detector no longe…
juliusmarminge 618e53b
chore(server): explain the node builtin suppression in AcpStderr
juliusmarminge 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
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
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,56 @@ | ||
| import { describe, expect, it } from "vite-plus/test"; | ||
|
|
||
| import { | ||
| ACP_STDERR_TAIL_MAX_CHARS, | ||
| appendAcpStderrTail, | ||
| sanitizeAcpStderrExcerpt, | ||
| } from "./AcpStderr.ts"; | ||
|
|
||
| describe("AcpStderr", () => { | ||
| it("keeps a bounded tail of stderr chunks", () => { | ||
| const prefix = "x".repeat(ACP_STDERR_TAIL_MAX_CHARS); | ||
| expect(appendAcpStderrTail(prefix, "abc")).toBe(`${prefix.slice(3)}abc`); | ||
| }); | ||
|
|
||
| it("redacts home paths, pairing URLs, and tokens from stderr excerpts", () => { | ||
| const excerpt = sanitizeAcpStderrExcerpt( | ||
| [ | ||
| "Invalid project config at /Users/ada/.cursor/cli.json", | ||
| "Authorization: Bearer secret-token-value", | ||
| "Visit http://localhost:5733/pair#token=ABCDEF for pairing", | ||
| "key=sk-abcdefghijklmnopqrstuv", | ||
| ].join("\n"), | ||
| { HOME: "/Users/ada" }, | ||
| ); | ||
|
|
||
| expect(excerpt).toContain("Invalid project config at ~/.cursor/cli.json"); | ||
| expect(excerpt).toContain("Bearer [redacted]"); | ||
| expect(excerpt).toContain("[pairing-url]"); | ||
| expect(excerpt).toContain("[redacted]"); | ||
| expect(excerpt).not.toContain("secret-token-value"); | ||
| expect(excerpt).not.toContain("ABCDEF"); | ||
| expect(excerpt).not.toContain("sk-abcdefghijklmnopqrstuv"); | ||
| }); | ||
|
|
||
| it("redacts hyphenated OpenAI project keys and header credentials", () => { | ||
| const excerpt = sanitizeAcpStderrExcerpt( | ||
| [ | ||
| "openai=sk-proj-abcdefghijklmnopqrstuvwxyz012345", | ||
| "svc=sk-svcacct-abcdefghijklmnopqrstuvwxyz012345", | ||
| "anthropic=sk-ant-api03-abcdefghijklmnopqrstuvwxyz012345", | ||
| "Authorization: Basic dXNlcjpwYXNz", | ||
| "x-api-key: ant-api-key-value", | ||
| ].join("\n"), | ||
| ); | ||
|
|
||
| expect(excerpt).toContain("[redacted]"); | ||
| expect(excerpt).toContain("Authorization: Basic [redacted]"); | ||
| expect(excerpt).toContain("x-api-key: [redacted]"); | ||
| expect(excerpt).not.toContain("sk-proj-"); | ||
| expect(excerpt).not.toContain("sk-svcacct-"); | ||
| expect(excerpt).not.toContain("sk-ant-api03-"); | ||
| expect(excerpt).not.toContain("abcdefghijklmnopqrstuvwxyz012345"); | ||
| expect(excerpt).not.toContain("dXNlcjpwYXNz"); | ||
| expect(excerpt).not.toContain("ant-api-key-value"); | ||
| }); | ||
| }); |
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,38 @@ | ||
| // @effect-diagnostics nodeBuiltinImport:off -- The excerpt sanitizer masks the home directory, which only the Node os module can resolve. | ||
| import * as NodeOS from "node:os"; | ||
|
|
||
| /** Last few KiB of ACP child stderr kept for startup / exit diagnostics. */ | ||
| export const ACP_STDERR_TAIL_MAX_CHARS = 4_096; | ||
|
|
||
| const PAIRING_URL_PATTERN = /https?:\/\/[^\s]*\/pair#[^\s]*/gi; | ||
| const BEARER_TOKEN_PATTERN = /\bBearer\s+[A-Za-z0-9._\-+=/]+/gi; | ||
| const BASIC_AUTH_PATTERN = /\bAuthorization:\s*Basic\s+\S+/gi; | ||
| const API_KEY_HEADER_PATTERN = /\bx-api-key:\s*\S+/gi; | ||
| const SECRET_TOKEN_PATTERN = | ||
| /\b(?:sk-[A-Za-z0-9][A-Za-z0-9-]{7,}|ghp_[A-Za-z0-9]+|xox[a-zA-Z]-[A-Za-z0-9-]+)\b/g; | ||
|
|
||
| export function appendAcpStderrTail(current: string, chunk: string): string { | ||
| const next = `${current}${chunk}`; | ||
| return next.length <= ACP_STDERR_TAIL_MAX_CHARS ? next : next.slice(-ACP_STDERR_TAIL_MAX_CHARS); | ||
| } | ||
|
|
||
| /** Bounded, redacted excerpt safe to put on user-facing adapter errors. */ | ||
| export function sanitizeAcpStderrExcerpt( | ||
| text: string, | ||
| environment: NodeJS.ProcessEnv = process.env, | ||
| ): string { | ||
| let result = text.replaceAll("\0", ""); | ||
| const homes = [environment.HOME, environment.USERPROFILE, NodeOS.homedir()].filter( | ||
| (value): value is string => typeof value === "string" && value.length > 1, | ||
| ); | ||
| for (const home of new Set(homes)) { | ||
| result = result.split(home).join("~"); | ||
| } | ||
| result = result | ||
| .replace(PAIRING_URL_PATTERN, "[pairing-url]") | ||
| .replace(BEARER_TOKEN_PATTERN, "Bearer [redacted]") | ||
| .replace(BASIC_AUTH_PATTERN, "Authorization: Basic [redacted]") | ||
| .replace(API_KEY_HEADER_PATTERN, "x-api-key: [redacted]") | ||
| .replace(SECRET_TOKEN_PATTERN, "[redacted]"); | ||
|
juliusmarminge marked this conversation as resolved.
coderabbitai[bot] marked this conversation as resolved.
|
||
| return result.trim(); | ||
| } | ||
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
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.