Skip to content

feat(vscode): cancel in-flight requests with Escape. - #789

Merged
will-lamerton merged 5 commits into
Nano-Collective:mainfrom
arpan7sarkar:feat/webview-escape-cancel
Aug 13, 2026
Merged

will-lamerton merged 5 commits into
Nano-Collective:mainfrom
arpan7sarkar:feat/webview-escape-cancel

Conversation

@arpan7sarkar

Copy link
Copy Markdown
Contributor

Description

Implements #758

Pressing Escape in the VS Code extension's chat panel now cancels an in-flight LLM request, mirroring the existing Stop button. The listener is bound on the webview's document (not just the chat input) so it fires even when focus has moved to a tool card, dropdown, or the streaming response area, and it's guarded by isProcessing so it's a no-op when idle. Also added a nanocoder.cancel command for the Command Palette.

While wiring this up, found that cancelling mid-stream surfaced as a Nanocoder prompt failed: RequestError: Internal error toast — AcpAgent.prompt was throwing a generic error on abort, and the ACP JSON-RPC layer flattened it into an opaque failure. Fixed that too: cancellation is now recognized explicitly, reported inline in the chat as "Cancelled by user", and resolved with stopReason: 'cancelled' instead of rejecting. NanocoderAcpClient also tracks an in-flight cancel client-side and suppresses the toast for it, so this holds even against a CLI build that hasn't picked up the agent-side change. Genuine errors still show the toast as before.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Changeset

  • Added a changeset (pnpm changeset) describing this change for the changelog

Docs-only or internal chores need no changeset (or run pnpm changeset --empty to note that intentionally).

Testing

Automated Tests

  • New features include passing tests in .spec.ts/tsx files
  • All existing tests pass (pnpm test:all completes successfully)
  • Tests cover both success and error scenarios

Manual Testing

  • Tested with Ollama
  • Tested with OpenRouter
  • Tested with OpenAI-compatible API
  • Tested MCP integration (if applicable)

Checklist

  • Code follows project style guidelines
  • Self-review completed
  • Documentation updated (if needed)
  • No breaking changes (or clearly documented)
  • Appropriate logging added using structured logging (see CONTRIBUTING.md)

Copilot AI lite review requested due to automatic review settings August 4, 2026 09:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@arpan7sarkar

Copy link
Copy Markdown
Contributor Author

Hey @akramcodez do check it out and let me know if any changes are needed .

@arpan7sarkar

Copy link
Copy Markdown
Contributor Author

Hey @will-lamerton , @Avtrkrb , @akramcodez , Do check this functionlity out , its perfectly working let me now if any change is needed , else merge it
Thanks

akramcodez
akramcodez previously approved these changes Aug 7, 2026

@akramcodez akramcodez left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM @arpan7sarkar, amazing work on this!

@arpan7sarkar

Copy link
Copy Markdown
Contributor Author

Thanks @akramcodez , now waiting for another review :)

@will-lamerton

Copy link
Copy Markdown
Member

Hey @arpan7sarkar - nice PR. A few small things before merge:

Blocking: cancel() doesn't flush pendingPermissions. Repro: send a message, let a tool hit a permission prompt, press Escape. The agent resolves via its abort race, but the client's resolver stays in the map, so hasPendingPermissions() stays true and _handlePrompt rejects every later message with "Please approve or deny the pending tool" until reload. Resolve each pending entry with {outcome: {outcome: 'cancelled'}} (the agent already handles that shape) and clear the map, plus dismiss the stale permission card. Pre-existing on the Stop button path, but binding Escape globally turns it from rare into routine.

Please also:

  • Add an acp-client.spec.ts case for the new cancelRequested backstop. That's the half of the fix that has to survive a version-skewed CLI, and the spec file already exists.
  • Add t.false(session.turnActive) to the new agent test, matching the sibling test above it. The finally still running on the new return path is the non-obvious bit worth pinning.
  • Extract a requestCancel() and call it from both the Escape handler and the Stop button click, so the two copies can't drift.

Non-blocking: 'Operation was cancelled' is now the fourth site coupled to that string (thrown in three places in chat-handler.ts, compared in message-helpers.tsx:18). Worth an isCancellationError() helper, but happy to take that as a follow-up rather than hold this PR.

@arpan7sarkar

Copy link
Copy Markdown
Contributor Author

Hey @will-lamerton , Thanks for giving me the broad picture and telling me the things that I am missing , I will add all this then raised a PR thanks

@akramcodez

Copy link
Copy Markdown
Member

Hey @arpan7sarkar, could you please resolve the merge conflicts when you get a chance? Thanks!

@arpan7sarkar

Copy link
Copy Markdown
Contributor Author

Hello @akramcodez today i will update the fixex that @will-lamerton told me then after that i will commmit that in the mean time i was working on #814 this pr here i actully find a big ci issue that i have fixed and mentioned there you can have a look into that

@arpan7sarkar

Copy link
Copy Markdown
Contributor Author

Hello @akramcodez @will-lamerton , Have implemnted all the requirments and also fixed merge conflicts have a look here :-)

Resolves the plugins/vscode/media/chat-panel.css conflict: Nano-Collective#846 made the
compiled CSS a build artifact (gitignored, emitted by `pnpm build:css`),
so take main's deletion. This branch only touched the file's trailing
newline - no CSS content is lost.
@will-lamerton
will-lamerton merged commit 85ac552 into Nano-Collective:main Aug 13, 2026
11 checks passed
AryanNandanwar pushed a commit to AryanNandanwar/nanocoder that referenced this pull request Aug 13, 2026
…#789)

* feat(vscode): cancel in-flight requests with Escape.

* fix(vscode): clear pending permissions when a request is cancelled

* fix(vscode): repair malformed commands array from the main merge

---------

Co-authored-by: Will Lamerton <[email protected]>
will-lamerton pushed a commit that referenced this pull request Sep 13, 2026
Hooks the background titler into the existing turn-end finally block,
fire and forget so the turn returns to idle immediately. On success it
sends a _nanocoder/sessionTitleChanged ext notification so an editor
client can refresh its session list without polling.

Turn success is tracked in a local flag rather than inferred from
reaching the finally. The cancel path added in #789 returns from inside
the catch, and the error path rethrows, and both still run the finally,
so "we got here" says nothing about whether the turn completed. The
session object carries no usable signal either: cancel() aborts its
controller and immediately swaps in a fresh one.

Three tests, and the two negative ones were verified as real pins by
temporarily forcing the guard true and confirming they fail. Without that
check they would have passed vacuously, since they also passed before any
of this was wired up.

Also carries titleGenerated forward on every save, alongside
titleManuallySet, so a title survives the next turn's persist.
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.

4 participants