Skip to content

weekly maintenance: acquire dream.lock to mutually-exclude nightly#30

Merged
stevepridemore merged 0 commit into
mainfrom
weekly-maintenance-lock
May 10, 2026
Merged

weekly maintenance: acquire dream.lock to mutually-exclude nightly#30
stevepridemore merged 0 commit into
mainfrom
weekly-maintenance-lock

Conversation

@stevepridemore
Copy link
Copy Markdown
Owner

Summary

Follow-up to #29. The new weekly maintenance task and the nightly dream both modify the graph but don't currently coordinate — they could in principle run concurrently, with race conditions between dream's `graph_relate` and weekly's `graph_prune execute` against the same nodes.

This PR makes the two routines mutually exclusive via the existing `~/graph-memory/processed/dream.lock` file (same one nightly already uses).

What changed

`prompts/weekly-maintenance.md`:

  • New Step 0: acquire the lock at the start of the run. Same JSON shape, same 2-hour stale threshold as nightly. `source` field set to `"scheduled-weekly"` to distinguish.
  • New Step 12: release the lock on every exit path (success, backup-failure abort, prune-sanity abort, any other failure).
  • Rules section updated to call out lock acquisition + release as mandatory invariants alongside backup and prune-sanity-check.

The live SKILL.md was regenerated via `scripts/sync-dream-skill.py --task weekly-graph-maintenance`. Next scheduled run (Sunday 6 AM) picks up the new content automatically — no re-registration needed.

Why now

The first manual run of the weekly task happened tonight without the lock. That was safe because no nightly was running at the time. But future scheduled overlap is possible (long-running dream colliding with the 6 AM weekly trigger, or another manual "Run now" during an active dream). The fix is small and closes a real correctness hazard.

Test plan

  • Sync script regenerates SKILL.md with the new sections at expected paths
  • Lock-file path correctly translated from `~/graph-memory/...` to `C:\Users\sprid\graph-memory...` in the live SKILL
  • First scheduled run on Sunday 6 AM — verify lock created at start, deleted at end, audit log shows the lock interactions

🤖 Generated with Claude Code

@stevepridemore stevepridemore merged this pull request into main May 10, 2026
2 checks passed
@stevepridemore stevepridemore deleted the weekly-maintenance-lock branch May 10, 2026 04:47
stevepridemore added a commit that referenced this pull request May 10, 2026
Both the nightly dream and the new weekly maintenance task modify the
graph. They should never run concurrently — concurrent graph_prune +
graph_relate against the same nodes is a real correctness hazard.

Adds Step 0 (acquire lock) and Step 12 (release lock) to the weekly
maintenance prompt. Uses the same lock file as the nightly dream
(~/graph-memory/processed/dream.lock) so the two routines mutually
exclude with shared semantics:

  - Same path, same JSON shape, same 2-hour stale threshold
  - source field distinguishes "scheduled-nightly" vs "scheduled-weekly"
  - Either side seeing a fresh lock from the other aborts immediately
  - Both sides MUST release on every exit path including aborts

Practical risk this closes: a long-running dream colliding with
weekly's prune-execute step, or a manual "Run now" of the weekly task
during an active dream. Likelihood is low for a single-user setup but
the fix is small and the failure mode (corrupted graph from concurrent
destructive ops) is severe.

Updated rules section to call out lock acquisition + release as
mandatory invariants alongside the existing backup and prune-sanity-
check invariants.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant