Skip to content

fix: improve forwarder lifecycle recovery and Cursor transcript sync - #286

Open
philau2512 wants to merge 48 commits into
leookun:mainfrom
philau2512:main
Open

fix: improve forwarder lifecycle recovery and Cursor transcript sync#286
philau2512 wants to merge 48 commits into
leookun:mainfrom
philau2512:main

Conversation

@philau2512

Copy link
Copy Markdown
Contributor

Summary

This PR brings the fork's forwarder lifecycle fixes, Cursor transcript synchronization improvements, and prompt/tool compatibility updates back to leookun/cursor-byok.

The changes are cumulative because this branch contains several related fork improvements. The main goal is to make Agent turns, tool execution, shell sessions, cancellation, and transcript projection more reliable under streaming, reconnect, and interrupted-transport scenarios.

Why

The Cursor client can receive events from multiple sources during an Agent turn:

  • live provider/tool stream events;
  • shell lifecycle events;
  • persisted conversation history;
  • transcript projection and replay.

Without strict lifecycle handling, this can result in:

  • duplicated reasoning or progress rows;
  • transcript content being overwritten by an older snapshot;
  • hidden PatchEdit or Write operations remaining incomplete;
  • terminal events being emitted more than once;
  • shell output or tool results being lost after cancellation or stream closure;
  • MCP tool calls failing when Cursor uses a server name instead of its canonical identifier.

This PR addresses these cases while preserving the existing upstream protocol and tool contracts.

Main changes

Forwarder lifecycle and transcript consistency

  • Defer transcript synchronization while an Agent turn is still active.
  • Project the final transcript only after a terminal state is reached.
  • Preserve terminal markers such as turn_ended.
  • Improve handling of continuation runs, checkpoint replay, and history backfill.
  • Prevent duplicated reasoning/progress content across multiple tool calls.
  • Preserve tool output and edit content during replay and compaction.
  • Ignore late deltas and duplicate invocations after a tool has completed.

Tool, edit, and shell recovery

  • Complete pending hidden PatchEdit and Write operations when a turn is canceled.
  • Recover tool results when the transport closes before the terminal result.
  • Improve shell streaming and shell lifecycle recovery.
  • Prevent duplicate terminal events and invalid subscriptions after stream termination.
  • Improve terminal tool handling and interrupted output recovery.

MCP compatibility

  • Normalize MCP lookups using canonical server identifiers and tool names.
  • Resolve server-name aliases to the corresponding canonical server identifier.
  • Add regression coverage for direct invocation, persisted registries, and alias resolution.

Prompt and tool contract updates

  • Update shared prompt behavior and language-policy handling.
  • Synchronize prompt/tool definitions across Agent, Ask, Debug, Plan, and Multitask modes.
  • Keep tool invocation and response-language behavior consistent across modes.
  • Lock language response with rule:

alwaysApply: true
response_language: en
lock_response_language: true

Build, localization, and documentation

  • Update build scripts and packaging configuration.
  • Refresh the generated localization catalog.
  • Update README and add the English CHANGELOG.md.

Review focus

The most important areas to review are:

  1. internal/backend/forwarder/

    • lifecycle transitions;
    • terminal event ordering;
    • transcript projection timing;
    • cancellation and transport-closure recovery.
  2. MCP tool normalization

    • canonical server identifier handling;
    • server-name alias resolution;
    • persisted registry compatibility.
  3. Prompt/tool contract changes

    • consistency across prompt modes;
    • compatibility with the existing Cursor client.

Validation

The following checks pass:

  • go build ./...
  • go test ./...
  • go test ./internal/backend/forwarder
  • yarn build
  • git diff --cached --check

The branch is currently 49 files changed, with approximately 3317 additions and 369 deletions compared with upstream/main.

Known limitation

go vet ./... still reports the existing lock-copy warning at:

internal/backend/agent/bridge/interaction/bridge.go:328

This warning is unrelated to the changes in this PR.

E2E validation with the installed Cursor client and a real provider has not yet been completed. The remaining risk is primarily around provider-specific streaming behavior and client-side transcript rendering.

philau2512 and others added 30 commits July 19, 2026 02:04
Honor explicit user language requests while retaining IDE defaults and stable prompt replay.
…erience

Updated prompt guidelines to prioritize specialized tools over terminal commands for file operations, clarified command examples to avoid assumptions about user environments, and emphasized the use of Read tools for metadata access in terminal files. Adjusted descriptions to ensure clarity and consistency across prompts.
Allow planning artifacts and workflow skills in Plan mode while using hybrid subagent escalation for complex investigations.
- Updated version number to 0.0.43.1 across all relevant files.
- Enhanced the build script to include error handling and output verification.
- Added a new function to defer transcript synchronization until the conversation turn ends.
…handling

- Updated build scripts for both batch and PowerShell to create Windows executables more efficiently.
- Introduced a new task for building Windows binaries without creating ZIP archives.
- Improved error handling and output verification during the build process.
…ce transcript handling

- Fixed an issue where reasoning/progress blocks were duplicated before multiple tools in a single agent run.
- Updated the handling of provider reasoning to ensure it is consumed only once per tool invocation.
- Added regression tests to verify that reasoning is rendered correctly in transcripts and only once per tool call.
- Implemented a fallback mechanism for reasoning content in tool results to maintain historical accuracy.
…erminal result handling after stream closure
…and update sync logic to skip active turns during backfill

- Removed the preserveCursorAppendedTurnEnded function to simplify transcript handling.
- Updated SyncAllCursorTranscriptsBestEffort to skip syncing transcripts for active turns.
- Added tests to ensure that active turns are not synced during startup backfill and that stale terminal states are correctly handled.
philau2512 and others added 18 commits August 4, 2026 17:29
…ng checkpoint mechanism adjustments and new environment variable for WebView sandbox. Verified successful tests.
Keep shell executions pending until the client reports Run, Skip, or another terminal state, and start foreground recovery only after execution begins.
Keep provider delivery responsive by buffering observability writes and trimming acknowledged stream backlog.
Keep canonical server and tool mappings available across long conversation turns and compaction-driven stream recreation.
Integrate checkpoint projection, imported history, shell streaming, terminal cancellation, provider adapters, localization, and MCP registry compatibility.
- rename CHANGELOG_LOCAL.md to CHANGELOG.md
- translate historical local changes and verification notes
- preserve dates, technical terms, commands, and test names
docs: rename local changelog and translate to English
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