Skip to content

feat(OMN-11242): wire TopicProvisioner into runtime kernel startup - #1652

Merged
jonahgabriel merged 3 commits into
mainfrom
jonah/omn-11242-wire-topic-provisioner-kernel
May 19, 2026
Merged

jonahgabriel merged 3 commits into
mainfrom
jonah/omn-11242-wire-topic-provisioner-kernel

Conversation

@jonahgabriel

@jonahgabriel jonahgabriel commented May 18, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Wires TopicProvisioner.ensure_provisioned_topics_exist() into the runtime kernel boot sequence (section 3.5 was already present in service_kernel.py — confirmed and documented)
  • Adds dynamic materialization path: _wire_live_handler_subscriptions() in service_runtime_host_process.py now calls TopicProvisioner.ensure_topic_exists() for each subscribe topic before calling wire_subscriptions()
  • All provisioning is best-effort: exceptions are caught, logged as WARNING, and never block kernel startup or live contract materialization

Changes

  • src/omnibase_infra/runtime/service_runtime_host_process.py: provision topics via TopicProvisioner before wire_subscriptions() in _wire_live_handler_subscriptions(); reads bootstrap_servers from self._event_bus._bootstrap_servers via isinstance(self._event_bus, EventBusKafka) check (avoids os.environ read blocked by check-env-reads pre-commit hook)
  • tests/unit/runtime/test_topic_provisioner_integration.py: 7 new unit tests covering boot-time structural checks, best-effort failure handling, call ordering (provision before subscribe), inmemory bus skip, and no-wiring skip

Test plan

  • uv run pytest tests/unit/runtime/test_topic_provisioner_integration.py -v — 7 tests pass
  • uv run pytest tests/ -m unit -v — full unit suite green
  • pre-commit run --all-files — all hooks pass

Ticket

OMN-11242

dod_evidence

  • 7 unit tests in test_topic_provisioner_integration.py pass locally
  • TopicProvisioner referenced in service_kernel.py (section 3.5) and service_runtime_host_process.py (_wire_live_handler_subscriptions)
  • ensure_provisioned_topics_exist callable confirmed via import test
  • Call ordering verified: provisioning precedes wire_subscriptions in test call log
  • Best-effort semantics verified: provisioner failure does not block subscription wiring
  • Pre-commit hooks pass including check-env-reads, kafka-no-hardcoded-fallback, mypy strict

Summary by CodeRabbit

  • New Features

    • Live handler subscriptions with Kafka now automatically pre-provision required topics, with graceful failure handling that logs warnings without blocking subscription.
  • Tests

    • Added comprehensive tests validating topic provisioning behavior during runtime initialization and dynamic handler subscription scenarios.

Review Change Stack

Evidence-Source: OCC#1147
Evidence-Ticket: OMN-11242

…ization

Provisions subscribe_topics from newly materialized contracts before
wire_subscriptions is called, ensuring Kafka topics exist before any
subscription attempt. Reads bootstrap_servers from the Kafka event bus
instance (not env) to stay within approved env-read boundaries.

Best-effort: TopicProvisioner failure logs a warning but never blocks
materialization or subscription. Provisioning is skipped entirely when
the runtime is using an inmemory event bus.

Boot-time provisioning (section 3.5 in service_kernel.py) was already
wired; this PR adds the dynamic-materialization path and 7 unit tests.
@coderabbitai

coderabbitai Bot commented May 18, 2026 •

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

The PR adds best-effort Kafka topic pre-provisioning to runtime handler subscription wiring. Before wiring subscriptions for live-materialized handlers, the code now checks if the event bus is Kafka, extracts bootstrap servers, and ensures each subscribed topic exists using TopicProvisioner. Provisioning failures log warnings and do not block subscriptions. Comprehensive tests verify kernel boot integration, best-effort failure handling, and conditional provisioning behavior.

Changes

Topic pre-provisioning for live handler subscriptions

Layer / File(s) Summary
Topic pre-provisioning in live handler subscriptions
src/omnibase_infra/runtime/service_runtime_host_process.py
RuntimeHostProcess._wire_live_handler_subscriptions() now performs best-effort Kafka topic pre-provisioning before wiring subscriptions. When the event bus is Kafka, it extracts bootstrap servers, creates a TopicProvisioner from contract paths, and ensures each subscribed topic exists. Provisioning failures are caught and logged as warnings without blocking subscription wiring.
Test module setup and helper functions
tests/unit/runtime/test_topic_provisioner_integration.py
Establishes test module documentation, module-level constants (provisioner patch target and fallback Kafka bootstrap server), and helper functions _make_descriptor_mock() and _make_kafka_bus_mock() for constructing test fixtures.
Kernel boot and provisioning verification tests
tests/unit/runtime/test_topic_provisioner_integration.py
Tests in TestKernelBootTopicProvisioning verify that TopicProvisioner is referenced in kernel source code and that its import path is correct. Additionally validates that when provisioning fails during boot, the failure is logged as a warning and does not halt kernel startup (best-effort behavior).
Live materialization provisioning behavior tests
tests/unit/runtime/test_topic_provisioner_integration.py
Tests in TestDynamicMaterializationTopicProvisioning verify the runtime ordering and conditional execution: provisioning is called for each subscribed topic before subscription wiring; provisioning failures do not block subscriptions from being wired; provisioning is skipped when the event bus is not Kafka; and provisioning is skipped when event bus wiring is missing.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A rabbit hops with topics in tow,
Pre-provisioning Kafka before subscriptions flow,
When bootstrap servers dance and queues align,
Best-effort magic makes the streams shine! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 71.43% 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 clearly and specifically describes the main change: wiring TopicProvisioner into the runtime kernel startup process.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch jonah/omn-11242-wire-topic-provisioner-kernel

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

@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: 2

🧹 Nitpick comments (2)
tests/unit/runtime/test_topic_provisioner_integration.py (2)

43-51: ⚡ Quick win

Consider replacing string-based source inspection with behavior verification.

String matching in source code is fragile and can break with refactoring (import aliasing, formatting changes). Since you have test_provisioner_import_path_is_correct validating the import path, this test adds limited incremental value. Consider removing it or replacing it with an integration test that actually exercises the kernel boot sequence.

🤖 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/runtime/test_topic_provisioner_integration.py` around lines 43 -
51, The test test_provisioner_is_referenced_in_kernel_source uses fragile
string-based source inspection of service_kernel to look for "TopicProvisioner"
and "ensure_provisioned_topics_exist"; replace it by either removing the test
(since test_provisioner_import_path_is_correct already covers import validation)
or convert it into a behavior/integration test that boots the kernel and asserts
the TopicProvisioner integration by exercising service_kernel's boot path (e.g.,
invoking the kernel startup routine and verifying that
ensure_provisioned_topics_exist is called or that the TopicProvisioner is
registered), targeting the service_kernel module and the
TopicProvisioner/ensure_provisioned_topics_exist symbols rather than matching
source text.

102-120: ⚖️ Poor tradeoff

Optional: Consider extracting the kernel simulation logic to a helper function.

The inline kernel section-3.5 simulation (lines 102-120) is complex and could be extracted to a reusable helper if other tests need similar behavior. Since this is currently the only test using this pattern, extraction is optional.

🤖 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/runtime/test_topic_provisioner_integration.py` around lines 102 -
120, Extract the inline kernel simulation block that calls
provisioner.ensure_provisioned_topics_exist and logs via kernel_logger into a
small reusable test helper (e.g., run_provisioning_and_log or
simulate_kernel_provisioning) to reduce duplication and improve readability;
move the try/except, the call to
mock_provisioner.ensure_provisioned_topics_exist (preserve correlation_id
param), the determination of log_level based on provisioning_result["status"],
and the kernel_logger.log/kernel_logger.warning behavior into that helper, then
replace the inline block with a single call to the new helper from the test.
🤖 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/omnibase_infra/runtime/service_runtime_host_process.py`:
- Around line 3575-3604: The loop over subcontract.subscribe_topics is wrapped
by a single try/except so one failing ensure_topic_exists call aborts
provisioning for remaining topics; change to provision each topic independently
by moving the try/except inside the for loop (or catching exceptions around each
await _provisioner.ensure_topic_exists(topic_name=_topic)), logging a
non-blocking warning that includes node_name and the specific _topic on failure
while keeping the outer bootstrap/TopicProvisioner creation unchanged.

In `@tests/unit/runtime/test_topic_provisioner_integration.py`:
- Around line 94-96: The local import "import logging as _logging" is redundant
because logging is already imported at module scope; remove the line "import
logging as _logging" and ensure any references within the test (e.g., near the
import of TopicProvisioner from omnibase_infra.event_bus.service_topic_manager)
use the existing module-level "logging" name instead.

---

Nitpick comments:
In `@tests/unit/runtime/test_topic_provisioner_integration.py`:
- Around line 43-51: The test test_provisioner_is_referenced_in_kernel_source
uses fragile string-based source inspection of service_kernel to look for
"TopicProvisioner" and "ensure_provisioned_topics_exist"; replace it by either
removing the test (since test_provisioner_import_path_is_correct already covers
import validation) or convert it into a behavior/integration test that boots the
kernel and asserts the TopicProvisioner integration by exercising
service_kernel's boot path (e.g., invoking the kernel startup routine and
verifying that ensure_provisioned_topics_exist is called or that the
TopicProvisioner is registered), targeting the service_kernel module and the
TopicProvisioner/ensure_provisioned_topics_exist symbols rather than matching
source text.
- Around line 102-120: Extract the inline kernel simulation block that calls
provisioner.ensure_provisioned_topics_exist and logs via kernel_logger into a
small reusable test helper (e.g., run_provisioning_and_log or
simulate_kernel_provisioning) to reduce duplication and improve readability;
move the try/except, the call to
mock_provisioner.ensure_provisioned_topics_exist (preserve correlation_id
param), the determination of log_level based on provisioning_result["status"],
and the kernel_logger.log/kernel_logger.warning behavior into that helper, then
replace the inline block with a single call to the new helper from the test.
🪄 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: f69538be-2105-4682-9d88-f3327c3b9bfa

📥 Commits

Reviewing files that changed from the base of the PR and between 07f69a0 and 9d55779.

📒 Files selected for processing (2)
  • src/omnibase_infra/runtime/service_runtime_host_process.py
  • tests/unit/runtime/test_topic_provisioner_integration.py

Comment thread src/omnibase_infra/runtime/service_runtime_host_process.py
Comment thread tests/unit/runtime/test_topic_provisioner_integration.py Outdated
@sonarqubecloud

Copy link
Copy Markdown

@jonahgabriel
jonahgabriel merged commit 4fc612c into main May 19, 2026
108 of 111 checks passed
@jonahgabriel
jonahgabriel deleted the jonah/omn-11242-wire-topic-provisioner-kernel branch May 19, 2026 13:10
jonahgabriel added a commit that referenced this pull request Jul 9, 2026
…ra (#2242)

* ci(OMN-14172): roll out integration silent-skip guard to omnibase_infra

Enforcement-not-detection rollout of the OMN-14172 silent-skip false-green
guard (omnimarket canary #1652, MERGED) to omnibase_infra — CI gate +
pre-commit hook ship in the same PR (Operating Rule #5):

- scripts/ci/check_integration_skips.py + integration_skip_guard.yaml,
  calibrated for infra's real Postgres-absence skip vocabulary (grepped
  from tests/); allowlists Kafka/Consul/Vault/Qdrant/live/catalog skips
- new `integration-guard` CI job: provisions postgres:16-alpine (mirrors
  migration-integration), applies all migrations, exports OMNIBASE_INFRA_DB_URL
  + POSTGRES_* env, runs the curated Postgres-only proofs with --junitxml,
  then enforces check_integration_skips.py (fail-closed)
- wired BLOCKING via ci_summary_gate.py SKIPPABLE_GATE_JOBS (the CI Summary
  umbrella required context); NO new branch-protection required context is
  registered here — deferred to operator/Codex once green on real PRs
- integration-skip-guard pre-commit hook (--selftest, no DB needed)
- tests/ci/test_check_integration_skips.py: case-(a) PASS + case-(b) RED
  regression proof plus full-vocabulary coverage

OCC companion owed: omnibase_infra verify/receipt-gate needs
Evidence-Source: OCC#<n> (Codex authors).

* fix(ci): narrow integration skip guard proofs

* fix(ci): make integration guard proof self-contained

* ci(OMN-14172): fix integration guard review follow-ups
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