Skip to content

Weekly graph maintenance: backup → analyze → prune → report#29

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

Weekly graph maintenance: backup → analyze → prune → report#29
stevepridemore merged 0 commit into
mainfrom
weekly-maintenance-routine

Conversation

@stevepridemore
Copy link
Copy Markdown
Owner

Summary

Adds a weekly scheduled task that runs every Sunday at 6 AM local time. The task does three things in sequence — backup, health analysis, and pruning — with safety gates between each.

This fills a real gap: the project has been running the nightly dream for weeks but no graph backups have actually been happening since 2026-05-06. A folder existed at `~/.claude/scheduled-tasks/weekly-graph-backup/` but was never registered as a routine in Claude Code's scheduled-tasks system, so it sat dormant. Same fate as `prompts/dream-weekly.md` (analysis prompt that's been in the repo since bootstrap, never scheduled).

This PR consolidates both into one weekly task with prune wrapped in.

What's in the PR

  • `prompts/weekly-maintenance.md` (new) — source-controlled prompt with 11 steps:
    1. Backup (graph_export with `label: weekly-pre-maintenance`, retention 14)
    2. Graph health overview (graph_stats)
    3. Unresolved contradictions (graph_contradictions, surfaced for human review)
    4. Stale entities (graph_cypher; confidence < 0.2 + last_seen > 90 days)
    5. Orphaned nodes
    6. Weak clusters (max edge weight < 0.3)
    7. Potential duplicates (graph_merge_suggestions, surfaced for human review)
    8. Dream process health (manifest + audit log)
    9. Prune preview with sanity check (abort if >50 nodes flagged)
    10. Prune execute (only if preview is sane)
    11. Report — append summary to `weekly-maintenance.log` + write detailed markdown to `weekly-reports/YYYY-MM-DD.md`
  • `scripts/sync-dream-skill.py` (extended) — refactored from one-task to N-tasks via a `TASKS` table. New `--task ` flag syncs only one; without flag, syncs all. Same CRLF→LF discipline preserved (SKILL.md parser breaks on CRLF).

Safety design

  • Backup gate: if step 1 fails, every subsequent step is skipped. Prune does not run without a fresh backup as recovery option.
  • Prune sanity check: if `graph_prune` preview shows more than 50 nodes to delete, the task aborts and logs a warning. A sudden large count usually signals a config change or bug, not legitimate cleanup.
  • No auto-resolve, no auto-merge: contradictions and duplicate candidates are reported for human review. The task is decisive only about decay-driven pruning, which is the boring/safe case.

Schedule

Registered via the scheduled-tasks MCP (`create_scheduled_task`):

```
taskId: weekly-graph-maintenance
cronExpression: 0 6 * * 0 (Sunday 6:00 AM, local time)
nextRunAt: 2026-05-10T10:00:05Z (= Sunday 6:00 AM ET)
```

Schedule registration is local Claude Code state per machine — not in source control. The prompt body that runs IS in source control via this PR.

Cleanup

Deleted local stale `~/.claude/scheduled-tasks/weekly-graph-backup/` folder. The new task ID (`weekly-graph-maintenance`) replaces the never-registered `weekly-graph-backup` name and reflects the broader scope.

Test plan

  • `python scripts/sync-dream-skill.py` syncs both nightly and weekly cleanly
  • `mcp__scheduled-tasks__list_scheduled_tasks` confirms the new task is registered with the right cron
  • First scheduled run on Sunday 6 AM — verify backup_file produced, prune executes (or correctly skips), and the report file lands at the expected path
  • Verify `graph_prune` tool is pre-approved on the task so the run doesn't pause waiting for permission

🤖 Generated with Claude Code

@stevepridemore stevepridemore merged this pull request into main May 10, 2026
2 checks passed
@stevepridemore stevepridemore deleted the weekly-maintenance-routine branch May 10, 2026 04:37
stevepridemore added a commit that referenced this pull request May 10, 2026
Adds prompts/weekly-maintenance.md as the source-controlled prompt for
a new weekly scheduled task. Combines three bodies of work that were
each partially in place:

- The graph_export backup (previously in a dormant ~/.claude/scheduled-
  tasks/weekly-graph-backup/SKILL.md folder that was never registered
  as a scheduled task)
- The dream-weekly.md health analysis (in the repo since the early
  bootstrap, never scheduled)
- A new graph_prune step (no prior implementation)

The shape: backup → analyze → prune → report, with safety gates:
1. Backup MUST succeed before any subsequent step runs (prune-with-no-
   backup is the failure mode the design avoids).
2. Prune sanity check: if preview shows >50 nodes to remove, abort and
   log a warning rather than executing. A sudden large prune count
   usually indicates a config change or bug, not legitimate cleanup.
3. Contradictions and duplicates are surfaced for human review only —
   never auto-resolved or auto-merged.

scripts/sync-dream-skill.py extended to handle multiple tasks via a
TASKS table. New --task flag syncs only one; without it, syncs all.
Keeps the existing CRLF→LF discipline for SKILL.md parser compatibility.

The scheduled task itself is registered separately via the scheduled-
tasks MCP create_scheduled_task call (not source-controlled — that's
local Claude Code state per machine). Cron: "0 6 * * 0" — Sunday 6 AM
local time. Next run ~5 hours from this commit.

Stale ~/.claude/scheduled-tasks/weekly-graph-backup/ folder removed
locally as part of this change. The new task ID is weekly-graph-
maintenance, replacing the never-registered weekly-graph-backup name.

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