fix: Greptile findings — ctx gap, print→logging, future imports#2
Merged
fix: Greptile findings — ctx gap, print→logging, future imports#2
Conversation
…orts 1. Multi-brain ctx gap: supersede(), correction_rate(), compute_leading_indicators(), audit_trend() now accept ctx param (was hardcoded to global DB_PATH) 2. print()→logging: 8 sites across _events.py, rule_tracker.py, mcp_server.py, _embed.py 3. from __future__ import annotations: added to 6 missing files Co-Authored-By: Gradata <noreply@gradata.ai>
1. Forward ctx to emit() and _detect_session() in supersede() 2. Remove 3 stale import sys in rule_tracker.py 3. Module-level _log in mcp_server.py (consistent with _events.py) Co-Authored-By: Gradata <noreply@gradata.ai>
Gradata
added a commit
that referenced
this pull request
May 1, 2026
* council-phase-c: lean-out plan extracted from claude-opus audit (overnight) Source: claude --print --model claude-opus-4-7 ran the lean-out audit 2026-04-30 02:00-02:12. Agent prepared the plan but couldn't Write the file directly (permission gate). Plan extracted from stdout. Headlines: - Baseline: SDK 68,717 LOC / 249 files. Target: 43,861 (-36%) - Scoring: keep _confidence.py (FSRS/Bayesian); pragmatist disagrees, prefers Beta - Modules: only 1 of 3 'duplicate pairs' is real (inspection.py) - Correction APIs: correct() canonical; rest private/renamed - Cloud: REMOVE _cloud_sync.py, MOVE cloud/* to extra - MCP/daemon/contrib/adapters/mining/sidecar/22 hooks → extras Architect (90 days) vs Pragmatist (60 days) disagreement flagged. Wildcard lens failed (deepseek 500); 6 of 7 voices in synthesis. Full council #2 launch report at ~/.hermes/council_reports/council_2026-04-30T02-02-45.md. * council-phase-c: VERIFIED_LEANOUT.md downgrades unsafe deletions Per-candidate verification using rg/search across ~/.claude/, SpritesWork/, ~/.hermes/, and Gradata's own src+tests. Findings invalidate several 'DELETE' recommendations from LEANOUT_PLAN: - _cloud_sync.py: NOT dead. Imported by tests, doctor, migrations, hooks. Move to [cloud] extra, do not delete. - scoring/memory_extraction.py: NOT 'broken import'. Has dedicated test + brain.py reference. Audit before deletion. - daemon.py: KEEP as extra. Phase B just wired BrainLockedError into it. - hooks/implicit_feedback.py: KEEP. Phase B just hardened it. - correction_detector privatize: DEPRECATE-rename across releases, not immediate. Confirmed safe to delete: graduation/scoring.py (0 imports verified). Confirmed safe rename: events_bus.py, _config.py (deprecation alias needed). Live Brain snapshot at ~/.hermes/brain-snapshot-20260430-0845/critical/. Phase B (242c408) is independently mergeable. * council-phase-c: VERIFIED_LEANOUT updated — pragmatist 0-for-3 on deletes, Phase B 3970/3970 pytest pass Pragmatist's DELETE list (notifications/onboard/safety) verified UNSAFE: - notifications.py: PUBLIC API (__init__.py exports Notification), Brain.subscribe() - onboard.py: Brain.init() canonical bootstrap (README headline) - safety.py: PII redaction used by _core.py Phase B test sweep: 3970 passed, 0 failed, 4:34 wall. Phase B branch is provably non-regressive — safe to push. * council-phase-c: 0/14 deletion candidates safe — graduation/scoring delete failed (test_graduation_scoring imports it) Lesson: '0 production import sites' != 'safe to delete'. Test coverage counts. Opt-in features with dedicated test files = real surface area. After full verification pass, NONE of the 14 LEANOUT_PLAN deletions should ship without first migrating their tests + verifying again. --------- Co-authored-by: oliver <oliver@spritesai.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
Greptile Review Findings Addressed
Test plan
Generated with Gradata
Greptile Summary
This PR correctly addresses three categories of issues identified in a prior review: multi-brain path isolation in
_events.py,print()→loggingmigration across four files, andfrom __future__ import annotationsadditions to six SDK files.supersede(),correction_rate(),compute_leading_indicators(), andaudit_trend()now acceptctx: BrainContext | Noneand resolvedb_pathvia the context when provided, falling back to_p.DB_PATHfor backward compatibility. This correctly closes the multi-brain isolation gap.print(..., file=sys.stderr)calls are replaced with structuredloggingcalls. The migration is functionally correct; minor inconsistencies remain in_embed.py(inlinegetLoggervs. module-level_log) andmcp_server.py(_logassignment between import blocks).tests/test_enhancements.pywas widened to accept two labels with a vague Python-version justification that warrants clarification.Confidence Score: 4/5
PR is safe to merge; all core fixes are correct with only minor style clean-ups remaining
The ctx propagation fix is correct and complete across all four affected functions, closing the multi-brain isolation gap. Logging migration and future-import additions are low-risk and well-executed. Score is 4 rather than 5 due to two minor PEP 8 inconsistencies (inline logger in _embed.py, _log assignment between imports in mcp_server.py) and one test assertion that accepts two possible labels with an unverified Python-version justification — none of these affect runtime correctness.
src/gradata/_embed.py (inline logger pattern), src/gradata/mcp_server.py (import ordering), tests/test_enhancements.py (widened assertion justification)
Important Files Changed
Sequence Diagram
sequenceDiagram participant Caller participant Brain participant BrainContext participant _events participant SQLite Caller->>Brain: supersede(event_id) Brain->>BrainContext: from_brain_dir(brain_dir) BrainContext-->>Brain: ctx Brain->>_events: supersede(event_id, ctx=ctx) _events->>_events: db = ctx.db_path if ctx else _p.DB_PATH _events->>SQLite: connect(db) SQLite-->>_events: conn _events->>_events: _detect_session(ctx=ctx) _events->>_events: emit(..., ctx=ctx) _events-->>Caller: replacement event dictComments Outside Diff (1)
src/gradata/_events.py, line 215-219 (link)ctxnot forwarded toemit()or_detect_session()The
supersede()function correctly resolvesdbfromctx, but then calls_detect_session()andemit()without passingctx. In a multi-brain scenario this causes the replacement event to be written to the default brain's DB (not the target brain), defeating the entire purpose of thectxfix introduced in this PR.Rule Used: # Code Review Rules
Rule 1: Never use print() ... (source)
Prompt To Fix With AI
Prompt To Fix All With AI
Greploops — Automatically fix all review issues by running
/greploopsin Claude Code. It iterates: fix, push, re-review, repeat until 5/5 confidence.Use the Greptile plugin for Claude Code to query reviews, search comments, and manage custom context directly from your terminal.
Reviews (2): Last reviewed commit: "fix: suppress Pyright error on optional ..." | Re-trigger Greptile
Context used:
Rule 1: Never use print() ... (source)