fix(tui): resumed sessions retain orphaned active runs and display Thinking indefinitely
Summary
Tact can restore interrupted transcript runs as permanently active. This causes the animated Thinking… status to remain visible indefinitely even after subsequent turns complete and no tools, subagents, or model calls remain active.
Environment
• v0.3.0 • OS observed: Linux x86_64 • Trigger: Resuming a session containing an interrupted or incomplete transcript segment
Steps to reproduce
- Start a Tact session and submit a turn.
- Interrupt or terminate Tact before the turn records one of: • run.completed • run.failed • session.ended
- Resume the same session.
- Submit and complete another turn normally.
- Observe that Thinking… continues animating after the new turn has completed.
Connection loss, process termination, or a worker failure that does not produce a terminal agent event can create the incomplete historical run.
Actual behavior
During session restoration, Tact replays historical run.started events into the live transcript model.
An interrupted historical run increments active_runs, but nothing decrements it if its transcript segment lacks run.completed or run.failed. Restoration does not normalize incomplete historical activity after replay.
Every future turn can start and finish successfully, but the inherited positive balance remains. Therefore, the composer continues displaying Thinking… indefinitely.
Observed transcript evidence
One affected resumed session contained six transcript segments with:
│ run.started: 63 │ run.completed: 53 │ run.failed: 5 │ session.ended: 0 │ active balance: 5
One run was genuinely active during inspection, meaning four stale active runs had already been inherited from earlier transcript segments. After the current turn completed, the projected balance returned to four rather than zero, leaving Thinking… active.
Expected behavior
No historical run can remain operational across a process boundary.
When restoring a persisted session, Tact should normalize unfinished historical runs before installing the restored projection:
• active_runs should be zero. • The transient Thinking status should be cleared. • Historical tool calls without terminal results should be marked orphaned or failed. • Future live turns should control activity independently. • Persisted transcript records should remain unmodified.
Relevant implementation in v0.3.0/current main
Activity is defined as active_runs > 0: https://github.com/clabby/tact/blob/v0.3.0/src/tui/transcript/model.rs#L135-L136
run.started increments the counter, while run.completed and run.failed enter terminal handling: https://github.com/clabby/tact/blob/v0.3.0/src/tui/transcript/model.rs#L364-L383
Terminal handling decrements the counter and retains Thinking whenever another active run remains: https://github.com/clabby/tact/blob/v0.3.0/src/tui/transcript/model.rs#L738-L744
Session restoration replays every retained record without closing or normalizing the reconstructed historical activity: https://github.com/clabby/tact/blob/v0.3.0/src/tui/components/root.rs#L458-L477
worker.turn_finished records an error when present but does not reconcile active_runs: https://github.com/clabby/tact/blob/v0.3.0/src/tui/transcript/model.rs#L251-L258
Suggested fix
Normalize historical activity after replaying transcript records in project_session.
Conceptually:
for record in records {
let observation = context_diagnostics.observe(&record);
if observation.completed_tokens.is_some() {
context_tokens = observation.completed_tokens;
}
let _ = transcript.update(TranscriptEvent::Record(record));
}
// Historical work cannot remain active in the new process.
let _ = transcript.update(TranscriptEvent::AgentStreamClosed);
Alternatively, normalize the underlying transcript model using its existing agent_stream_closed() behavior.
Additional live-state hardening/testing
There is a related live-state reconciliation gap:
• Worker events and agent events travel through separate paths. • worker.turn_finished and run.completed can arrive in either order. • A worker task failure may produce worker.turn_finished without a corresponding terminal agent event. • worker.turn_finished currently does not reconcile activity.
A follow-up could correlate worker turns with agent runs so a missing terminal agent event can eventually be reconciled without double-decrementing overlapping runs.
This is additional hardening; restore-boundary normalization should independently fix the reproducible resumed-session defect.
Suggested tests:
- Replay a transcript ending with run.started but no terminal event.
- Confirm the restored projection is inactive.
- Confirm Thinking… is not displayed.
- Confirm orphaned historical tools are marked failed.
- Start and complete a new turn after restoration.
- Confirm the indicator activates and then clears normally.
- Replay multiple interrupted transcript segments.
- Confirm unmatched historical runs do not accumulate.
- Replay a normally completed transcript and confirm its visible history is unchanged.
- Confirm normalization does not append synthetic events or modify persisted transcript files.