Background bash: four task-lifecycle gaps in v0.68.0 (memory sum, PTY output, PTY replay label, task records)
Description
A source review of v0.68.0 found four small gaps in the background-task code. We did not see a failure from them on a running system. Each item names the code and a possible repair.
1. The memory watcher can report a partial sum as complete
When the cgroup reading is not available, the fallback adds the memory of each process in the group. It skips a process that it cannot read, and it still returns the sum as complete:
- Linux:
memory_limit.rs:905-923:let Ok(stat) = std::fs::read_to_string(...) else { continue; };and thenSome(sum). - macOS:
memory_limit.rs:986-1002: the loop skips a failedproc_pid_rusage, and thenSome(sum).
Effect: the memory cap can see less memory than the group uses. A process that exits during the scan is a normal skip. Other read errors are not.
Possible repair: skip a process only when it no longer exists. For any other read error, return None (unknown).
2. PTY output can be incomplete without a mark
worker_thread.rs:23 starts the worker with .spawn(run).map(|_| ()) and does not keep the join handle. When a PTY task finishes, the finalizer waits at most 200 ms for the reader (registry.rs:14941-14946) and then sends the completion. It does not do a check of reader_done after the wait.
Effect: if the reader is slow, the completion can lose the last output, and nothing tells the caller. The reader thread can also continue after the task is complete.
Possible repair: when reader_done is still false after the wait, mark the output as incomplete in the completion. Keep the join handle so that shutdown can wait for the reader for a limited time.
3. PTY replay can report Killed without a check that the process stopped
pty_replay.rs:18-25: after a restart, settle_unattached_pty calls terminate_pty_group(pid) and then mark_terminal(BgTaskStatus::Killed, None, Some("pty_lost_on_bridge_restart")). It does not do a check that the group stopped. The other branch already uses FateUnknown.
Possible repair: publish Killed only after the group is gone. Otherwise publish FateUnknown, as the other branch does.
4. Two kinds of task records stay in storage
- A dead task with no exit marker is not recovered. The sweep recovers a dead
RunningorKillingtask onlyif let Ok(Some(marker)) = read_exit_marker(...)(registry.rs:10550-10557). Without a marker, the record stays not terminal, and its files stay. - The sweep removes a finished task with an undelivered result only when
abandonment_dueis true: more than seven days old, and the project root is gone, and the working directory is gone. In a project that continues to exist, AFT keeps such a record with no time limit.
Possible repair: after a grace period, close a dead task that has no marker with an unknown result. Give undelivered results a time or size limit that does not depend on the project folder.
Environment
- AFT v0.68.0, Linux. Items 1 and 2 also apply to macOS.
- Found by source review. This report has no reproduction.
Thanks for the careful review, @iceteaSA. We checked all four against our next batch, which isn't released yet:
- Memory sum: confirmed. A read error other than "process gone" will make the sum unknown, so the cap never acts on a partial number. Being fixed.
- PTY output: already fixed in the next batch. A PTY completion now waits for the reader, and if the output can't be fully drained it is marked incomplete with the reason.
- PTY replay: mostly confirmed. Replay does try to settle the group, but it publishes
Killedeven when settling times out. The proposed fix publishesKilledonly when the group is confirmed gone, andFateUnknownotherwise. - Task records: confirmed for both kinds. The proposed fix closes a dead task with no exit marker as unknown after a grace period, and gives undelivered results a time limit that doesn't depend on the project folder.
We'll post here when a release carries them.