Day three: the loop leaves a trace
Описание и применение
Внедрена система логирования для каждой итерации агента, позволяющая сохранять результаты в уникальных файлах с временной меткой и обеспечивать надёжную обработку ошибок.
Задача
The agent loop ran but produced no visible output or error, and subsequent runs overwrote previous logs, making it impossible to review past executions.
Результат
All agent runs now leave a trace in timestamped JSON files, enabling review of status, cost, and debugging. The loop’s error handling is robust, and ticket lookup is accurate.
Рабочий процесс
- 1. Identify ticket file by name or heading using grep with fallback.
- 2. Neutralize pipefail with || true to allow error block execution.
- 3. Anchor grep to ^# US-XX to avoid false positives.
- 4. Execute agent loop and pipe output to Claude.
- 5. Tee output to a timestamped history file in history/
<TICKET_ID>_<timestamp>.json. - 6. Verify script with bash -n and isolated simulation.
- 7. Review history files for status, cost, and debugging information.
Доказательства
The loop had been running for two days, and that early morning, for the first time, there was no way to see it.
The fix added a second content-matching attempt — look for the # US-04 — ... heading inside the file when the name isn't enough — and neutralized pipefail with || true on both pipelines, so the existing error block would actually run when it should.
The implementation was a tee at the end of the pipeline: claude ... | tee "$HISTORY_FILE"
- Дата записи: 2026-09-20T02:00:26.287Z