Fix: guard daemon never registers strategies, prunes 0 bytes#17
Open
conal wants to merge 4 commits intoRuya-AI:mainfrom
Open
Fix: guard daemon never registers strategies, prunes 0 bytes#17conal wants to merge 4 commits intoRuya-AI:mainfrom
conal wants to merge 4 commits intoRuya-AI:mainfrom
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Fix
One-line:
import cozempic.strategiesin 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)