Skip to content

Dedupe local signed log appends - #519

Merged
joelteply merged 1 commit into
canaryfrom
codex/dedupe-local-log-and-bash32-supervisor
May 5, 2026
Merged

joelteply merged 1 commit into
canaryfrom
codex/dedupe-local-log-and-bash32-supervisor

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Summary

  • add an idempotent signed-envelope append helper for local messages.jsonl
  • mirror own-client messages into the audit log while suppressing display echo
  • stop host send from racing the monitor mirror after gh/local-bus delivery
  • harden bearer supervisor empty-array assignments for macOS bash 3.2 + set -u

Validation

  • bash -n airc lib/airc_bash/cmd_send.sh lib/airc_bash/cmd_connect.sh lib/airc_bash/cmd_teardown.sh test/integration.sh
  • git diff --check
  • python3 test/test_monitor_formatter.py
  • ./airc doctor --tests python_units
  • real continuum scope: nohup background join stayed healthy >70s; marker delivered once (delta=1)

Not in this PR

  • startup serialization for two simultaneous stale-host takeovers. I tried a scope lock and rejected it after live testing because it still allowed competing host owners through the re-exec path. That needs a cleaner design, not a half patch.

Copilot AI review requested due to automatic review settings May 5, 2026 06:19
@joelteply
joelteply merged commit 67367f1 into canary May 5, 2026
8 checks passed
@joelteply
joelteply deleted the codex/dedupe-local-log-and-bash32-supervisor branch May 5, 2026 06:20

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

This PR introduces an idempotent “append signed envelope to local messages.jsonl” mechanism to prevent duplicate audit-log rows, and adjusts the monitor/send flows so own-client messages are recorded without being echoed back to the sender.

Changes:

  • Added airc_core.log_append.append_unique_sig() (with a small CLI wrapper) to dedupe appends by envelope signature.
  • Updated monitor_formatter to use the idempotent append helper and to mirror own-client messages into the audit log while suppressing display.
  • Updated cmd_send.sh and the multi-channel monitor supervisor to reduce duplicate local writes and harden bash 3.2 + set -u behavior.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
test/test_monitor_formatter.py Adds a unit test asserting own-client messages are mirrored but not displayed.
lib/airc_core/monitor_formatter.py Switches local mirroring to an idempotent append-by-sig helper and changes own-client filtering order.
lib/airc_core/log_append.py New module implementing lock + tail-scan based deduped appends (and a CLI entrypoint).
lib/airc_bash/cmd_send.sh Uses the deduped append helper for local audit writes and removes a host-side append that raced the monitor mirror.
airc Adjusts multi-channel monitor supervisor PID array assignments to be bash-3.2/set -u-safe.

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

Comment on lines +26 to +37
def _recent_sigs(path: str, limit: int = TAIL_LIMIT) -> set[str]:
try:
with open(path, encoding="utf-8", errors="replace") as f:
lines = f.readlines()[-limit:]
except (FileNotFoundError, OSError):
return set()
sigs: set[str] = set()
for raw in lines:
sig = _line_sig(raw)
if sig:
sigs.add(sig)
return sigs
Comment on lines +40 to +88
def _acquire_lock(path: str) -> str:
lock_path = f"{path}.lock"
deadline = time.time() + LOCK_WAIT_SEC
payload = f"{os.getpid()}\n".encode("ascii", errors="replace")
while True:
try:
fd = os.open(lock_path, os.O_CREAT | os.O_EXCL | os.O_WRONLY, 0o600)
try:
os.write(fd, payload)
finally:
os.close(fd)
return lock_path
except FileExistsError:
try:
age = time.time() - os.path.getmtime(lock_path)
if age > LOCK_STALE_SEC:
os.unlink(lock_path)
continue
except FileNotFoundError:
continue
except OSError:
pass
if time.time() >= deadline:
raise TimeoutError(f"timed out waiting for log lock: {lock_path}")
time.sleep(LOCK_SLEEP_SEC)


def append_unique_sig(path: str, line: str) -> str:
"""Append `line`, skipping if its JSON sig already exists in the log tail."""
parent = os.path.dirname(path)
if parent:
os.makedirs(parent, exist_ok=True)
framed = line if line.endswith("\n") else line + "\n"
sig = _line_sig(framed)
lock_path = _acquire_lock(path)
try:
if sig and sig in _recent_sigs(path):
return "skipped"
fd = os.open(path, os.O_WRONLY | os.O_CREAT | os.O_APPEND, 0o644)
try:
os.write(fd, framed.encode("utf-8"))
finally:
os.close(fd)
return "appended"
finally:
try:
os.unlink(lock_path)
except OSError:
pass
Comment thread lib/airc_bash/cmd_send.sh

_airc_append_local_signed() {
if ! printf '%s\n' "$1" | "$AIRC_PYTHON" -m airc_core.log_append append --path "$MESSAGES" >/dev/null; then
echo "$1" >> "$MESSAGES"
Comment thread airc
fi
done
_pids=("${_alive[@]}")
_pids=(${_alive[@]+"${_alive[@]}"})
Comment thread airc
_kept+=("$entry")
done
_pids=("${_kept[@]}")
_pids=(${_kept[@]+"${_kept[@]}"})
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