Skip to content

Fix: guard daemon never registers strategies, prunes 0 bytes#17

Open
conal wants to merge 4 commits intoRuya-AI:mainfrom
conal:fix-guard-strategy-registration
Open

Fix: guard daemon never registers strategies, prunes 0 bytes#17
conal wants to merge 4 commits intoRuya-AI:mainfrom
conal:fix-guard-strategy-registration

Conversation

@conal
Copy link

@conal conal commented Mar 10, 2026

Summary

The guard daemon guard_prune_cycle calls run_prescription, which iterates over strategy names from PRESCRIPTIONS. But guard.py never imports the cozempic.strategies package, so the @strategy decorators never run and STRATEGIES stays empty. Every strategy name is silently skipped (if sname not in STRATEGIES: continue), and pruning removes 0 bytes.

cli.py has the import (line 25), which is why cozempic treat and cozempic diagnose work correctly. Only the guard/daemon code path is affected.

Reproduction

from cozempic.guard import guard_prune_cycle
from cozempic.registry import STRATEGIES
print(STRATEGIES)  # {} -- empty

Fix

One-line: import cozempic.strategies in guard.py.

Evidence

Before fix: run_prescription on a 2.7MB session returns 0 results, 0 bytes saved.
After fix: same session returns 7 strategy results, 370KB (13.4%) saved.

Related: #15 (guard prune cycle removes 0 bytes)

conal and others added 4 commits March 8, 2026 19:34
…rable

Guard now computes token thresholds automatically (75%/45% of context
window) when --threshold-tokens is not passed. Previously, token checking
was entirely skipped without explicit flags, so the guard only watched
file size (50MB default). Sessions with high token density but small
file size (e.g. meaning-rich conversations without build output) could
hit context limits long before file size thresholds.

Also makes SYSTEM_OVERHEAD_TOKENS configurable via --system-overhead-tokens
flag or COZEMPIC_SYSTEM_OVERHEAD_TOKENS env var. The default (21K) is
conservative; sessions with heavy rules files, MCP servers, and tool
schemas can have 30K-40K+ tokens of system overhead, causing the heuristic
to underestimate context usage.

Fixes Ruya-AI#8, fixes Ruya-AI#9.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When Claude Code restarts, start_guard_daemon now detects that the
existing guard is watching a stale session and replaces it. A companion
session file alongside the PID file tracks which session_id the guard
is monitoring. On session mismatch, the old guard is killed via SIGTERM
and a new one starts for the current session.

Fixes Ruya-AI#11

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
guard.py imports PRESCRIPTIONS and STRATEGIES from the registry but never
imports the strategies package that populates STRATEGIES via the @strategy
decorator. As a result, STRATEGIES is always empty when guard_prune_cycle
runs, every strategy name is silently skipped in run_prescription, and
pruning removes 0 bytes.

cli.py has the import (line 25: import cozempic.strategies), which is why
treat/diagnose work correctly. Only the guard daemon path was missing it.

Fix: add 'import cozempic.strategies' to guard.py.

Co-Authored-By: Claude Opus 4.6 <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