Skip to content

Fix race condition causing requested commands to be auto-cancelled.#10241

Open
szgupta wants to merge 4 commits intomasterfrom
suraj/fix-active-convo-id-race
Open

Fix race condition causing requested commands to be auto-cancelled.#10241
szgupta wants to merge 4 commits intomasterfrom
suraj/fix-active-convo-id-race

Conversation

@szgupta
Copy link
Copy Markdown
Member

@szgupta szgupta commented May 6, 2026

Description

When two agent conversations run in parallel in different terminal views, set_active_conversation_id was called during automatic follow-ups (tool call → result cycles). This function has transfer semantics: it removes the conversation from every other terminal view's live list. When two views both trigger follow-ups concurrently, each view's follow-up could steal the other view's conversation, causing requested commands to be silently dropped with:

No conversation ID found for requested command

Root cause

set_active_conversation_id was designed for explicit user navigation (opening a conversation in a different pane from the command palette), but was also being called in two automatic code paths:

  1. send_follow_up_for_conversation (controller.rs) — after tool call results are sent back
  2. send_request_input (controller.rs) — when sending any non-passive request

These paths only need to update the "most recently streamed" pointer within their own view. They should never touch other views.

Fix

history_model.rs: Added mark_active_conversation_id — a non-transferring variant that updates the active conversation pointer for a single terminal view without removing the conversation from other views' live lists. The existing set_active_conversation_id (with transfer semantics) is preserved for explicit navigation call sites.

controller.rs: Switched both follow-up call sites to use mark_active_conversation_id instead of set_active_conversation_id.

history_model.rs (conversation_id_for_action): Added a global fallback search across all in-memory conversations when the per-view lookup fails. This is a safety net — if a conversation is ever removed from a view's live list while actions are in flight, the command still executes instead of being silently dropped.

Linked Issue

N/A — discovered via internal debugging of intermittent command cancellation during parallel agent conversations.

Testing

Manual testing with parallel agent conversations in split panes. The race condition is timing-dependent and not consistently reproducible, but the fix is structurally sound: the follow-up paths no longer call the transferring variant, so the race is eliminated by design.

Agent Mode

  • Warp Agent Mode - This PR was created via Warp's AI Agent Mode

Co-Authored-By: Oz [email protected]
Conversation

@cla-bot cla-bot Bot added the cla-signed label May 6, 2026
@szgupta szgupta force-pushed the suraj/fix-active-convo-id-race branch from 86b1197 to 46a26eb Compare May 6, 2026 06:12
@szgupta szgupta force-pushed the suraj/fix-active-convo-id-race branch from 46a26eb to e64a356 Compare May 6, 2026 06:16
@szgupta szgupta changed the title [WIP] Fix race condition related to setting active conversation ID. Fix race condition: set_active_conversation_id transfers conversations between views during follow-ups May 6, 2026
@szgupta szgupta changed the title Fix race condition: set_active_conversation_id transfers conversations between views during follow-ups Fix race condition causing requested commands to be auto-cancelled. May 6, 2026
@szgupta
Copy link
Copy Markdown
Member Author

szgupta commented May 6, 2026

@zachbai this is a short-term fix. Real fix is consolidating these terminal view <> convo ID maps and their access patterns. It's a big mess right now and will require a good amount of work to avoid regressing stuff. So this is an in-between to get the halting problem fixed.

@szgupta szgupta requested a review from zachbai May 6, 2026 06:35
@szgupta szgupta marked this pull request as ready for review May 6, 2026 06:35
@oz-for-oss
Copy link
Copy Markdown
Contributor

oz-for-oss Bot commented May 6, 2026

@szgupta

I'm starting a first review of this pull request.

I completed the review and no human review was requested for this pull request.

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

@zachbai
Copy link
Copy Markdown
Contributor

zachbai commented May 6, 2026

@zachbai this is a short-term fix. Real fix is consolidating these terminal view <> convo ID maps and their access patterns. It's a big mess right now and will require a good amount of work to avoid regressing stuff. So this is an in-between to get the halting problem fixed.

We should be able to get rid of the active_conversation_id map. It's redundant with the active conversation_id in the AgentViewController, which is more correctly the source of truth for "conversation actively displayed in this terminal pane"

Copy link
Copy Markdown
Contributor

@oz-for-oss oz-for-oss Bot left a comment

Choose a reason for hiding this comment

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

Overview

This PR separates explicit conversation transfer from automatic active-conversation marking and adds a fallback lookup for requested command actions.

Concerns

  • The global fallback in conversation_id_for_action drops the terminal-view ownership constraint and can associate a requested command with a conversation from another pane.

Verdict

Found: 0 critical, 1 important, 0 suggestions

Request changes

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

Comment thread app/src/ai/blocklist/history_model.rs Outdated
// Fallback: the conversation may have been transferred to another view
// or removed from the live list while the action was executing. Search
// all in-memory conversations so the command is not silently dropped.
let fallback = self
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.

⚠️ [IMPORTANT] The fallback ignores terminal-view ownership, so any caller that fails the per-view lookup can bind this action to a conversation owned by another pane; TerminalView then executes the requested command in the current pane's active session. Keep the fallback scoped to conversations owned by terminal_view_id (or use an action→conversation mapping) rather than searching every conversation.

@szgupta szgupta enabled auto-merge (squash) May 6, 2026 06:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants