Skip to content

lib/fleet.sh: fleet_ts_field bails on a leading blank line, skipping its own jq fallback

Id: TD-PPagop-26090702 · Status: open · Filed: 2026-09-07

fleet_ts_field reads the file’s first line for its no-fork fast path and returns empty when that line is empty ([[ -n "$line" ]] || return 0) even though the [[ -s "$file" ]] guard already established the file has content — so a non-empty file whose first line is blank (a hand-edited heartbeat.json or .state-sync-published.json with a leading newline, or a future writer that emits one) never reaches the jq fallback and reads as ‘no ts’, which fleet_publication_status reports as unknown. This contradicts the function’s own header contract (‘correctness never depends on which shape a caller happens to hold’) and is the same class of gap PR #1176’s b826d06 fixed for the pretty-printed shape, one corner narrower. It is latent (every current writer is jq -nc, whose first byte is {) and it degrades in the conservative direction — the node shows stale/unknown, a visible false alarm, never false freshness — so it was not worth blocking #1176 over. Fix options: (a) drop the early return and fall through to the jq fallback whenever the fast-path prefix does not match, since the -s guard already excludes truly empty files and the fallback parses the whole file anyway; or (b) read the first non-empty line for the fast-path test. Either way, extend test/fleet-publication.test.sh’s shape cases with a leading-blank-line fixture.

Default: Drop the [[ -n "$line" ]] || return 0 early return so an unmatched fast path always falls through to the whole-file jq fallback — it is the smaller change and the fallback already owns every non-fast-path shape.

Section titled “Default: Drop the [[ -n "$line" ]] || return 0 early return so an unmatched fast path always falls through to the whole-file jq fallback — it is the smaller change and the fallback already owns every non-fast-path shape.”

Noticed while the Approver was judging https://github.com/Poetic-Poems/agent-ops/pull/1176.

Migrated to https://github.com/Pullwright/agent-ops/issues/2020.