Skip to content

fix(OMN-12489): read delegation projection from analytics DB - #1011

Merged
jonahgabriel merged 2 commits into
devfrom
jonah/omn-12489-projection-api-analytics-dsn
Jun 1, 2026
Merged

jonahgabriel merged 2 commits into
devfrom
jonah/omn-12489-projection-api-analytics-dsn

Conversation

@jonahgabriel

@jonahgabriel jonahgabriel commented May 31, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • make projection API prefer OMNIDASH_ANALYTICS_DB_URL for materialized projection reads
  • keep OMNIBASE_INFRA_DB_URL as fallback for compatibility
  • make delegation inference contract use payload_type_match and put inference-response first for fallback routing

Runtime evidence

  • 13002 before repair: data_freshness=degraded, latest_event_at=2026-05-13T14:53:08.924137+00:00, row_count=40
  • 13002 after live stability repair/backfill: data_freshness=fresh, latest_event_at=2026-05-31T22:34:20+00:00, row_count=36
  • top row: e1347df1-22ec-4e90-b15c-3f340e0cffd4, model Qwen3.6-35B-A3B

Verification

  • uv run pytest tests/test_projection_api_server.py::TestPostgresDsn tests/unit/delegation/test_handler_routing_intent.py -q
  • git diff --check

Summary by CodeRabbit

  • Configuration Updates

    • Reordered event-publish topics to prioritize inference responses.
    • Switched handler routing to payload-type matching for more accurate dispatch.
  • Infrastructure Improvements

    • DB selection now prefers the analytics DB if available, falling back to the infra DB otherwise.
  • Bug Fixes

    • Added stricter validation for declared event topics to fail fast on misconfiguration.
  • Tests

    • Updated unit and integration tests to reflect the routing, topic-resolution, and DB-selection behavior.

Ticket: OMN-12489
Evidence-Ticket: OMN-12489
Evidence-Source: OCC#2022

@coderabbitai

coderabbitai Bot commented May 31, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@jonahgabriel, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 37 minutes and 28 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ed4c6f91-cbbb-400b-9dbd-5388b3d7c5ff

📥 Commits

Reviewing files that changed from the base of the PR and between 309919c and 8fed1c9.

📒 Files selected for processing (2)
  • src/omnimarket/nodes/node_llm_delegation_call_effect/handlers/handler_llm_delegation_call.py
  • tests/unit/nodes/node_llm_delegation_call_effect/test_handler_llm_delegation_call.py
📝 Walkthrough

Walkthrough

This PR reorders published topics and switches handler routing to payload-type matching, replaces index-based topic constants with suffix-resolved lookups (and tests), and makes the projection API server prefer the analytics DB URL with a fallback to the contract DB.

Changes

Handler Routing and Event Configuration

Layer / File(s) Summary
Event routing and handler dispatch strategy
src/omnimarket/nodes/node_llm_delegation_call_effect/contract.yaml
Reordered event_bus.publish_topics to list the inference-response topic (onex.evt.omnibase-infra.inference-response.v1) first. Changed handler_routing.routing_strategy from "operation_match" to "payload_type_match".
Suffix-based topic resolution and tests
src/omnimarket/nodes/node_llm_delegation_call_effect/handlers/handler_llm_delegation_call.py, tests/unit/nodes/node_llm_delegation_call_effect/test_handler_llm_delegation_call.py
Replaced index-based TOPIC_DELEGATION_* assignments with _single_contract_topic(...) suffix-resolution (exactly-one-match enforced). Added/updated tests to assert published contract topics and resolved constants (including MODEL_DEGRADED).

Analytics Database URL Selection

Layer / File(s) Summary
DSN selection with analytics preference and tests
src/omnimarket/projection/api_server.py, tests/test_projection_api_server.py
Updated _dsn() to read OMNIDASH_ANALYTICS_DB_URL first with fallback to OMNIBASE_INFRA_DB_URL; updated RuntimeError message and tests to validate missing env vars, analytics preference, and fallback behavior.

🎯 3 (Moderate) | ⏱️ ~20 minutes

🐰 I nibble contracts, tweak the route,
Topics leap forward, handlers resolute,
Analytics first, then contract's embrace,
Tests cheer on every suffix in place. 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately captures the primary change: updating the projection API to prefer the analytics database while maintaining compatibility. The changes across all files align with this objective.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch jonah/omn-12489-projection-api-analytics-dsn

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
github-actions Bot enabled auto-merge May 31, 2026 22:40
@github-actions

github-actions Bot commented May 31, 2026 •

Copy link
Copy Markdown

✅ Architectural Review — PASSED

Errors: 0
Warnings: 0

What this checks

Rule Description
ARCH-TOPIC-001 No hardcoded Kafka topic strings in handler code
ARCH-DI-001 No event_bus=None bypass
ARCH-DI-002 No direct Handler instantiation outside workflow_runner/adapters
ARCH-DI-003 No reinvented DI containers
ARCH-TOPIC-002 contract.yaml topics follow `onex.{cmd

No architectural violations found.

Powered by node_pr_review_bot

@github-actions

github-actions Bot commented May 31, 2026 •

Copy link
Copy Markdown

✅ PR Review Bot — CLEAN

Findings: 0
Run ID: ``

Note: Reviewer models are running as stubs (OMN-7969–OMN-7972 pending). Architectural findings from Phase 1 (arch-lint) are the authoritative signal until model handlers land.


Verdict semantics

Verdict Meaning
clean No blocking findings
risks_noted Findings noted; threads passed verification
blocking_issue MAJOR/CRITICAL findings not resolved — do not merge

Powered by node_pr_review_bot — FSM pipeline with multi-model review fan-out

@github-actions

github-actions Bot commented May 31, 2026 •

Copy link
Copy Markdown

⚠️ Hostile Reviewer — DEGRADED (informational)

Blocking findings (critical/error): 0
Total findings: 0
Models succeeded: none

Note: All reviewer models failed or were unavailable. Degraded results are informational during the pilot phase (OMN-8524) and do not block merge. Error: cli_review exited non-zero (all models failed or binary error)


Gate semantics (pilot phase)

Verdict Meaning Blocks merge?
passed No critical/error findings No
blocked CRITICAL or ERROR findings found Yes
degraded All models unavailable (infra) No (pilot)

Powered by omniintelligence.review_pairing.cli_review — node-based adversarial review via HandlerLlmCliSubprocess (OMN-8524)

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/omnimarket/nodes/node_llm_delegation_call_effect/contract.yaml`:
- Around line 96-101: The publish_topics order in contract.yaml no longer
matches the positional mapping used in HandlerLlmDelegationCall; update the
handler (HandlerLlmDelegationCall in
src/omnimarket/nodes/node_llm_delegation_call_effect/handlers/handler_llm_delegation_call.py)
to resolve topics by name instead of relying on _publish[0..3]: read the
publish_topics array from the node contract/metadata and look up each required
topic string (the values corresponding to TOPIC_DELEGATION_CALL_COMPLETED,
TOPIC_DELEGATION_CALL_ESCALATION_TRIGGERED, TOPIC_DELEGATION_ALL_TIERS_FAILED,
TOPIC_DELEGATION_MODEL_DEGRADED) by matching their topic names, assign them into
the handler's publish mapping by key, and use those named entries everywhere
instead of using fixed numeric indices; alternatively, revert contract.yaml to
the original ordering so _publish[0..3] remain correct.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: e77c24c0-9fb1-4bc8-80fa-446e78b3b78d

📥 Commits

Reviewing files that changed from the base of the PR and between 8af3d9d and 31df90f.

📒 Files selected for processing (3)
  • src/omnimarket/nodes/node_llm_delegation_call_effect/contract.yaml
  • src/omnimarket/projection/api_server.py
  • tests/test_projection_api_server.py

Comment thread src/omnimarket/nodes/node_llm_delegation_call_effect/contract.yaml

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/unit/nodes/node_llm_delegation_call_effect/test_handler_llm_delegation_call.py (1)

124-131: 💤 Low value

These assertions are tautological — they restate the resolution invariant.

Each TOPIC_DELEGATION_* constant is produced by _single_contract_topic(..., suffix), which returns a value that already satisfies endswith(suffix). So assert TOPIC_DELEGATION_CALL_COMPLETED.endswith("delegation-call-completed.v1") can never fail unless the module already raised at import. The only assertion with real coverage here is the ordering check on publish_topics[0]. Consider asserting each resolved constant is actually present in contract["event_bus"]["publish_topics"] to verify resolution selected a declared topic.

♻️ Make the assertions verify resolution against the contract
 publish_topics = contract["event_bus"]["publish_topics"]
 assert publish_topics[0].endswith("inference-response.v1")
-assert TOPIC_DELEGATION_CALL_COMPLETED.endswith("delegation-call-completed.v1")
-assert TOPIC_DELEGATION_ESCALATION_TRIGGERED.endswith(
-    "delegation-escalation-triggered.v1"
-)
-assert TOPIC_DELEGATION_ALL_TIERS_FAILED.endswith(
-    "delegation-all-tiers-failed.v1"
-)
-assert TOPIC_DELEGATION_MODEL_DEGRADED.endswith("delegation-model-degraded.v1")
+for resolved in (
+    TOPIC_DELEGATION_CALL_COMPLETED,
+    TOPIC_DELEGATION_ESCALATION_TRIGGERED,
+    TOPIC_DELEGATION_ALL_TIERS_FAILED,
+    TOPIC_DELEGATION_MODEL_DEGRADED,
+):
+    assert resolved in publish_topics
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@tests/unit/nodes/node_llm_delegation_call_effect/test_handler_llm_delegation_call.py`
around lines 124 - 131, The current assertions on
TOPIC_DELEGATION_CALL_COMPLETED, TOPIC_DELEGATION_ESCALATION_TRIGGERED,
TOPIC_DELEGATION_ALL_TIERS_FAILED, and TOPIC_DELEGATION_MODEL_DEGRADED are
tautological because they mirror `_single_contract_topic(..., suffix)` behavior;
instead assert that each resolved constant is actually present in the contract's
publish topics (e.g., contract["event_bus"]["publish_topics"] or the local
publish_topics variable used in test_handler_llm_delegation_call) to verify
resolution selected a declared topic, while keeping the existing ordering
assertion for publish_topics[0]; locate the constants and the
publish_topics/contract usage in the test to make these presence assertions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@src/omnimarket/nodes/node_llm_delegation_call_effect/handlers/handler_llm_delegation_call.py`:
- Around line 62-99: The deploy-gate is rejecting the PR because it expects
runtime-evidence in a specific location/format; ensure the evidence for
OMN-12489 is placed exactly where the gate requires — typically as a commit
trailer (e.g., add `Evidence-Ticket: OMN-12489` and `Evidence-Source: OCC#2010`
to the latest commit message) or as the specific PR label/metadata the gate
checks (e.g., add the required `Evidence-Ticket` label or
`deploy:evidence=OMN-12489` label); update the PR/commit accordingly and re-run
the gate, and if it still fails paste the exact deploy-gate error output so we
can match the expected format (this is unrelated to code symbols like
_single_contract_topic or TOPIC_DELEGATION_EXECUTE which are fine).

---

Nitpick comments:
In
`@tests/unit/nodes/node_llm_delegation_call_effect/test_handler_llm_delegation_call.py`:
- Around line 124-131: The current assertions on
TOPIC_DELEGATION_CALL_COMPLETED, TOPIC_DELEGATION_ESCALATION_TRIGGERED,
TOPIC_DELEGATION_ALL_TIERS_FAILED, and TOPIC_DELEGATION_MODEL_DEGRADED are
tautological because they mirror `_single_contract_topic(..., suffix)` behavior;
instead assert that each resolved constant is actually present in the contract's
publish topics (e.g., contract["event_bus"]["publish_topics"] or the local
publish_topics variable used in test_handler_llm_delegation_call) to verify
resolution selected a declared topic, while keeping the existing ordering
assertion for publish_topics[0]; locate the constants and the
publish_topics/contract usage in the test to make these presence assertions.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 378c6f2d-039b-4f75-9899-fe42b7788053

📥 Commits

Reviewing files that changed from the base of the PR and between 31df90f and 309919c.

📒 Files selected for processing (2)
  • src/omnimarket/nodes/node_llm_delegation_call_effect/handlers/handler_llm_delegation_call.py
  • tests/unit/nodes/node_llm_delegation_call_effect/test_handler_llm_delegation_call.py

@jonahgabriel
jonahgabriel force-pushed the jonah/omn-12489-projection-api-analytics-dsn branch from 309919c to 8fed1c9 Compare June 1, 2026 17:42
@jonahgabriel
jonahgabriel added this pull request to the merge queue Jun 1, 2026
Merged via the queue into dev with commit acc642a Jun 1, 2026
42 checks passed
@jonahgabriel
jonahgabriel deleted the jonah/omn-12489-projection-api-analytics-dsn branch June 1, 2026 17:48
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