Skip to content

Fixed an issue where background tasks would also terminate when a to-do task session ended - #1159

Merged
xintaofei merged 5 commits into
mainfrom
task/538
Nov 15, 2026
Merged

xintaofei merged 5 commits into
mainfrom
task/538

Conversation

@xintaofei

Copy link
Copy Markdown
Collaborator

Prepared by codeg work task 538.

…unning

A task's turn ending used to retire and disconnect its connection at
once, killing any background Bash/Monitor the agent had started and
leaving the user to ask "so what happened?". A normal end_turn that
leaves background work (for agents that resume on their own), a live
delegated child, or a pending permission behind now holds the run
open instead: it settles once that work and the agent's own follow-up
turn have been quiet for 15 s, or after the keepalive cap
(CODEG_ACP_BACKGROUND_KEEPALIVE_MAX_SECS, 60 min by default, 0
disables), using the follow-up's reply as the summary.

- acp/turn_end_hold: the shared probe and wait loop; AIR async tasks
  outrank a possibly stranded watcher count
- work_task engine: background_wait / background_wait_end events,
  stop-waiting action, cancel/reconcile aware, boot settles holds a
  restart cut short into review; a task already closed with
  task_complete is not held
- automation engine: same hold before settling a run
- UI: card note with the running count, "Stop waiting" action, and
  timeline entries, in all 10 locales
…al async-task tables

Review follow-ups on the turn-end hold:

- The waiter now marks its hold `settling` and drops it only after the
  generation is settled, so the reconcile tick and merge recovery can no
  longer settle a held run first (without its summary or verdict) in the
  gap between the wait ending and the settle. A cancel leaves a settling
  hold to its waiter; it has already won the row. Merge recovery skips
  held generations. The automation engine keeps its held marker through
  the settle the same way.
- The async-task table outranks the watcher's count only for Claude
  Code, whose table carries all its background work. Grok publishes
  only workflow runs there, so a finished workflow no longer hides a
  background sub-agent still running.
- A connection lost mid-hold keeps the last probe, so a follow-up reply
  read before it went away is still the summary.
… ends

Production review follow-ups on the turn-end hold:

- A turn that ends on a held connection after the held one (a turn
  Grok starts on its own, or a prompt sent to the session meanwhile)
  is no longer dropped. Its answer and reported error now feed the
  settle, and one that ends otherwise than `end_turn` (stopped,
  refused, failed) ends the wait: the run settles canceled/failed as
  that turn ended, instead of into review or "succeeded" on the held
  turn's `end_turn`. Same in the automation engine, whose held set
  becomes a map carrying a stop token.
- The settle summary is the newest answer since the hold began,
  background reply or later turn alike, so a prompted fix made after
  the agent reported a failure no longer loses to that older report.
- At boot, a held merge generation has its open wait closed too; the
  merge recovery still settles it from git.
The later turn's answer was stamped when the engine consumed its
TurnComplete, which can lag the bus, while the background reply is
stamped as the session applies it — so a lagging engine could rank an
older prompted answer over a newer background report. The session now
stamps `last_turn_completed_at` beside `last_assistant_text`, the probe
carries both answers with their session-side stamps, and the hold
starts from the held turn's own completion time. LaterTurns keeps only
how a later turn ended.
…ost connection

The session keeps only its last turn's answer, cleared by a turn that
said nothing, and it goes with the connection. So when the engine handles
a later turn on a held connection, it keeps that turn's answer, with the
session's stamp, in LaterTurns again. The settle takes the newest of the
background reply, the last look's turn answer, and the kept one, all
on the session's clock.
@xintaofei
xintaofei merged commit 4c3af65 into main Nov 15, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant