feat(runtime): align platform runtime contexts#31
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces V6 “runtime contexts” (Backtest/Sandbox/Live) as thin wrappers that boot a shared kernel service set, aligns the in-process observability utilities (MetricCollector, Tracer) to the V6 MetricsPort/TracerPort contracts, and adds a new /api/v2/info endpoint exposing contract/runtime metadata for operational introspection.
Changes:
- Added
BacktestRuntime,SandboxRuntime, andLiveRuntimecontexts that register runtime/metrics/tracer/plugin-registry into aPlatformKernellifecycle. - Updated
MetricCollectorandTracerto satisfyMetricsPortandTracerPort(tagged metrics + context-managed spans with attributes). - Added
/api/v2/infoplus corresponding docs and tests; updated CHANGELOG.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_runtime_contexts.py | Adds tests for runtime context policy metadata, kernel boot lifecycle, and port conformance. |
| tests/test_api_v2_observability.py | Extends API v2 tests to validate /api/v2/info and refactors span assertion formatting. |
| src/runtime/contexts.py | Implements the runtime context classes and lifecycle integration with PlatformKernel. |
| src/runtime/init.py | Exposes runtime context API at src.runtime. |
| src/platform/runtime.py | Adds platform-layer re-exports for runtime contexts. |
| src/platform/api_v2.py | Wires runtime contexts into the API app state and adds /api/v2/info. |
| src/core/monitoring.py | Updates tracer spans to be context managers with attributes; adds tagged metric helpers to match ports. |
| docs/architecture/open-platform.md | Documents Phase 6 runtime contexts and /api/v2/info. |
| docs/ARCHITECTURE_TARGET_STATE.md | Updates target-state architecture notes to include runtime contexts and /api/v2/info. |
| docs/api/rest-api.md | Adds /api/v2/info to the endpoint overview. |
| CHANGELOG.md | Records the new runtime contexts, observability alignment, /api/v2/info, and related tests. |
Comments suppressed due to low confidence (1)
src/runtime/contexts.py:151
_on_stoponly records the stop counter whenself.metricsis a concreteMetricCollector. If a customMetricsPortis injected, runtime stop metrics will be silently skipped. Consider callingself.metrics.incr(...)directly to honor the port abstraction.
self.state = RuntimeState.STOPPED
if isinstance(self.metrics, MetricCollector):
self.metrics.incr("runtime_stop_total", tags={"runtime": self.mode.value})
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+307
to
+315
| return ApiEnvelope( | ||
| data={ | ||
| "name": "Unified Quant Platform", | ||
| "version": app.version, | ||
| "contract_version": CONTRACT_VERSION, | ||
| "runtimes": { | ||
| name: runtime.info() | ||
| for name, runtime in request.app.state.runtime_contexts.items() | ||
| }, |
Comment on lines
+139
to
+143
| if isinstance(self.metrics, MetricCollector): | ||
| self.metrics.incr("runtime_start_total", tags={"runtime": self.mode.value}) | ||
| if isinstance(self.tracer, Tracer): | ||
| with self.tracer.start_span( | ||
| f"runtime.{self.mode.value}.start", |
Comment on lines
+72
to
+76
| self.plugin_registry = plugin_registry or PluginRegistry( | ||
| contract_version=CONTRACT_VERSION | ||
| ) | ||
| self.config = self._build_config(config or {}) | ||
| self.state = RuntimeState.CREATED |
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
/api/v2/infoexposing API version, contract_version, and runtime policy metadata.PR 28/29/30 Checks
Tests
Result: 1274 passed, 35 skipped