spacedriveapp / spacedriveapp/spacebot

feat: update BranchTracker.last_activity_at during branch execution

Open
#557 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
2.4k
Forks
367
PR merge metrics
No merged PRs in 30d

Description

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

  • #556 — initial per-call timeout + BranchTracker infrastructure
  • #332 — related activity tracking work

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with ProcessEvent in src/agent.rs, then trace SpacebotHook's on_tool_result and on_text_delta into the cortex.rs event loop. Follow the existing BranchTracker timeout check and track_branch_start flow. Done means branch activity updates last_activity_at during execution without blocking health ticks or the event loop.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.