mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 16:07:35 +01:00
Follow-up to the stale-Working defense (48fa2b6). Two related bugs:
1. ROOT CAUSE — agent-hook-lib.sh:write_inject_state used a naive printf
to interpolate $label and $key directly between JSON double quotes,
with zero escaping. Any user-supplied custom prompt containing
newlines, quotes, or backslashes broke the JSON so jq rejected it
in the daemon's parser. cpsat then fell back to "null", the
cleanup's outer guard skipped, and the file lingered indefinitely
leaking /tmp space (e.g. the AOZ sentinel from May 19 with a 1132-
byte multi-line prompt).
Fix: switch to `jq -Rs .` for both key and label — the same idiom
the daemon's execute_inject (cockpit-daemon.sh:258-262) already
uses. Newlines and quotes are now correctly escaped on every write.
2. LEGACY CLEANUP — even after fixing the writer, existing corrupted
files keep lingering since the parser still can't extract
startedAt. Added a belt-and-suspenders elif branch in the daemon
sweep: when the file exists but cpsat couldn't be parsed, fall
back to filesystem mtime; if older than 30 min, delete it. Files
that fail to parse never become live again, so a time-based sweep
is safe.
Both edits stay in scripts/agent-hook-lib.sh and scripts/cockpit-
daemon.sh — agent-hook-bridge.sh is untouched.