Skip to content

Commit 930e640

Browse files
fix(logs): a restart between polls no longer saves the new run's first lines twice (#111)
A `container logs -f` opened during one run streams on into the next run after a restart, with nothing in between. When a container was stopped and started again between two polls (the Restart button does that), the old run's follower stored the new run's first lines under the old run, and the new run's follower stored them again from its replay. A follower now holds what it reads and stores a row only once a check that began after the row was read found the container still in its run: each poll (the supervisor passes the poll's start instant to the followers it keeps; no extra process), or its own `inspect` when it holds 1 MB. When a poll finds the container out of the run, the supervisor tells the follower to stop instead of aborting it. The follower wraps up before the container's next task starts: if `inspect` still shows its run, it stores everything it holds; if the container moved on, it reads the current log once, drops the held rows that are its beginning (matched by text bytes, KMP), and stores the rest (e.g. the old run's shutdown messages). Rows held when cgui quits are dropped and replayed by the next follower. Saved rows lag the log by up to one poll interval. `logpersist::reconcile` takes the poll's start instant. Live test (c2) restarts a followed container between polls; it fails with the old behaviour (the new run's first 28 lines under the old run). Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 692cd70 commit 930e640

4 files changed

Lines changed: 653 additions & 63 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4040
from how much text is saved, which splits and missing blank lines don't
4141
change. A line that was split is still saved as two rows next to each
4242
other.
43+
- **Restarting a container no longer saves the new run's first lines
44+
twice.** After a quick restart (the Restart button stops and starts the
45+
container within a moment), background log saving could store the new
46+
run's first lines under the old run as well as under the new one. cgui now
47+
saves a line only once it has seen the container still in the same run,
48+
and keeps the old run's last lines, such as its shutdown messages. Saved
49+
logs can trail the live output by up to one refresh (2 s with the window
50+
open, 10 s when hidden).
4351

4452
### Internal
4553

‎app/src-tauri/src/lib.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,13 +434,14 @@ pub fn run() {
434434
}
435435
continue;
436436
}
437+
let polled_at = Instant::now();
437438
match state::poll_once(&history).await {
438439
Ok(cs) => {
439440
// Persist this tick before any other side effects
440441
// so a crash mid-tick still gets the data on disk.
441442
crate::history::record(&cs);
442443
// Background log capture reuses this very list.
443-
logpersist::reconcile(&cs);
444+
logpersist::reconcile(&cs, polled_at);
444445
// Display streams (Logs view) of stopped or
445446
// deleted containers never end by themselves.
446447
logstreams::reconcile(&cs);

0 commit comments

Comments
 (0)