Skip to content

Every log.jsonl reader but one parses with jq -R -s splits, which costs ~80s on a real 2.3 MB log where inputs costs ~0.07s

Id: TD-PPagop-26082503 · Status: resolved · Filed: 2026-08-25 · Resolved: 2026-08-25 · Ref: #792

Noticed while reviewing PR #774 (issue #662), whose new stage_health_verdicts was written in the same idiom and has been changed to inputs on that branch. The idiom itself predates it and is still in four other readers.

Every reader of an event stream in this repository slurps the whole file into one string and splits it with a regex:

[ splits("\n") | select(length > 0) | (fromjson? // empty) ]

splits is oniguruma, run over the entire slurped document, and it is not linear in practice. Measured against this node’s own log.jsonl (2 309 600 bytes, 8 777 lines, jq 1.7):

parse wall
jq -R -s '[ splits("\n") | … ]' 83 s
jq -R -n '[ inputs | … ]' 0.07 s

Identical output; the difference is entirely the split. log.jsonl is never rotated (scripts/rotate-logs.sh keeps it whole as the fleet’s permanent record), so this cost grows for the life of a node, and the fleet union a few of these readers take as input is the sum of every node’s copy.

Call sites still on the slow spelling:

  • lib/crash-loop.sh:52 — crash_loop_verdict
  • lib/crash-loop.sh:127, lib/crash-loop.sh:174 — crash_loop_preselection_verdict and its companion
  • lib/review-gate.sh:377, lib/review-gate.sh:415
  • lib/escalation-autonomy.sh:68

lib/dependency-gate.sh:86 also uses splits("\n"), but over a short command output rather than a log, so it is not part of this.

crash_loop_verdict and crash_loop_preselection_verdict are the ones that matter most: agent-cycle.sh:6770 and agent-cycle.sh:6778 run both over $union_log inside the cycle’s own path, so today’s log sizes put a multi-minute parse on a cycle that is otherwise doing nothing.

Mechanical, one line per call site: jq -R -s '[ splits("\n") | … ]' becomes jq -R -n '[ inputs | … ]', with -s dropped and -n added. inputs under -R yields one string per line, so select(length > 0) and fromjson? // empty keep their existing meaning and torn-line tolerance is unchanged. Each reader has its own test file; the assertions should not need to move.

Worth doing as one pull request across all six so the idiom does not survive in half the tree and get copied again — which is how it reached #774.

References to remove when this is resolved

Section titled “References to remove when this is resolved”
  • The header comment in lib/stage-health.sh that cites this record as the reason it does not use the splits spelling.

Migrated to https://github.com/Poetic-Poems/agent-ops/issues/982.

The jq conversion this record describes landed in PR #792, closing the independently filed duplicate #791. The last live reference — the lib/stage-health.sh header comment named above — was removed in the pull request resolving agent-ops#982.