🎯 Goal
Make all write-side operations idempotent so reruns with the same inputs do not create duplicates or inconsistent state.
📍 Context
- Repo: autonomous-dev-loop
- Domain: Re-runnability
- Component:
scripts/lib/output_writer.mjs, scripts/manage_labels.mjs
🚀 Description
Idempotence is already partially applied in this repo but inconsistently:
upsert_issue_validation_comment.mjs — upserts by bot-marker ✅
auto_fix_pr.mjs label creation — tolerates HTTP 422 (existing label) ✅
output_writer.mjs — overwrites files unconditionally without checking expected state ❌
manage_labels.mjs — label operations need idempotence verification ❌
A re-run caused by a transient failure or manual retry must produce the same final state as the first run.
🧩 Scope
In:
scripts/lib/output_writer.mjs: before writing a file, check if its content is already identical; skip the write if so (use fs.readFile + strict equality).
scripts/manage_labels.mjs: verify each label operation is upsert-safe — add only if not already present, remove only if present; no-op otherwise.
- Define a run-context idempotency key composed of
{ issueNumber, commitSha, step } to scope write guards.
- Document the idempotency contract for each write operation (inline, one line per function).
Out:
- Workflow trigger strategy changes.
- Changes to read-only operations.
🧪 Acceptance criteria
⚙️ Constraints
- Preserve current business behavior — this is hardening only, no functional changes.
- The skip-write check must use strict byte-level equality, not semantic comparison.
- No new runtime dependencies.
🎯 Goal
Make all write-side operations idempotent so reruns with the same inputs do not create duplicates or inconsistent state.
📍 Context
scripts/lib/output_writer.mjs,scripts/manage_labels.mjs🚀 Description
Idempotence is already partially applied in this repo but inconsistently:
upsert_issue_validation_comment.mjs— upserts by bot-marker ✅auto_fix_pr.mjslabel creation — tolerates HTTP 422 (existing label) ✅output_writer.mjs— overwrites files unconditionally without checking expected state ❌manage_labels.mjs— label operations need idempotence verification ❌A re-run caused by a transient failure or manual retry must produce the same final state as the first run.
🧩 Scope
In:
scripts/lib/output_writer.mjs: before writing a file, check if its content is already identical; skip the write if so (usefs.readFile+ strict equality).scripts/manage_labels.mjs: verify each label operation is upsert-safe — add only if not already present, remove only if present; no-op otherwise.{ issueNumber, commitSha, step }to scope write guards.Out:
🧪 Acceptance criteria
Functional
output_writer.mjstwice with identical inputs produces exactly one file write on disk (second call is a no-op).manage_labels.mjstwice with the same label set leaves the PR/issue in the same label state (no duplicate add, no spurious remove).Edge cases
auto_fix_pr.mjs— extend same pattern).Tests
writeGeneratedFilestwice with the samechangesarray results infs.writeFilebeing called only once per file (second call skipped).manage_labelsadd operation with a label already present does not call the GitHub API a second time.⚙️ Constraints