Background task elapsed time restarts after a restart for non-Claude harnesses
PR #7550 shows how long each background task has run, in the tab above the chat composer. For every harness except Claude Code, that time counts from when Orchestrator first saw the task, not from when the task started. When the daemon restarts or the chat reconnects, the same task shows a fresh time ("0s", then counting) even though it has been running all along.
Why it happens
- The ACP harnesses, Codex and Unreal Agent keep their tasks in the shared tracker (
backend/internal/adapters/chatdriver/backgroundtasks/tracker.go). The tracker stampsStartedAtthe first time it records a task. - The tracker lives only in memory, inside the driver's conversation. After a restart or reconnect it is rebuilt from provider replay or a fresh native read, so every task is "first seen" again and gets a new start time.
- Claude Code is not affected: AO's runtime projection records the task's own
task_startedtime and keeps it for the life of that run.
Steps to reproduce
- Start a Codex chat and have it run a long background command (for example
sleep 900). - Wait a few minutes. The tab shows the elapsed time, for example "4m".
- Restart the app, or let the chat controller reconnect.
- The same task now shows "0s" and counts up from there.
Ways to fix it
- Use a real start time where the provider sends one, for example the timestamp of Codex's
item/startedfor the exec item, or the ACP tool call that launched the job. - Otherwise, persist the first-seen time per task (keyed by session, task id and run id), so a restart keeps it instead of stamping a new one.
- If neither is known, report no start time. The tab already hides the elapsed time when
startedAtis missing, which is better than showing a wrong number.
Done when
The elapsed time for a running Codex or ACP task stays the same across a daemon restart and a chat reconnect, and a new run of the same task id still starts from zero.
@Annieeeee11 are u actively working on this one or would like to pass ?
Triage note: this bug is in the unmerged #7550, not on main (main has no background-task tracker yet). The fix belongs in #7550 before it merges. I've left the details there.
@Annieeeee11 are u actively working on this one or would like to pass ?
@bhushan4work you can pick this up
@nikhilachale now that #7550 is merged, can you confirm whether #8326 still reproduces on main i.e., should i open a new pr for the elapsed-time fix, or is it already resolved?
@bhushan4work yes it still exists on the main so can take a deep dive in it and fix it properly