Skip to content

feat: keep a redacted excerpt of failed tool output (#79) - #158

Merged
NehharShah merged 1 commit into
mainfrom
feat/error-excerpts
Nov 21, 2026
Merged

NehharShah merged 1 commit into
mainfrom
feat/error-excerpts

Conversation

@NehharShah

Copy link
Copy Markdown
Collaborator

What changed and why

Adapters record that a tool call failed but not why. Now, wherever an adapter grades a tool call, a failed call keeps the first 200 characters of its output on the event (errorExcerpt), redacted — so Reflex can learn which fixes go with which errors.

The guard is double: the output is redacted first (redactTruncated, which redacts a 1,224-character window before cutting, so a secret crossing the limit is seen whole), and the excerpt must then pass findLeaks() — the same leak scan generated text passes. An excerpt that still looks like a leak is dropped entirely, not just trimmed. Successful calls keep nothing.

Per adapter:

  • Claude Code: the tool_result content (string or text blocks) of a failed result; sidechain results get the same treatment.
  • Codex: the call output on function_call_output / local_shell_call_output / custom_tool_call_output when exitFailed() says so.
  • Cursor: the app database query now takes the first 400 characters of the output only for failed calls (status error or a non-zero exit code, gated in SQL with a CASE), and the adapter redacts down to 200. The consent question says so plainly now: "for failed calls the first 200 characters of the error output, redacted — never messages, and never the output of a call that succeeded." This changes the feat: read tool outcomes from Cursor's app database (#71) #142 promise ("never tool output") — the issue listed Cursor, the extraction is gated to failures and redacted before storage, and docs/security.md states the new surface exactly.

markResult takes the optional excerpt; a shared errorExcerpt() lives in common.ts with textContent() (moved from Codex's local helper) so all three adapters share one implementation.

Docs

docs/security.md (the Cursor app database row: what is selected for failed calls, the redaction and the leak gate), docs/architecture.md (a "Failed tool calls keep an excerpt" paragraph: per-adapter sources, the double guard, and that no skill/memory/handbook is generated from it).

Testing

pnpm lint, pnpm typecheck, pnpm build, pnpm test: 757 passed, 18 skipped.

  • common.test.ts: the excerpt is ≤200, redacted (an npm token in output is gone), and dropped when a leak survives (git@github.com: Permission denied — git@ is excluded from the email redaction by design, so the email-shaped leak fails the gate); textContent reads strings and text blocks.
  • claude.test.ts: a failed result with a token in its output keeps a redacted ≤200 excerpt; a git@… failure stays marked isError but keeps no excerpt; a successful result keeps neither.
  • codex.test.ts: a failed call's output yields the same.
  • cursor-outcomes.test.ts: a failed call's output reaches the reader (400 chars, pre-redaction) and lands redacted on the event; a succeeded call's output never appears; the failed file event carries one too. The old "never output text" test now asserts the new contract: output only for failed calls.

Where the adapters grade a tool call, a failed one now keeps the first 200
characters of its output on the event: redacted first, then gated by the same
leak scan generated text passes - an excerpt that still looks like a leak is
dropped entirely, and successful calls keep nothing. Claude Code reads it from
the tool_result content, Codex from the call output, Cursor from the app
database, where the query takes the first 400 characters only for failed calls
and the consent says so.
@NehharShah
NehharShah merged commit 1a1363a into main Nov 21, 2026
2 checks passed
@NehharShah
NehharShah deleted the feat/error-excerpts branch November 21, 2026 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant