Skip to content

feat(runtime): add decision model contracts - #1739

Merged
Teingi merged 2 commits into
oceanbase:masterfrom
AlexStocks:codex/decision-model-infra
Sep 27, 2026
Merged

Teingi merged 2 commits into
oceanbase:masterfrom
AlexStocks:codex/decision-model-infra

Conversation

@AlexStocks

Copy link
Copy Markdown
Contributor

Which issue or RFC does this PR close?

Refs #1643, #1644, #1645, #1647, #1648.

This is a foundation PR only; it does not close any of those issue-level behaviors.

Rationale for this change

The Jev/Laya investigation points to one reusable architecture rule for PowerContext: decision models should be provider-neutral runtime collaborators, invoked from deterministic code paths and allowed to fail open. This PR adds that narrow foundation before any Memory, Handoff, Experience, or Skill policy uses it.

What changes are included in this PR?

  • Adds provider-neutral DecisionModel contracts under powercontext.builtin.runtime:
    • explicit options in DecisionModelRequest
    • explicit fallback metadata in DecisionModelResult
    • portable inference usage reporting
  • Adds StructuredDecisionModel, a small adapter that wraps an existing StructuredGenerator and converts stable inference failures into explicit fail-open results.
  • Adds isolated decision inference configuration fields and a default-off RuntimeConfig.decision_assistance_enabled switch.
  • Splits the inference workload override validation into smaller helpers so adding the decision workload does not make the existing validator harder to maintain.

This PR intentionally does not connect decision models to Memory writes, Memory reranking, Handoff generation, Handoff acknowledgement, OpenAPI schemas, persistence, or prompt capabilities.

Are there any user-facing changes?

No behavior change is expected by default. The new configuration fields are inert until a later PR wires a decision model into a specific runtime policy path. There are no persisted format, HTTP API, OpenAPI, or generated-client changes.

How was this change tested?

  • uv run pytest tests/builtin/runtime/test_decision_model.py tests/test_server_generation.py -q
  • uv run pytest tests/e2e/test_builtin_runtime.py -q
  • uv run ruff check src/powercontext/builtin/runtime/decision_model.py src/powercontext/builtin/runtime/config.py src/powercontext/builtin/runtime/__init__.py tests/builtin/runtime/test_decision_model.py tests/test_server_generation.py
  • uv run ty check src/powercontext/builtin/runtime/decision_model.py src/powercontext/builtin/runtime/config.py tests/builtin/runtime/test_decision_model.py tests/test_server_generation.py

AI usage statement

Implemented with OpenAI Codex in the Codex desktop app, based on the Jev/Laya/OpenClaw/Hermes research notes and repository-local code inspection.

Introduce provider-neutral DecisionModel request/result types, a fail-open structured-generator adapter, and isolated decision inference configuration. The new runtime switch defaults off and does not connect the decision model to existing Memory or Handoff behavior yet.

Validation:

- uv run pytest tests/builtin/runtime/test_decision_model.py tests/test_server_generation.py -q

- uv run pytest tests/e2e/test_builtin_runtime.py -q

- uv run ruff check src/powercontext/builtin/runtime/decision_model.py src/powercontext/builtin/runtime/config.py src/powercontext/builtin/runtime/__init__.py tests/builtin/runtime/test_decision_model.py tests/test_server_generation.py

- uv run ty check src/powercontext/builtin/runtime/decision_model.py src/powercontext/builtin/runtime/config.py tests/builtin/runtime/test_decision_model.py tests/test_server_generation.py

Co-authored-by: OmX <omx@oh-my-codex.dev>

@AsperforMias AsperforMias left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please validate model-selected IDs against the request options before returning a successful decision. The inline finding includes a reproducer.

Design note (non-blocking): #1739 and #1740 share a base and introduce different contracts in the same module; please reconcile the intended contract before landing both. The linked issues #1643, #1644, #1645, #1647 and #1648 still require their domain implementations and experiments. This PR accurately describes itself as foundation-only, so those are follow-up scope, not additional blockers here.

Comment thread src/powercontext/builtin/runtime/decision_model.py Outdated
Reject non-fallback decision outputs that omit a selected option, select an option outside the request, or report scores for unknown option IDs. Invalid provider output now fails open with an explicit invalid_output fallback while preserving usage.

Tested: uv run --no-sync pytest tests/builtin/runtime/test_decision_model.py -q; ruff check/format --check decision_model and test; ty check decision_model and test

@Teingi Teingi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@Teingi
Teingi merged commit 7e22219 into oceanbase:master Sep 27, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants