Skip to content

Scan resilience: model preflight, shared per-post path, crash-safe memory#16

Merged
jackparnell merged 1 commit into
TheColonyCC:masterfrom
arch-colony:feat/scan-resilience
Jun 30, 2026
Merged

Scan resilience: model preflight, shared per-post path, crash-safe memory#16
jackparnell merged 1 commit into
TheColonyCC:masterfrom
arch-colony:feat/scan-resilience

Conversation

@arch-colony

Copy link
Copy Markdown
Contributor

Three scan-mode resilience + maintainability improvements (follow-up to the timeout fix).

1. Crash-safe incremental memory

Scan mode saved colony_analyzed.json once, at the end of a run. A local-LLM scan can run for minutes, so a kill / reboot / OOM mid-run discarded every analysis since the last run — the next run then re-ran the model over all of them. cmd_scan now checkpoints every SCAN_SAVE_EVERY (10) newly-analyzed posts and again in a finally, so an interrupted scan keeps its finished work. Writes stay atomic.

2. Model-availability preflight

The startup check only confirmed the Ollama daemon was reachable. If the requested model wasn't pulled, every call_ollama returned None and the whole run silently no-op'd. ensure_model_available() now checks /api/tags and fails fast with ollama pull <model> — wired into both scan and webhook.

3. Extracted _process_post()

The single-post (--post-id) and bulk-scan branches duplicated the analyze → stamp → record → act pipeline. One shared helper removes drift risk and makes the per-post path unit-testable.

Tests

tests/test_scan_resilience.py (12 tests): preflight match/miss/daemon-down, _process_post success/dry-run/model-failure, the checkpoint cadence, and that a mid-scan crash still persists completed work. Full suite: 130 passing.

🤖 Generated with Claude Code

…mory

Three robustness/maintainability improvements to scan mode:

1. Crash-safe incremental memory (was: saved once at end of run). A local
   LLM scan can run for minutes; a kill / reboot / OOM mid-run discarded
   every analysis since the last run, so the next run re-burned the model
   over all of them. cmd_scan now checkpoints memory every SCAN_SAVE_EVERY
   (10) newly-analyzed posts AND in a finally, so an interrupted scan keeps
   its finished work. Writes are atomic (existing _atomic_json_write).

2. Model-availability preflight. The startup check only confirmed the
   Ollama daemon was reachable; if the requested model wasn't pulled, every
   call_ollama returned None and the whole run silently no-op'd with per-post
   errors. ensure_model_available() now checks /api/tags and fails fast with
   "ollama pull <model>" — wired into both scan and webhook entry points.

3. Extracted _process_post(). The single-post (--post-id) and bulk-scan
   branches duplicated the analyze -> stamp -> record -> act pipeline; one
   shared helper removes the drift risk and makes the per-post path unit-
   testable.

Pinned by tests/test_scan_resilience.py (12 tests): preflight match/miss/
daemon-down, _process_post success/dry-run/model-failure, and the
checkpoint cadence + that a mid-scan crash still persists completed work.
Full suite: 130 passing.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@jackparnell
jackparnell merged commit c25e590 into TheColonyCC:master Jun 30, 2026
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.

2 participants