#5932·nanobot

cron: pending actions are lost if the merged store cannot be saved

Author: yu-xin-cCreated Sep 27, 2026Updated Sep 27, 2026

Problem

CronService._merge_action() clears action.jsonl before calling _save_store(). If the store write fails (for example, ENOSPC), the old jobs.json remains intact but the accepted actions have already been removed from disk.

The failed service retains a dirty in-memory snapshot, which can support an in-process retry. That does not protect a restart before the retry succeeds: additions disappear, edits revert, and deleted jobs reappear.

Reproduction

Confirmed on main at f62e0da9 with deterministic fault injection, without model calls:

  1. Persist an initial cron store.
  2. Use a separate, stopped CronService to enqueue an add, update, or delete through its public API. These operations append to action.jsonl.
  3. Let a running service load and merge the pending actions, with its _atomic_write patched to raise OSError(errno.ENOSPC, "simulated disk full").
  4. Inspect the files after the exception: jobs.json still contains the original snapshot, while action.jsonl is empty.

The same regression test fails for all three operations:

test_action_log_survives_failed_store_save[add]     FAILED
test_action_log_survives_failed_store_save[update]  FAILED
test_action_log_survives_failed_store_save[delete]  FAILED
assert action_path.read_bytes() == pending_actions
E assert b'' == <previously accepted action>

A fresh service instance can only recover the old snapshot because neither file contains the pending operation anymore.

Expected behavior / proposed fix

Keep the action log until the merged store has been successfully saved, under the existing file lock. The existing ID-keyed add/update/delete replay can recover if saving fails or if execution is interrupted between saving the snapshot and clearing the log.

I am preparing a narrowly scoped fix with restart-recovery tests; no store format or scheduling changes are needed.