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:
- New
ProcessEvent variant in src/agent.rs (or wherever the enum lives)
- Hook emits the event from
on_tool_result and/or on_text_delta in SpacebotHook
- Cortex event loop handler in
cortex.rs receives it and updates branch_trackers[last_activity_at]
- 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
Summary
Follow-up from #556. The
last_activity_atfield onBranchTrackeris 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_atis set toInstant::now()intrack_branch_startnow.duration_since(tracker.last_activity_at) >= branch_timeoutstarted_atProposed Approach
Add a
ProcessEventvariant (e.g.,BranchActivity { branch_id }) sent fromSpacebotHookon tool completions and/or text deltas. The cortex event loop would then updatelast_activity_atin the branch tracker. This requires:ProcessEventvariant insrc/agent.rs(or wherever the enum lives)on_tool_resultand/oron_text_deltainSpacebotHookcortex.rsreceives it and updatesbranch_trackers[last_activity_at]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