Skip to content

feat: update BranchTracker.last_activity_at during branch execution #557

@EZotoff

Description

@EZotoff

Summary

Follow-up from #556. The last_activity_at field on BranchTracker is currently only set at branch spawn time. To make branch timeout detection truly activity-based, it should be updated during branch execution — on tool completions, text deltas, or LLM call boundaries.

Current State

  • BranchTracker.last_activity_at is set to Instant::now() in track_branch_start
  • The cortex supervisor checks it for timeout detection: now.duration_since(tracker.last_activity_at) >= branch_timeout
  • But since it's never updated after spawn, it's functionally equivalent to started_at

Proposed Approach

Add a ProcessEvent variant (e.g., BranchActivity { branch_id }) sent from SpacebotHook on tool completions and/or text deltas. The cortex event loop would then update last_activity_at in the branch tracker. This requires:

  1. New ProcessEvent variant in src/agent.rs (or wherever the enum lives)
  2. Hook emits the event from on_tool_result and/or on_text_delta in SpacebotHook
  3. Cortex event loop handler in cortex.rs receives it and updates branch_trackers[last_activity_at]
  4. Careful mutex handling to avoid blocking the health tick or the event loop

Why Not Just Use Wall-Clock

A branch can legitimately run for 2-3 minutes doing memory recalls and tool calls. Wall-clock timeouts would kill active branches. Activity-based detection distinguishes "working slowly" from "genuinely stuck."

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions