Files
PaperClipAI/server
Josh CoxandReview 538de6bed6 fix(cursor-local): do not restart a cancelled run as a fresh session (#22204) (#22506)
<!-- Write all pull request text in Simplified Technical English
(ASD-STE100): short sentences, one instruction per sentence, simple
approved vocabulary, and the active voice. -->

## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - The Cursor adapter runs the Cursor CLI and resumes a saved session
when one exists
> - A cancelled run left the CLI process dead with a non-zero exit, and
the adapter read the full transcript for "unknown session" text
> - The transcript match fired on agent words, so the adapter started a
fresh session after the cancel
> - This pull request gates the fresh-session retry on a live run and
matches only Cursor's own error
> - The benefit is a cancelled run stays cancelled, and a transcript
phrase never restarts a run

## Linked Issues or Issue Description

Fixes #22204

## What Changed

- The Cursor adapter no longer retries a resumed run with a fresh
session when the run was cancelled or the process was killed. The retry
gate now requires no process signal and no aborted run signal.
- The unknown-session matcher no longer reads the full stdout
transcript. It now reads only the parsed Cursor error message from the
stream-json error or result event, plus stderr.
- `isCursorUnknownSessionError` now takes the parsed error message
instead of stdout. The name and the match patterns stay the same.
- The codex-local adapter already gates its unknown-session retry on no
process signal. This change applies the same rule to the Cursor adapter,
and it adds the run-signal gate.
- New tests in
`packages/adapters/cursor-local/src/server/execute-cancel-retry.test.ts`
cover the cancelled run, the signal-killed run, the transcript phrase,
and the genuine unknown-session retry.
- New matcher tests in
`packages/adapters/cursor-local/src/server/parse.test.ts` cover the
error text, stderr, and the empty case.
- The server matcher tests in `adapter-session-codecs.test.ts` and
`cursor-local-adapter.test.ts` use the new signature.

## Verification

- Negative control: the new execute tests fail 3 of 4 on the unfixed
code, because the adapter retries in each "does not retry" case. The
genuine retry case passes on the unfixed code. With the fix, all 4 tests
pass.
- Targeted vitest runs pass with the fix: cursor-local
`execute-cancel-retry.test.ts` and `parse.test.ts` (9 passed),
`execute.test.ts`, `execute.remote.test.ts`, and
`remote-command.test.ts` (13 passed), `test.test.ts` (2 passed), and
server `adapter-session-codecs.test.ts` and
`cursor-local-adapter.test.ts` (35 passed). Total: 59 passed, 0 failed.
- Package typecheck passes: `pnpm --filter
@paperclipai/adapter-cursor-local typecheck` (`tsc --noEmit`) exits 0.
It covers the new test file.
- The full server typecheck does not run in this sandbox. The tsc layer
was killed by the system for low memory (SIGKILL on the 1285-file
layer). CI is the arbiter for server typecheck.
- The full server suite and the embedded-Postgres suites do not run
here. CI is the arbiter for that coverage.
- No live Cursor CLI run was done. The fix uses a mocked process runner.
The real unknown-session error shape (error event or stderr) follows the
issue report.

## Risks

- A genuine unknown-session failure that Cursor reports only as plain
stdout text, and not as a stream-json error event or stderr, no longer
triggers the fresh-session retry. The run then fails with the error
instead of retrying. This is the intended scope change.
- A cancel that arrives after the retry decision but before the retry
process starts still starts the retry process. The server cancel
machinery must kill it. No second retry exists, so the run still ends
cancelled.
- The match patterns stay the same. A long stderr line can still match,
but stderr is Cursor's own diagnostic output, not agent transcript text.

## Model Used

Meta Muse Spark 1.3

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [ ] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [ ] All Paperclip CI gates are green
- [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [ ] I will address all Greptile and reviewer comments before
requesting merge

Signed-off-by: Josh Cox <joshuacox@users.noreply.github.com>
Co-authored-by: Review <review@local>
2026-12-05 05:21:08 -08:00
..