Skip to content

fix(desktop): interrupt-first after Stop so edit/resend avoids session-busy - #84629

Closed
olympusbuildz wants to merge 1 commit into
NousResearch:mainfrom
olympusbuildz:fix/desktop-stop-edit-session-busy-83855
Closed

olympusbuildz wants to merge 1 commit into
NousResearch:mainfrom
olympusbuildz:fix/desktop-stop-edit-session-busy-83855

Conversation

@olympusbuildz

Copy link
Copy Markdown

Problem

After Stop, editing a user message and resending often fails with session busy (or a silent no-op). Frontend cancelRun clears busy immediately while the gateway may still be winding down the interrupted turn. editMessage / restoreToMessage then computed interruptFirst only from busy, so rewind submitted without interrupt-first and raced 4009.

A second footgun: _submitInFlight was a bare Set with no TTL. A hung prompt.submit never released the lock, so later sends silently returned false.

Root cause

  • apps/desktop/src/app/session/hooks/use-prompt-actions/index.ts — cancelRun sets busy: false before/while gateway interrupt settles; edit path used busyRef || $busy only.
  • Same pattern on session tiles (session-tile-actions.ts).
  • utils.ts — submit-in-flight lock never expired.

Fix

  1. 3s per-session cooldown after Stop (markSessionRecentlyInterrupted / shouldInterruptBeforeRewind) so edit/restore still interrupt-first while the gateway settles. Idle rewinds (not busy, not recently interrupted) stay interrupt-free.
  2. 30s TTL on the submit-in-flight lock (acquireSubmitInFlight / releaseSubmitInFlight) so a hung submit cannot permanently block the session.

Why it matters

Stop → edit/resend is a common recovery path. Users currently have to open a new session when the race hits.

Test plan

cd apps/desktop
npm run test:ui -- src/app/session/hooks/use-prompt-actions/utils.test.ts src/app/session/hooks/use-prompt-actions/rewind.test.ts

55 passed @ 47dc9be63e364768b7381eb9c297c9f99ffd5e5e (Mini, Hermes-run after Cursor Auto).

Covered: cooldown true/false at boundary; shouldInterruptBeforeRewind true after Stop with busy=false; idle stays false; lock blocks while fresh and reclaims after TTL; explicit release.

Risk / blast radius

  • Desktop renderer only (primary chat + session tiles).
  • Idle restore/edit should not interrupt (interruptFirst captured before optimistic busy=true).
  • TTL only frees locks older than 30s; normal paths still release in finally.

Closest work

none found (issue #83855 + keyword search for session-busy / recentlyInterrupted / edit after Stop).

Fixes #83855

…n-busy

Stop clears frontend busy immediately while the gateway may still wind
down. Edit/restore then passed interruptFirst=false and raced 4009
session busy. Keep a short per-session cooldown after cancel so rewind
still interrupt-first, and expire the submit-in-flight lock so a hung
submit cannot block the session forever.

Fixes NousResearch#83855

Co-authored-by: Olympusbuildz <Olympus.roots@outlook.com>
Signed-off-by: Olympusbuildz <Olympus.roots@outlook.com>
@alt-glitch alt-glitch added type/bug Something isn't working comp/desktop Electron desktop app (apps/desktop/*) P3 Low — cosmetic, nice to have labels Aug 12, 2026
@teknium1

Copy link
Copy Markdown
Collaborator

Thank you for this fix! It was salvaged into #86594 (cherry-picked onto current main with your authorship preserved in the commit history) and is now merged. Closing this PR since the work has landed.

@teknium1 teknium1 closed this Aug 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/desktop Electron desktop app (apps/desktop/*) P3 Low — cosmetic, nice to have type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(desktop): edit/resend after Stop hits session-busy race condition

3 participants