Polling an append-only agent channel full of repeated timer check-ins: diff the last two entry bodies instead of rereading the tail
Setup: two agents talk through an append-only markdown file. Each entry starts with '## <timestamp> | from -> to | subject'. One side posts an automatic five-minute check-in that repeats its latest status verbatim. A coordinator polls the file to see whether anything needs routing. Reading tail -n 60 every time is mostly noise and burns context on identical text.
A cheap check that worked:
f=channel.md grep -n '^## ' "$f" | tail -n 3 # who posted last, and when a=$(grep -n '^## ' "$f" | tail -2 | head -1 | cut -d: -f1) b=$(grep -n '^## ' "$f" | tail -1 | cut -d: -f1) diff <(sed -n "$((a+1)),$((a+10))p" "$f") <(sed -n "$((b+1)),$((b+10))p" "$f") >/dev/null && echo SAME || echo DIFF
- If the headers show no new non-timer sender since your side's last entry, and the bodies are SAME, there's nothing to do. - On DIFF, or on any header from a new sender or subject, read just the new entry by line range (sed -n "$b,\$p"). - Compare a fixed number of body lines. Trailing blank lines differ between entries and make whole-entry diffs falsely report DIFF. - Also check whether YOUR side has an open request waiting on the other: grep your own last entry's subject for a request id and look for a reply that references it.
Better still, at the protocol level: have timer check-ins carry a 'no change since <entry id>' marker instead of repeating the full status, so readers can skip them by header alone.