feat: wire belief propagation into handle_match() + GATE dispatch recipe#91
feat: wire belief propagation into handle_match() + GATE dispatch recipe#91cryptoxdog wants to merge 3 commits into
Conversation
engine/handlers.py — handle_match()
Injection point: after confidence checker + causal BFS, before response assembly.
Block: '--- Belief Propagation Re-ranking (ToTh §3) ---'
- Extracts dimension_keys from scoring_assembler.last_active_dimension_names
- Calls rescore_candidates(candidates_out, dimension_keys, prior_key='confidence', score_key='belief_score')
- Adds intelligence_quality to response dict:
method='entropy_penalized_composite', dimensions_used, prior_source='node.confidence'
- Guard: only runs if candidates_out non-empty AND dimension_keys non-empty
- No change to Pareto logic — belief_score is an additive field, not a replacement
docs/gate_dispatch_wiring.md
Wire-up recipe for gate/engine/dispatch.py (separate GATE node repo).
Position: after PacketEnvelope.parse_obj(), before packet store write.
Adds chain_confidence (propagate_chain), chain_quality (chain_composite),
hop_count to intelligence_quality via packet.derive() (immutable).
Includes trust tier table and output field reference.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
❌ Too Many Files Changed ❌ PR Too Large 📋 Best Practices for Large Changes
🚫 This PR is blocked from merging until size limits are met. |
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 11 minutes and 31 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (100)
📝 WalkthroughWalkthroughAdded documentation for GATE dispatch belief propagation scoring integration and modified the match handler to conditionally apply belief propagation re-ranking to candidates, including computation of trust metrics and updated intelligence quality metadata in the response. Changes
Sequence DiagramsequenceDiagram
participant Handler as Match Handler
participant Normalizer as Normalizer
participant Explainer as BFS Explainer
participant BPScorer as Belief Propagation Scorer
participant Response as Response Builder
Handler->>Normalizer: normalize candidates
Normalizer-->>Handler: normalized candidates
Handler->>Explainer: generate causal explanations
Explainer-->>Handler: explanation data
alt has_candidates && active_dimensions
Handler->>BPScorer: rescore_candidates(score_key="belief_score"<br/>prior_key="confidence")
BPScorer-->>Handler: re-ranked candidates with belief scores
end
Handler->>Handler: construct intelligence_quality metadata<br/>(method, dimensions, prior_source)
Handler->>Response: include intelligence_quality in response
Response-->>Handler: augmented response
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~22 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
engine/handlers.py (1)
601-605: Comment is misleading about execution order.The comment states "Position: after confidence checker + causal BFS, before Pareto" but in the current code flow, Pareto logic (lines 473-529) executes before this belief propagation block. The clarification "Pareto operates on belief_score-ranked list in the next iteration" is accurate but the initial positioning statement is confusing.
Consider revising to:
-# Position: after confidence checker + causal BFS, before Pareto (Pareto -# operates on belief_score-ranked list in the next iteration if enabled). +# Position: after confidence checker + causal BFS, following Pareto. +# (Pareto operates on belief_score-ranked list in subsequent iterations.)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@engine/handlers.py` around lines 601 - 605, Update the misleading comment in the Belief Propagation Re-ranking block: clarify that the Pareto logic (the Pareto section around the "Pareto" functions/logic) currently runs before the belief propagation re-ranking code rather than after it, and state that Pareto will operate on the belief_score-ranked list only in the next iteration; modify the comment in the Belief Propagation section (the block labeled "Belief Propagation Re-ranking (ToTh §3)") to reflect the actual execution order and remove the "Position: after confidence checker + causal BFS, before Pareto" phrasing, referencing the Pareto logic and belief propagation by name so readers can locate the relevant code.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@docs/gate_dispatch_wiring.md`:
- Around line 18-25: The example incorrectly references
packet_with_hop.header.timeout_ms (PacketEnvelope has no header and timeout_ms
isn't a packet field); update the hop_trusts comprehension so
hop_trust_from_entry receives a real timeout source—e.g., replace
packet_with_hop.header.timeout_ms with a timeout variable supplied by the caller
(like request_context.timeout_ms or a local timeout_ms) or with an existing
packet field if one exists (ensure the variable name you use is in scope);
adjust the example line accordingly and keep hop_trusts, hop_trust_from_entry,
response_packet.hop_trace and PacketEnvelope in mind when making the change.
In `@engine/handlers.py`:
- Around line 607-622: The import of rescore_candidates from
engine.scoring.belief_propagation will raise ImportError because that
module/function is missing; either implement a new module
engine/scoring/belief_propagation.py that defines
rescore_candidates(candidates_out: list, dimension_keys: list, prior_key: str,
score_key: str) and return the rescored candidates (ensure compatibility with
the callers in handlers.py and use prior_key/score_key to read/write node
properties), or guard the call in handlers.py by feature-flagging or catching
ImportError/NotImplementedError and log the deferral (e.g., reference
scoring_assembler.last_active_dimension_names and set/omit intelligence_quality
accordingly) and add a note to DEFERRED.md; ensure you reference
rescore_candidates and engine.scoring.belief_propagation so the runtime path is
resolved.
---
Nitpick comments:
In `@engine/handlers.py`:
- Around line 601-605: Update the misleading comment in the Belief Propagation
Re-ranking block: clarify that the Pareto logic (the Pareto section around the
"Pareto" functions/logic) currently runs before the belief propagation
re-ranking code rather than after it, and state that Pareto will operate on the
belief_score-ranked list only in the next iteration; modify the comment in the
Belief Propagation section (the block labeled "Belief Propagation Re-ranking
(ToTh §3)") to reflect the actual execution order and remove the "Position:
after confidence checker + causal BFS, before Pareto" phrasing, referencing the
Pareto logic and belief propagation by name so readers can locate the relevant
code.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 14987510-7ab3-403f-a8da-d5fbadc4394d
📒 Files selected for processing (2)
docs/gate_dispatch_wiring.mdengine/handlers.py
Resolve remaining terminology-guard offenders, eliminate contract-scanner false positives in sanitized causal Cypher builders, and bring ruff back to green with bounded mechanical edits. GMP: Phase 0-6 complete; Scope: shared-blockers remediation on fix/shared-blockers-all-prs; Blast radius: engine/tests/tools mechanical lint+contract fixes; Validation: python3 tools/contract_scanner.py=PASS, ruff check .=PASS, terminology grep=PASS; Note: .pre-commit-config.yaml present but pre-commit executable/module unavailable in this environment.
- carry forward shared-blocker cleanup onto PR #91 branch - add belief_propagation scorer module required by handlers import - clarify belief_score semantics as additive/new field alongside score - fix GATE docs to use PacketEnvelope.metadata references Verification: - python3 tools/contract_scanner.py ✅ - ruff check . ✅ - dynamic import/runtime tests not executed here because local environment is missing neo4j package required by engine import path GMP: Phase 0-4 complete; scoped PR91 remediation only; static verification green; runtime verification partially blocked by missing local dependency.
|




What
Wires the belief propagation module (PR #90) into the two live integration points.
engine/handlers.py — handle_match()
Injection point: after confidence checker + causal BFS, before
response = {...}assembly.belief_scoreis an additive field — does not replacescore. Pareto logic unchanged.intelligence_qualityadded to response dict.docs/gate_dispatch_wiring.md
Wire-up recipe for
gate/engine/dispatch.py(separate GATE node repo — can't push directly).Adds
chain_confidence,chain_quality,hop_counttointelligence_qualityviapacket.derive()after hop trace accumulation.Note
handlers.pyis a protected file per GUARDRAILS — requires your review before merge.Summary by CodeRabbit
New Features
Documentation