Skip to content

fix: send BranchResult on failure to prevent channel orphaning#279

Merged
jamiepine merged 1 commit intospacedriveapp:mainfrom
l33t0:fix/branch-failure-orphan
Mar 1, 2026
Merged

fix: send BranchResult on failure to prevent channel orphaning#279
jamiepine merged 1 commit intospacedriveapp:mainfrom
l33t0:fix/branch-failure-orphan

Conversation

@l33t0
Copy link
Contributor

@l33t0 l33t0 commented Mar 1, 2026

Summary

When branch.run() returns an error, the spawned task logged the failure but never sent a ProcessEvent::BranchResult back to the channel. This caused the channel to become permanently stuck:

  1. Branch ID stays in active_branches indefinitely (leaked handle)
  2. Retrigger never fires (should_retrigger stays false)
  3. Channel LLM never runs again — no reply is ever delivered
  4. Metrics counter never decrements

The fix sends a BranchResult with the error as the conclusion on failure, matching how workers already handle this correctly via WorkerComplete with notify: true.

Root cause

In channel_dispatch.rs, the tokio::spawn block for branch.run() only handled Err with a tracing::error! log — no event was sent. Meanwhile, branch.run() itself only sends BranchResult on the success path (after the agentic loop breaks normally). Any hard failure (e.g. LLM API error, invalid model) fell through silently.

Comparison with workers

Workers already handle this correctly — their spawn block matches on both Ok and Err, always setting notify: true:

let (result_text, notify) = match future.await {
    Ok(text) => (text, true),
    Err(error) => {
        tracing::error!(...);
        (format!("Worker failed: {error}"), true)  // still notifies
    }
};

Test plan

  • cargo clippy -- -D warnings clean
  • cargo fmt -- --check clean
  • Verified single call site for branch.run() — no other spawn locations

When branch.run() returns an error, the spawned task only logged the
failure but never sent a ProcessEvent::BranchResult back to the channel.
This caused:

1. The branch ID to stay stuck in active_branches indefinitely (leaked)
2. The retrigger to never fire (should_retrigger stays false)
3. The channel LLM to never run again to deliver a reply
4. The metrics counter to never decrement

Now the spawned task sends a BranchResult with the error as the
conclusion on failure, matching how workers already handle this via
WorkerComplete with notify: true.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 1, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f0ccd6e and 4b8c591.

📒 Files selected for processing (1)
  • src/agent/channel_dispatch.rs

Walkthrough

Adds error handling for spawned branch tasks by capturing task metadata (event_tx, agent_id, channel_id) before execution and sending a ProcessEvent::BranchResult with failure details when the branch task errors, ensuring failure notifications are reported to the channel.

Changes

Cohort / File(s) Summary
Branch task failure notification
src/agent/channel_dispatch.rs
Captures task metadata and sends ProcessEvent::BranchResult on branch execution errors instead of silently ignoring failures. No public API changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: fixing a bug where branch failures don't send notifications, causing the channel to become stuck.
Description check ✅ Passed The description is directly related to the changeset, providing clear context about the bug, root cause, comparison with workers, and test plan.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@jamiepine jamiepine merged commit 08c5e8c into spacedriveapp:main Mar 1, 2026
4 checks passed
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