Skip to content

fix(tracing): tolerate unescaped Windows paths in hook payloads - #198

Merged
Stephen Belanger (Qard) merged 1 commit into
mainfrom
fix/cursor-windows-unescaped-transcript-path
Oct 20, 2026
Merged

Stephen Belanger (Qard) merged 1 commit into
mainfrom
fix/cursor-windows-unescaped-transcript-path

Conversation

@AbhiPrasad

@AbhiPrasad Abhijeet Prasad (AbhiPrasad) commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

Fixes #197

I know this is a bug with cursor itself, but we need to workaround this for a customer. I've reached out to the cursor team to let them know.

Problem

On Windows, Cursor writes transcript_path into the hook payload with raw backslashes ("c:\Users\..."). That isn't valid JSON, so every bt trace hook --source cursor call failed with invalid escape. The installed hook throws away output and errors, so the failure was silent and no Cursor trace was ever recorded.

The root cause is a serialization bug in Cursor. This PR works around it in bt trace hook.

Fix

parse_hook_payload in bt-daemon/src/hook.rs:

  1. Strict serde_json parse first. Valid payloads take this path unchanged, so nothing changes once Cursor fixes the bug.
  2. On failure, re-read backslashes that don't start a valid JSON escape (\U, \., \a, \u without 4 hex digits) as literal backslashes, then parse again. Properly escaped fields such as text with \n or \" are untouched.
  3. In the --transcript-path-field field only, turn control characters picked up from escape-like path segments (\b91a…, \new, \tmp) back into \b, \f, \n, \r, \t.
  4. If the repaired payload still doesn't parse, return the original error.

Known limitations

  • A UNC path (\\server\share) in a raw path would collapse to \server\share, because \\ is a valid escape. Cursor transcript paths live under the user's home directory, so this shouldn't happen in practice.
  • Only the transcript path field gets its accidental escapes restored. Other path fields would still parse but could keep stray control characters. Only transcript_path has been reported.
  • Not addressed here: the installed PowerShell hook still discards errors, and bt trace doctor cursor doesn't check the capture path. Both would be worth a follow-up.

Testing

  • New unit tests use the issue's payload shape, with escape-like path segments, and check that escaped text survives. Another test checks that valid JSON is unchanged and that unfixable payloads return the original error.
  • Piped the issue's payload through the built binary. It now gets past parsing.
  • cargo test --all-features, cargo clippy --all-targets -D warnings, and cargo fmt --check all pass.
  • Not tested end to end on Windows with a real Cursor install.

🤖 Generated with Claude Code

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-19T23:35:21.256481Z c239027 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Cursor on Windows writes `transcript_path` with raw backslashes
(`c:\Users\...`), which is invalid JSON, so every Cursor hook failed to
parse and the installed hook silently swallowed the error.

When strict parsing fails, treat invalid escapes as literal backslashes
and restore accidental escapes (`\b`, `\f`, `\n`, `\r`, `\t`) in the
transcript path field. Valid JSON still takes the strict path unchanged.

Fixes #197

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AbhiPrasad
Abhijeet Prasad (AbhiPrasad) force-pushed the fix/cursor-windows-unescaped-transcript-path branch from 0e9f6f8 to c239027 Compare October 19, 2026 23:33

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c23902741d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "Codex (@codex) address that feedback".

Comment thread bt-daemon/src/hook.rs
@Qard

Copy link
Copy Markdown
Collaborator

Fails in Windows CI.

@AbhiPrasad

Copy link
Copy Markdown
Member Author

re-ran CI - it was a flake

@Qard
Stephen Belanger (Qard) merged commit 54ff15c into main Oct 20, 2026
37 of 39 checks passed
@Qard
Stephen Belanger (Qard) deleted the fix/cursor-windows-unescaped-transcript-path branch October 20, 2026 16:43
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.

Cursor tracing (bt trace hook --source cursor) silently fails to parse hook payload on Windows due to unescaped backslashes in transcript_path

2 participants