Skip to content

fix(monitor): empty/zero offset file → tail from EOF (continuum-b741's history dump) - #230

Merged
joelteply merged 1 commit into
canaryfrom
fix/joiner-tail-from-now-not-history
Apr 28, 2026
Merged

joelteply merged 1 commit into
canaryfrom
fix/joiner-tail-from-now-not-history

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Empty or '0'-content monitor_offset made tail compute '-n +1' = print whole file. Joiners saw days of replayed history on connect. Fix: treat empty/zero/non-numeric as 'no usable offset' → -n 0.

Verification: tabs 19/0.

Bug: a present-but-empty (or "0"-content) `.airc/monitor_offset` made
the joiner's SSH tail compute `-n +1` = "from line 1 forward" = print
the host's ENTIRE messages.jsonl. Joiners saw days of historical
chat dumped on connect.

Reproduced by continuum-b741 2026-04-28 during Phase 1+2 e2e: their
monitor showed messages from authenticator-fd63 dated 2026-04-25
right after they joined the mesh.

## Fix

airc top-level (the joiner's tail-startup block before the SSH retry
loop): treat empty / zero / non-numeric saved offsets as "no usable
offset" — keep `-n 0` (current EOF). Only use the saved value when
it's a meaningful positive integer.

Defaults to `-n 0` first; only overrides when a positive int is read
from the file. case-statement with explicit empty / 0 / non-numeric
patterns means a corrupt offset file degrades safely instead of
replaying.

## Verification

  test/integration.sh tabs: 19/0 ✓

  The bug is observation-time (full history visible), not behavior-
  time (no incorrect state mutation), so the integration suite
  doesn't catch it directly. Manual: starting `airc connect` against
  a host with thousands of historical messages now shows EOF only.

## Related

  Phase 2C will also need to clear monitor_offset on host change
  (the offset is per-host but the file is per-scope; line N of host
  A is meaningless on host B). Out of scope for this fix.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings April 28, 2026 19:02
@joelteply
joelteply merged commit 8943a99 into canary Apr 28, 2026
@joelteply
joelteply deleted the fix/joiner-tail-from-now-not-history branch April 28, 2026 19:02

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes airc monitor tailing behavior when monitor_offset is empty/zero/non-numeric so joiners don’t replay the entire history on connect.

Changes:

  • Initialize tail start position to default to EOF (-n 0) and only resume from a saved offset when it’s a meaningful positive integer.
  • Add inline documentation explaining the bug scenario (empty/zero offset expanding to tail -n +1) and the intended behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread airc
Comment on lines +1175 to +1183
local tail_pos="-n 0"
if [ -f "$offset_file" ]; then
tail_pos="-n +$(($(cat "$offset_file" 2>/dev/null || echo 0) + 1))"
else
tail_pos="-n 0"
local _saved_offset; _saved_offset=$(cat "$offset_file" 2>/dev/null | tr -d '[:space:]')
case "$_saved_offset" in
''|0|*[!0-9]*) ;; # empty / zero / non-numeric → keep -n 0
*)
tail_pos="-n +$((_saved_offset + 1))"
;;
esac

Copilot AI Apr 28, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The safe offset parsing here is only applied for the initial tail_pos. On reconnects, the code later resets tail_pos using the old tail_pos="-n +$(($(cat "$offset_file" ...)+1))" logic (in both joiner and host loops). If the offset file is empty/"0" (e.g., quiet channel so the formatter never writes an updated offset, or a truncate during write), the next reconnect will still expand to tail -n +1 and replay the full history. Please reuse this same “meaningful positive integer” check when recomputing tail_pos after each loop iteration (ideally factor into a helper).

Copilot uses AI. Check for mistakes.
joelteply added a commit that referenced this pull request Apr 28, 2026
…ndows e2e) (#245)

Found by continuum-b69f (Windows tab) during the issue #244 test plan
2026-04-28: their messages were sent OK and reached the mesh host's
log, but my monitor (Mac) didn't display them.

Root cause: my saved monitor_offset = 128, host's current messages.jsonl
= 84 lines (truncated/reset since my last session — most likely from
teardown --flush or daemon respawn). My SSH-tail used `-n +118` which
BLOCKS waiting for line 118 to appear; meanwhile lines 70-84 (where
continuum-b69f's writes landed) were below my offset and silently
invisible.

This was a regression of #230's class — empty/zero offset was caught,
but stale-offset-past-EOF wasn't.

## Fix

cmd_connect joiner branch, after SSH config but before the reconnect
loop: if we have a saved offset that's > 0, query the host's current
log length via `ssh ... wc -l < messages.jsonl`. If saved offset >
host lines, the offset is stale (host log was reset since we last
ran). Clear the offset file + reset tail_pos to -n 0 (EOF). Print a
loud warning so the user knows we lost some history (matches
never-swallow-errors).

Single extra SSH round-trip on the FIRST cycle only (subsequent
reconnects use the formatter-persisted offset which is now consistent
with the live log).

## Verification

  bash -n: clean
  test/integration.sh tabs: 19/0 ✓

  Manual e2e: pending Mac monitor restart on this code +
  cross-machine verification with continuum-b69f's next probe.

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
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.

2 participants