From 60dff3107b7c5c2b51481952c7b74616b9fb8871 Mon Sep 17 00:00:00 2001 From: Jacob Stephens Date: Fri, 23 Oct 2026 20:30:01 -0400 Subject: [PATCH 1/2] Show Inbox finish times with explicit time-ago labels (#1207) --- console/README.md | 8 ++ console/tests/inbox.test.cjs | 42 +++++++++ docs/guide.md | 2 +- site/how-it-works/index.html | 1 + src/console/assets/console.css | 2 +- src/console/row.html | 2 +- src/logs/command_record.rs | 4 + src/logs/reading.rs | 1 + src/logs/status/inbox.rs | 54 ++++++++++-- tests/console/inbox.rs | 157 +++++++++++++++++++++++++++++++++ 10 files changed, 263 insertions(+), 10 deletions(-) diff --git a/console/README.md b/console/README.md index 91d5905e9..389b96470 100644 --- a/console/README.md +++ b/console/README.md @@ -133,6 +133,14 @@ and Ready tag colours, Landing keeps Working's live-activity marker, and a live row given a Stop shows Stopping with a drifting stripe until it ends. Pause motion and reduced motion hold the stripe still. +Ended rows show their recorded finish date and time in UTC, followed by an +explicit relative age, such as “Ended Oct 23, 2026 at 23:03:17 UTC · 52 min ago”. +That age is time since finish, not run duration. Each nested Ticket run uses its +own finish time, including in History. Refreshing recomputes the relative age +and keeps the recorded instant. The information is rendered by the server and +remains visible without JavaScript. Missing or invalid finish times say “End +time unknown”; file modification times are not presented as recorded finishes. + When no Commands are live on this machine, the Inbox explains that above its sections. It points to ended problems in Needs you and pull requests in Ready for review, and shows the last recorded skipped Pass reasons from Activity logs. diff --git a/console/tests/inbox.test.cjs b/console/tests/inbox.test.cjs index 27f5a80c6..605f42837 100644 --- a/console/tests/inbox.test.cjs +++ b/console/tests/inbox.test.cjs @@ -187,6 +187,48 @@ test("Inbox folds, loads only its own resources and fits a 390 px phone", async assert.equal(await page.evaluate(() => document.fonts.check('14px "IBM Plex Sans"') && document.fonts.check('12px "IBM Plex Mono"')), true); }); +test("finish information is visible without JavaScript on a narrow phone", async t => { + const page = await pageFor(t, { javaScriptEnabled: false, viewport: { width: 320, height: 844 } }); + await page.goto(origin); + const age = page.locator('[data-group="needs you"] .command > .row-head > .age').first(); + assert.equal(await age.isVisible(), true); + assert.match(await age.innerText(), /^Ended \w+ \d+, \d{4} at \d\d:\d\d:\d\d UTC · \d+ (sec|min|hr \d+ min) ago$/); + assert.ok(Number.isFinite(Date.parse(await age.locator('time').getAttribute('datetime')))); + const box = await age.boundingBox(); + assert.ok(box.x >= 0 && box.x + box.width <= 320, JSON.stringify(box)); + assert.equal(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth), true); + assert.equal(await page.locator('.command .peek-link').first().isVisible(), true); +}); + +test("existing refresh advances finish age while keeping its recorded instant", async t => { + const path = join(home, '.thirdshift/logs/acme/widgets/commands/issue/71-fixture.command.json'); + const end = new Date(Date.now() - 55000).toISOString(); + const fixture = JSON.parse(await readFile(join(home, '.thirdshift/logs/acme/widgets/commands/issue/1-fixture.command.json'), 'utf8')); + fixture.issue = { number: 71, url: 'https://github.com/acme/widgets/issues/71', title: 'Finish refresh fixture' }; + fixture.started_at = new Date(Date.parse(end) - 140 * 60000).toISOString(); + fixture.ended_at = end; + fixture.cause = 'finish refresh fixture'; + await writeFile(path, JSON.stringify(fixture)); + t.after(() => rm(path, { force: true })); + const page = await pageFor(t); + await page.goto(origin); + const row = page.locator('.command').filter({ has: page.locator('a[href="https://github.com/acme/widgets/issues/71"]') }); + const time = row.locator('time'); + assert.equal(await time.getAttribute('datetime'), end); + assert.match(await row.locator('.age').textContent(), /\d+ sec ago$/); + const absolute = await time.textContent(); + // Cross the server's minute boundary, then wake the ordinary filesystem refresh. + await page.waitForTimeout(Math.max(0, Date.parse(end) + 61000 - Date.now())); + await appendFile(join(home, '.thirdshift/logs/acme/widgets/commands/issue/1-fixture.log'), 'Refresh finish age\n'); + await page.waitForFunction(() => [...document.querySelectorAll('.command')].some(row => + row.querySelector('a[href="https://github.com/acme/widgets/issues/71"]') && row.querySelector('.age')?.textContent.includes('1 min ago'))); + assert.equal(await time.getAttribute('datetime'), end); + assert.equal(await time.textContent(), absolute); + await page.reload(); + assert.match(await row.locator('.age').textContent(), /1 min ago$/); + assert.equal(await time.getAttribute('datetime'), end); +}); + test("all section headings fit above the fold on a 14 inch laptop with a busy Needs you", async t => { const page = await pageFor(t, { viewport: { width: 1440, height: 900 } }); await page.goto(origin); diff --git a/docs/guide.md b/docs/guide.md index 895af22a5..88dd642de 100644 --- a/docs/guide.md +++ b/docs/guide.md @@ -279,7 +279,7 @@ To open this machine's Inbox locally, run: thirdshift console --no-sign-in ``` -Open the localhost address it prints. The Console shows the same Inbox as `thirdshift status`, with live stages, logs and Session traces. It never starts work; start Commands from the CLI or the operating system's scheduler. +Open the localhost address it prints. The Console shows the same Inbox as `thirdshift status`, with live stages, logs and Session traces. Ended rows show their recorded finish date and time in UTC and an explicit relative age, for example **Ended Oct 23, 2026 at 23:03:17 UTC · 52 min ago**. This is time since finish, not run duration. Nested Ticket runs and History use each Command's own finish time; missing or invalid finish times say **End time unknown**. The finish information also works without JavaScript. The Console never starts work; start Commands from the CLI or the operating system's scheduler. #### Console on a server diff --git a/site/how-it-works/index.html b/site/how-it-works/index.html index 49f38e246..b8b9f6965 100644 --- a/site/how-it-works/index.html +++ b/site/how-it-works/index.html @@ -153,6 +153,7 @@

How thirdshift works

thirdshift logs https://github.com/acme/widgets/issues/7 --follow

The Console shows this machine's Commands, opening on its Inbox. Beside the CLI, you can watch their stages and logs there. For this machine on localhost, start it with:

When no Commands are running, the Inbox shows the last recorded skipped Pass reasons, points to work waiting for you, and links to Cron jobs to help diagnose launch failures. If no reason was recorded, it says so.

+

Ended rows show the recorded finish date and time in UTC and an explicit age, such as Ended Oct 23, 2026 at 23:03:17 UTC · 52 min ago. The age means time since finish, not run duration. Nested Ticket runs and History show each Command's own finish; an unavailable finish says End time unknown.

thirdshift console --no-sign-in

For a server, thirdshift console install prints an installation script to read and run with sudo, putting its Console behind a sign-in. Console installation and machine status.

A signed-in Console account can Stop a live Command or Requeue it for Pickup. The CLI does the same:

diff --git a/src/console/assets/console.css b/src/console/assets/console.css index b18300f0e..8c312ce69 100644 --- a/src/console/assets/console.css +++ b/src/console/assets/console.css @@ -25,7 +25,7 @@ summary .count { margin-left: 12px; color: var(--dim); font-size: 13px; } .row-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; } .state { color: var(--text); } .heartbeat { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--working); opacity: .4; } -.age { margin-left: auto; white-space: nowrap; } +.age { margin-left: auto; } .issue-title { flex: 1 1 160px; } .command p { margin: 4px 0 0; } .now { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } diff --git a/src/console/row.html b/src/console/row.html index 4d5a5e939..c7db4ce3b 100644 --- a/src/console/row.html +++ b/src/console/row.html @@ -1,5 +1,5 @@
  • -
    {% if row.live %}{% endif %}{{ row.state }} {% match row.subject_url %}{% when Some with (url) %}{{ row.subject }}{% when None %}{{ row.subject }}{% endmatch %} {{ row.title }}{{ row.age }}
    +
    {% if row.live %}{% endif %}{{ row.state }} {% match row.subject_url %}{% when Some with (url) %}{{ row.subject }}{% when None %}{{ row.subject }}{% endmatch %} {{ row.title }}{% match row.timing.finish %}{% when Some with (finish) %} · {% when None %}{% endmatch %}{{ row.timing.age }}

    {{ row.now_line|linkify }}

    Command logs and Session traces {% if !row.harness.is_empty() %}

    {{ row.harness }}

    {% endif %} diff --git a/src/logs/command_record.rs b/src/logs/command_record.rs index e7153f396..1e9196046 100644 --- a/src/logs/command_record.rs +++ b/src/logs/command_record.rs @@ -44,6 +44,9 @@ pub(super) struct CommandRecord { pub started_at: String, #[serde(default)] pub ended_at: Option, + /// Reader-only provenance: legacy retention estimates are not recorded finishes. + #[serde(skip)] + pub end_time_estimated: bool, pub stages: Vec, pub session_log: Option, pub outcome: Option, @@ -287,6 +290,7 @@ impl CommandRecord { effort: harness.effort.clone(), started_at: now.to_rfc3339(), ended_at: None, + end_time_estimated: false, stages: Vec::new(), session_log: None, outcome: None, diff --git a/src/logs/reading.rs b/src/logs/reading.rs index 3b390bcc8..618b29129 100644 --- a/src/logs/reading.rs +++ b/src/logs/reading.rs @@ -237,6 +237,7 @@ fn read_records(folder: &Path) -> Result> { // Records written before completion times existed were last // replaced when their outcome was recorded. if record.outcome.is_some() && record.ended_at.is_none() { + record.end_time_estimated = true; record.ended_at = entry .metadata()? .modified() diff --git a/src/logs/status/inbox.rs b/src/logs/status/inbox.rs index 9143f55e1..de596da0b 100644 --- a/src/logs/status/inbox.rs +++ b/src/logs/status/inbox.rs @@ -1,6 +1,6 @@ //! Owned Inbox presentation for the Console, from the same observations as status. use anyhow::Result; -use chrono::{DateTime, Local}; +use chrono::{DateTime, Local, Utc}; use std::path::Path; use super::{age, stage_text, ticket_text}; @@ -37,7 +37,7 @@ pub(crate) struct Row { pub title: String, pub state: String, pub now_line: String, - pub age: String, + pub timing: Timing, pub count: usize, pub cause: String, pub harness: String, @@ -48,6 +48,41 @@ pub(crate) struct Row { pub sessions: Vec, } +pub(crate) struct Timing { + pub finish: Option, + pub age: String, +} + +pub(crate) struct Finish { + pub datetime: String, + pub label: String, +} + +impl Timing { + fn new(live: bool, start: &str, end: Option<&str>, now: DateTime) -> Self { + if live { + return Self { + finish: None, + age: elapsed(start, now), + }; + } + let finish = end.and_then(|end| { + DateTime::parse_from_rfc3339(end).ok().map(|time| Finish { + datetime: end.into(), + label: time + .with_timezone(&Utc) + .format("%b %-d, %Y at %H:%M:%S UTC") + .to_string(), + }) + }); + let age = finish.as_ref().map_or_else( + || "End time unknown".into(), + |finish| format!("{} ago", elapsed(&finish.datetime, now)), + ); + Self { finish, age } + } +} + impl Row { pub fn peek_url(&self) -> String { super::inspect::url("/peek", &self.selector, None) @@ -179,10 +214,7 @@ fn entry_row(entry: Observation<'_>, now: DateTime, root: &std::path::Pat .outcome .clone() .unwrap_or_else(|| "unknown outcome".into()), - age: elapsed( - command.ended_at.as_deref().unwrap_or(&command.started_at), - now, - ), + timing: Timing::new(false, &command.started_at, command.ended_at.as_deref(), now), count: 1, cause: String::new(), harness: String::new(), @@ -334,7 +366,15 @@ fn row( title, state: command.state.into(), now_line: stage_text(command), - age: elapsed(facts.ended_at.as_deref().unwrap_or(&facts.started_at), now), + timing: Timing::new( + live, + &facts.started_at, + facts + .ended_at + .as_deref() + .filter(|_| !facts.end_time_estimated), + now, + ), count: 1, cause: facts.cause.clone().unwrap_or_default(), harness: format!( diff --git a/tests/console/inbox.rs b/tests/console/inbox.rs index 33e5c1518..5edd211f9 100644 --- a/tests/console/inbox.rs +++ b/tests/console/inbox.rs @@ -3,6 +3,163 @@ use serde_json::Value; use std::path::Path; use std::{fs, process::Command}; +#[test] +fn ended_rows_distinguish_finish_age_from_run_duration() { + use super::write_record; + use serde_json::json; + + let home = tempfile::tempdir().unwrap(); + configure(home.path()); + let end = chrono::Utc::now() - chrono::Duration::minutes(52); + let mut fixture = record(home.path(), 7, Some("merged"), 0); + fixture["started_at"] = json!((end - chrono::Duration::minutes(140)).to_rfc3339()); + fixture["ended_at"] = json!(end.to_rfc3339()); + write_record(home.path(), 7, &fixture); + let console = Console::start(Path::new(env!("CARGO_BIN_EXE_thirdshift")), home.path()); + let html = console.get("/").text().unwrap(); + assert!(html.contains("52 min ago"), "{html}"); + assert!( + html.contains(&format!(""), "{html}"); + assert!(!html.contains("2 hr 20 min"), "{html}"); +} + +#[test] +fn unavailable_finish_times_are_not_invented_from_other_observations() { + use super::write_record; + use serde_json::json; + + let home = tempfile::tempdir().unwrap(); + configure(home.path()); + for (number, outcome, end) in [ + (1, Some("merged"), Value::Null), + (2, Some("failed"), json!("not a timestamp")), + (3, None, Value::Null), + ] { + let mut fixture = record(home.path(), number, outcome, 0); + fixture["ended_at"] = end; + write_record(home.path(), number, &fixture); + } + let console = Console::start(Path::new(env!("CARGO_BIN_EXE_thirdshift")), home.path()); + for page in ["/", "/?page=history"] { + let html = console.get(page).text().unwrap(); + assert_eq!(html.matches("End time unknown").count(), 3, "{html}"); + assert!(!html.contains("