An always-on second brain you talk to. Voice notes in Telegram → typed, linked knowledge in your Obsidian vault. Runs 24/7 on the Claude subscription you already have.
Python ai-agentsai-automationclaudeclaude-codeebbinghausknowledge-graphllmmemory-systemobsidianpersonal-assistantpkmproductivitypythonsecond-braintelegram-botvoice-assistant
fix(session): pane.log growth as a version-proof liveness fallback
smixs82e2a525a01b
diff --git a/src/d_brain/services/claude_session.py b/src/d_brain/services/claude_session.pyindex 1e2ad3e..cfd150a 100644--- a/src/d_brain/services/claude_session.py+++ b/src/d_brain/services/claude_session.py@@ -162,6 +162,14 @@ class ClaudeSession:"capture-pane", "-t", self._target, "-p", "-S", _CAPTURE_SCROLLBACK).stdout+ def _pane_log_size(self) -> int:+ """Byte size of the piped transcript — a growing log is the+ version-proof liveness signal (no on-screen text dependency)."""+ try:+ return self._pane_log.stat().st_size+ except OSError:+ return 0+def _session_exists(self) -> bool:return self._tmux("has-session", "-t", self.session_name).returncode == 0@@ -430,6 +438,7 @@ class ClaudeSession:self._send_prompt(prompt, rid, wrap=wrap)last_active = self._clock()+ last_log_size = self._pane_log_size()deadline = self._clock() + timeoutidle_streak = 0while self._clock() < deadline:@@ -465,9 +474,14 @@ class ClaudeSession:# Stall model: silence is NOT a hang signal — a quiet task# still shows the working spinner. Stuck == no visible turn# (and no completion) for longer than stall_timeout.- if is_working(cap):+ # Two liveness signals: the recognized spinner, OR a growing+ # transcript — pane.log growth is version-proof and survives+ # any future change to the spinner's on-screen text.+ log_size = self._pane_log_size()+ if is_working(cap) or log_size > last_log_size:last_active = self._clock()- elif self._clock() - last_active > self._stall_timeout:+ last_log_size = log_size+ if self._clock() - last_active > self._stall_timeout:self._interrupt()# leave inflight as an orphan/stuck signal for the watchdogreturn AskResult("error", detail="session stalled (no active turn)")diff --git a/tests/test_claude_session.py b/tests/test_claude_session.pyindex 40a43b2..926e058 100644--- a/tests/test_claude_session.py+++ b/tests/test_claude_session.py@@ -518,3 +518,39 @@ def test_ask_dismisses_feedback_survey_instead_of_stalling(tmp_path, clock):assert pressed, "survey was not dismissed with 0"escapes = [c for c in fake.sent_keys() if c[-1] == "Escape"]assert not escapes, "stall interrupt fired instead of dismissing survey"+++def test_growing_pane_log_prevents_false_stall(tmp_path, clock):+ # Version-proof liveness: even if a future spinner format is+ # unrecognized, a transcript that keeps growing means the brain is+ # working — it must not be killed as a stall.+ log = tmp_path / ".dbrain" / "pane.log"+ log.parent.mkdir(parents=True, exist_ok=True)+ log.write_text("")+ busy = "thinking, but with a spinner we do not recognize\n"+ fake = FakeTmux([READY] + [busy] * 20 + [_complete("rid00001")], exists=True)+ s = make_session(tmp_path, fake, clock) # stall_timeout=10, poll=1++ def grow_sleep(seconds: float) -> None:+ clock["now"] += seconds+ with log.open("a") as f:+ f.write("x" * 100) # transcript advancing → alive++ s._sleep = grow_sleep+ res = s.ask("long task")+ assert res.status == "ok"+ assert not any(c[-1] in ("Escape", "C-c") for c in fake.sent_keys())+++def test_static_pane_log_and_no_spinner_still_stalls(tmp_path, clock):+ # The fallback must not disable stall detection: a genuinely wedged+ # turn (no spinner, transcript frozen) still gets interrupted.+ log = tmp_path / ".dbrain" / "pane.log"+ log.parent.mkdir(parents=True, exist_ok=True)+ log.write_text("frozen")+ busy = "no spinner, no markers, nothing changing\n"+ fake = FakeTmux([READY] + [busy] * 40, exists=True)+ s = make_session(tmp_path, fake, clock)+ res = s.ask("x", timeout=600)+ assert res.status == "error"+ assert "stall" in (res.detail or "").lower()