feat: retain orchestrator + cluster-level injection#96
Merged
Conversation
- RetainOrchestrator: 3-phase event persistence adapted from Hindsight. Phase 1 (read): delta detection via dedup keys. Phase 2 (atomic): JSONL + SQLite write with crash recovery cursor. Phase 3 (best-effort): manifest update. 23 new tests. - Cluster-level injection: inject cluster summaries instead of individual rules when cluster has confidence >= 0.75, size >= 3, no contradictions. Saves injection slots (10 → fewer items, more semantic density). 7 new tests. 2871 tests passing (+30 new). Co-Authored-By: Gradata <noreply@gradata.ai>
There was a problem hiding this comment.
Gradata has reached the 50-review limit for trial accounts. To continue receiving code reviews, upgrade your plan.
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 Walkthrough
WalkthroughIntroduces Changes
Sequence DiagramssequenceDiagram
participant Client
participant Orchestrator as RetainOrchestrator
participant FileSystem
participant Database
participant Manifest
Client->>Orchestrator: queue(event)
Orchestrator->>Orchestrator: Accumulate in pending queue
Client->>Orchestrator: flush()
activate Orchestrator
rect rgba(100, 149, 237, 0.5)
Note over Orchestrator, FileSystem: Phase 1: Read Existing
Orchestrator->>FileSystem: Load events.jsonl (best-effort)
Orchestrator->>FileSystem: Load .event_cursor.json
Orchestrator->>Orchestrator: Compute existing_keys<br/>(dedup from ts|type|source)
Orchestrator->>Orchestrator: Identify new events
end
rect rgba(60, 179, 113, 0.5)
Note over Orchestrator, Database: Phase 2: Write & Persist
Orchestrator->>FileSystem: Append new events to events.jsonl
Orchestrator->>Database: Ensure events table
loop For each event
Orchestrator->>Database: INSERT OR IGNORE
end
Orchestrator->>FileSystem: Save cursor (last_committed_key)
end
rect rgba(184, 134, 11, 0.5)
Note over Orchestrator, Manifest: Phase 3: Post-Write (best-effort)
Orchestrator->>Manifest: update_manifest(brain_dir)
end
Orchestrator->>Client: Return {written, errors, phases}
deactivate Orchestrator
sequenceDiagram
participant Hook
participant Lessons as Lesson Parser
participant Clustering
participant Filter as Rule Filter
participant Output
Hook->>Lessons: parse_lessons(data)
Lessons->>Hook: Return lesson list
alt Clustering available
Hook->>Clustering: cluster_rules(filtered_lessons,<br/>min_cluster_size=3)
Clustering->>Clustering: Form clusters by category
rect rgba(60, 179, 113, 0.5)
Note over Clustering: Per-Cluster Decision
alt confidence >= 0.75 AND<br/>not contradictions
Clustering->>Output: Emit [CLUSTER:...|N rules]
else Low confidence OR contradictions
Clustering->>Filter: Pass to individual rules
end
end
else Clustering unavailable
Hook->>Filter: Proceed with all lessons
end
Filter->>Filter: Build individual [RULE:]/[PATTERN:] lines<br/>for non-clustered rules
Filter->>Output: Append individual lines
Output->>Hook: Return combined lines
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
This was referenced Apr 17, 2026
This was referenced Apr 17, 2026
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
Test plan
Generated with Gradata