Skip to content

fix(modal-infra): guard _current_prompt_task against overlap#80

Merged
ColeMurray merged 1 commit into
mainfrom
fix/bridge-prompt-task-race
Feb 8, 2026
Merged

fix(modal-infra): guard _current_prompt_task against overlap#80
ColeMurray merged 1 commit into
mainfrom
fix/bridge-prompt-task-race

Conversation

@ColeMurray
Copy link
Copy Markdown
Owner

@ColeMurray ColeMurray commented Feb 8, 2026

When two prompt commands overlap, the older task’s done-callback could clear _current_prompt_task after a newer prompt has already started. That breaks stop, since _handle_stop cancels _current_prompt_task.

This change only clears _current_prompt_task if the finished task is still the current one, and adds a regression test to ensure an older completion can’t wipe out a newer active prompt task.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 8, 2026

Terraform Validation Results

Step Status
Format ⚠️
Init
Validate

Note: Terraform plan was skipped because secrets are not configured. This is expected for external contributors. See docs/GETTING_STARTED.md for setup instructions.

Pushed by: @ColeMurray, Action: pull_request

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Feb 8, 2026

Greptile Overview

Greptile Summary

This PR fixes a race in AgentBridge._handle_command() where the done-callback for an older prompt task could clear self._current_prompt_task after a newer prompt has already started. The change makes the done-callback clear _current_prompt_task only if the finished task is still the current one, and adds a regression test that starts two overlapping prompt tasks and ensures the older completion does not wipe out the newer active task.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a race in modal-infra’s sandbox bridge where overlapping prompt commands could cause an older prompt task’s done-callback to clear _current_prompt_task after a newer prompt has started, which would break stop behavior.

Changes:

  • Guard _current_prompt_task clearing so only the currently-tracked task can clear itself on completion.
  • Add a regression test to ensure an older prompt completion can’t wipe out a newer active prompt task.
  • Minor test cleanup (import usage and cancellation handling).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
packages/modal-infra/src/sandbox/bridge.py Prevents stale prompt task completion from clearing _current_prompt_task for a newer prompt.
packages/modal-infra/tests/test_bridge_stop.py Adds regression coverage for overlapping prompt tasks; small test cleanups.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ColeMurray ColeMurray merged commit f651ae5 into main Feb 8, 2026
17 checks passed
@ColeMurray ColeMurray deleted the fix/bridge-prompt-task-race branch February 8, 2026 05:02
bleleve added a commit to bleleve/background-agents that referenced this pull request Jun 1, 2026
…odal verdict

Two follow-ups to reef's review on ColeMurray#80:

1. The comment claimed "TTL is short by design — plans are decided in
   minutes, not hours" but the constant was 7 days. Drop to 24h and
   reword the comment so the intent matches.

2. The modal-driven verdict path (handlePlanApproveSubmission /
   handlePlanRejectSubmission) wasn't clearing the KV entry, so stale
   refs accumulated on every same-channel approval until the TTL
   expired. Add a clearPlanAwaitingKvRef helper called after the
   chat.update succeeds — also defends against a late-arriving
   cross-channel callback re-updating the message after the modal
   handler already settled it.

The TTL now acts as a floor (sessions whose awaiting message is never
acted on), not the primary lifecycle bound.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
bleleve added a commit to bleleve/background-agents that referenced this pull request Jun 1, 2026
…odal verdict

Two follow-ups to reef's review on ColeMurray#80:

1. The comment claimed "TTL is short by design — plans are decided in
   minutes, not hours" but the constant was 7 days. Drop to 24h and
   reword the comment so the intent matches.

2. The modal-driven verdict path (handlePlanApproveSubmission /
   handlePlanRejectSubmission) wasn't clearing the KV entry, so stale
   refs accumulated on every same-channel approval until the TTL
   expired. Add a clearPlanAwaitingKvRef helper called after the
   chat.update succeeds — also defends against a late-arriving
   cross-channel callback re-updating the message after the modal
   handler already settled it.

The TTL now acts as a floor (sessions whose awaiting message is never
acted on), not the primary lifecycle bound.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

2 participants