feat: add adaptive provider reasoning control - #99
Conversation
Add explicit provider capability profiles, role-sensitive reasoning effort, bounded verifier escalation, failover projection, Batch/Responses/streaming integration, fixed-effort ablation, admin persistence, 100% slice coverage, and APA 7 doctoring.
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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 |
Strip extension-only profile fields before core patch validation, preserve durable profile updates after frozen-agent replacement, and refresh verifier/synthesizer reasoning evidence after bounded worker retry. Add TDD regressions and retain 100% focused statement/branch/docstring coverage.
Remove adaptive-reasoning hook installation from package import, expose an idempotent explicit activation API, enable it at the product CLI composition root before agent loading, and document the standalone/MSA boundary.
Extract generated-plan cursor sizing into a documented pure seam so list and non-list plan shapes, active and absent workflow contexts, and the 100% branch-coverage contract remain directly testable.
|
@coderabbitai review Review exact current head |
🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
requested_sha="d1d3242fc9e71ffdb2fe94ee06e8a880c08bc558"
printf 'HEAD: '
git rev-parse HEAD
printf '\nRequested object: '
git rev-parse "$requested_sha^{commit}"
printf '\nStatus:\n'
git status --short
printf '\nCommit summary:\n'
git show --no-ext-diff --format=fuller --no-patch "$requested_sha"
printf '\nChanged files against first parent:\n'
git diff-tree --no-commit-id --name-status -r "$requested_sha"
printf '\nRepository root files and candidate reasoning files:\n'
fd -t f -d 4 . | rg -i '(^|/)(reason|provider|agent|batch|plan|doctor|cli|config|__init__)'
printf '\nPython module outlines for candidate source files:\n'
while IFS= read -r f; do
echo "===== $f ====="
ast-grep outline "$f" --items all --type class,function --view compact || true
done < <(fd -t f -e py . | rg -i '(reason|provider|agent|batch|plan|cli|config|__init__)')Length of output: 5069 🏁 Script executed: #!/bin/bash
set -euo pipefail
head="d1d3242fc9e71ffdb2fe94ee06e8a880c08bc558"
printf '%s\n' '=== refs that contain exact HEAD ==='
git branch -a --contains "$head" || true
printf '%s\n' '=== possible merge bases ==='
git show-branch --merge-base HEAD "$(git for-each-ref --format='%(refname)' 'refs/remotes/*' | head -n 12)" 2>/dev/null || true
printf '%s\n' '=== recent ancestry (names only) ==='
git log --oneline --decorate -n 20 "$head"
printf '%s\n' '=== cumulative changed files versus likely PR base refs ==='
for ref in origin/main origin/master main master; do
if git rev-parse --verify -q "$ref" >/dev/null; then
base="$(git merge-base "$ref" "$head")"
echo "--- $ref; merge base $base ---"
git diff --name-status "$base" "$head"
fi
done
printf '%s\n' '=== exact final-commit patch ==='
git diff --no-ext-diff --find-renames --find-copies "${head}^" "$head" -- contextual_orchestrator/_reasoning_orchestrator_hooks.py
printf '%s\n' '=== core module outlines ==='
for f in \
contextual_orchestrator/__init__.py \
contextual_orchestrator/reasoning_control.py \
contextual_orchestrator/reasoning_runtime.py \
contextual_orchestrator/_reasoning_orchestrator_hooks.py \
contextual_orchestrator/batch_routing.py \
contextual_orchestrator/provider_transport.py; do
if test -f "$f"; then
echo "===== $f ====="
ast-grep outline "$f" --items all --view compact || true
fi
done
printf '%s\n' '=== reasoning-related test and documentation files ==='
fd -t f -d 3 . tests docs contextual_orchestrator 2>/dev/null | rg -i '(reasoning|batch|provider|doctor|cli|init)'Length of output: 13253 🏁 Script executed: #!/bin/bash
set -euo pipefail
files=(
contextual_orchestrator/__init__.py
contextual_orchestrator/__main__.py
contextual_orchestrator/reasoning_control.py
contextual_orchestrator/reasoning_runtime.py
contextual_orchestrator/_reasoning_client_hooks.py
contextual_orchestrator/_reasoning_config_hooks.py
contextual_orchestrator/_reasoning_orchestrator_hooks.py
contextual_orchestrator/_reasoning_payload.py
contextual_orchestrator/_reasoning_policy.py
contextual_orchestrator/_reasoning_profile.py
contextual_orchestrator/_reasoning_state.py
contextual_orchestrator/_reasoning_workflow.py
contextual_orchestrator/_reasoning_workload.py
contextual_orchestrator/model_fallback.py
contextual_orchestrator/batch_routing.py
)
printf '%s\n' '=== line counts ==='
wc -l "${files[@]}"
printf '%s\n' '=== source symbol map ==='
for f in "${files[@]}"; do
echo "===== $f ====="
ast-grep outline "$f" --items all --view signatures || true
done
printf '%s\n' '=== activation, installation, and public-API references ==='
rg -n -C 3 --glob '*.py' \
'\b(enable_reasoning_control|install_.*hooks|reasoning_control|ReasoningRuntime|_INSTALLED|_installed)\b' \
contextual_orchestrator tests
printf '%s\n' '=== reasoning evidence, projection, ownership, retry, batch, privacy references ==='
rg -n -C 2 --glob '*.py' \
'\b(custom_id|reasoning(_effort|_tokens)?|thinking|usage|retry|verif|failover|fallback|trace|plan_size|decomposition|access_list|workflow|hidden|analysis)\b' \
contextual_orchestrator/_reasoning_client_hooks.py \
contextual_orchestrator/_reasoning_config_hooks.py \
contextual_orchestrator/_reasoning_orchestrator_hooks.py \
contextual_orchestrator/_reasoning_payload.py \
contextual_orchestrator/_reasoning_policy.py \
contextual_orchestrator/_reasoning_profile.py \
contextual_orchestrator/_reasoning_state.py \
contextual_orchestrator/_reasoning_workflow.py \
contextual_orchestrator/_reasoning_workload.py \
contextual_orchestrator/model_fallback.py \
tests/test_reasoning_control.py \
tests/test_reasoning_runtime.py \
tests/test_reasoning_runtime_coverage.py \
tests/test_reasoning_runtime_coverage_retry.py \
tests/test_reasoning_workload.py \
tests/test_reasoning_workload_coverage.pyLength of output: 116498 🏁 Script executed: #!/bin/bash
set -euo pipefail
show() {
local file="$1"
local start="$2"
local end="$3"
echo "===== ${file}:${start}-${end} ====="
sed -n "${start},${end}p" "$file" | nl -ba -v "$start"
}
show contextual_orchestrator/__init__.py 1 170
show contextual_orchestrator/__main__.py 45 155
show contextual_orchestrator/reasoning_runtime.py 1 100
show contextual_orchestrator/_reasoning_profile_types.py 1 260
show contextual_orchestrator/_reasoning_profile_value.py 1 260
show contextual_orchestrator/_reasoning_policy.py 1 338
show contextual_orchestrator/_reasoning_payload.py 1 163
show contextual_orchestrator/_reasoning_client_hooks.py 1 179
show contextual_orchestrator/_reasoning_state.py 1 314
show contextual_orchestrator/_reasoning_workflow.py 1 280
show contextual_orchestrator/_reasoning_orchestrator_hooks.py 1 362
printf '%s\n' '===== import-boundary and activation tests ====='
sed -n '1,260p' tests/test_reasoning_import_boundary.py | nl -ba
sed -n '1,260p' tests/test_reasoning_activation_coverage.py | nl -ba
printf '%s\n' '===== behavior tests ====='
sed -n '1,280p' tests/test_reasoning_control.py | nl -ba
sed -n '1,280p' tests/test_reasoning_runtime.py | nl -ba
sed -n '1,280p' tests/test_reasoning_workload.py | nl -ba
printf '%s\n' '===== doctoring citations and claim boundaries ====='
rg -n -C 3 -i \
'(Fugu|Conductor|TRINITY|RouteLLM|FrugalGPT|ISO/IEC 23894|ISO/IEC 42001|References|claim|limit|not |APA)' \
docs/doctoring/adaptive-reasoning-control.mdLength of output: 1888 🏁 Script executed: #!/bin/bash
set -euo pipefail
show() {
local file="$1"
local start="$2"
local end="$3"
echo "===== ${file}:${start}-${end} ====="
sed -n "${start},${end}{=;p;}" "$file"
}
show contextual_orchestrator/__init__.py 1 170
show contextual_orchestrator/__main__.py 45 155
show contextual_orchestrator/reasoning_runtime.py 1 100
show contextual_orchestrator/_reasoning_profile_types.py 1 220
show contextual_orchestrator/_reasoning_profile_value.py 1 260
show contextual_orchestrator/_reasoning_policy.py 1 338
show contextual_orchestrator/_reasoning_payload.py 1 163
show contextual_orchestrator/_reasoning_client_hooks.py 1 179
show contextual_orchestrator/_reasoning_state.py 1 314
show contextual_orchestrator/_reasoning_workflow.py 1 280
show contextual_orchestrator/_reasoning_orchestrator_hooks.py 1 362
show tests/test_reasoning_import_boundary.py 1 260
show tests/test_reasoning_activation_coverage.py 1 260
show tests/test_reasoning_control.py 1 280
show tests/test_reasoning_runtime.py 1 280
show tests/test_reasoning_workload.py 1 280
printf '%s\n' '===== doctoring citations and claim boundaries ====='
rg -n -C 3 -i \
'(Fugu|Conductor|TRINITY|RouteLLM|FrugalGPT|ISO/IEC 23894|ISO/IEC 42001|References|claim|limit|not |APA)' \
docs/doctoring/adaptive-reasoning-control.mdLength of output: 124670 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '%s\n' '=== generated-plan implementation and callers ==='
rg -n -C 12 --glob '*.py' \
'\bdef _plan_generated\b|\b_plan_generated\s*\(|\bplan_generated\s*\(' \
contextual_orchestrator tests
printf '%s\n' '=== usage collection and retry fixtures ==='
rg -n -C 12 --glob '*.py' \
'\bdef take_usage\b|\btake_usage\s*\(|RetryUsageClient|NoUsageClient|retry.*usage|usage.*retry' \
contextual_orchestrator tests
printf '%s\n' '=== full focused retry coverage section ==='
sed -n '1,280p' tests/test_reasoning_runtime_coverage_retry.py
printf '%s\n' '=== generated-plan tests and expected contract ==='
rg -n -C 10 --glob '*.py' \
'generated.plan|plan.size|set_plan_size|_update_generated_plan_cursor|empty.*plan|steps == \[\]' \
tests contextual_orchestrator
printf '%s\n' '=== direct history for modified generated-plan hook ==='
git log --format='%H %s' --follow -- contextual_orchestrator/_reasoning_orchestrator_hooks.pyLength of output: 63513
Finding — current invocation usage can remain stale after retry
This conflicts with the current-invocation usage evidence requirement. It can also cause Affected locations:
Clear the existing row usage when the recomputation has no usage. Add a regression where the initial worker, verifier, and synthesizer calls report usage and their recomputations return I also verified these static properties at the exact head:
The PR should remain Draft until
|
|
@opencode-agent @cwl-noema-review Review exact current contributor head |
|
@coderabbitai full review Review exact contributor head |
Purpose
Add the missing within-model test-time-compute axis to Contextual Orchestrator. The runtime already allocates compute through model selection and direct-versus-deep workflow topology; this change adds explicit, role-sensitive reasoning effort while keeping expected cost bounded and difficult-task capability recoverable.
Historical central snapshot (superseded by the live dependency refresh below):
.github#937@8726df151e64eecb89d91a4c029e809a785ee126and.github#939@ac5665148bb113f92e97d2fc49a729bca2f050b5were unintegrated read-only dependencies. No evidence from that snapshot transfers.Stack order
This PR is intentionally stacked on
feat/free-first-model-fallback-policy(#94), which is stacked on the provider-egress security base (#96). Required integration order:The PR remains Draft.
Product behavior
none < minimal < low < medium < high < xhigh < max;null;Standalone and modular activation boundary
Importing
contextual_orchestratorno longer activates or monkey-patches the optional adaptive-reasoning extension. The publicenable_reasoning_control()composition-root API activates it explicitly and idempotently. The packaged CLI invokes this API before loading agent configuration; a library or another CWL service opts in before constructing runtime objects. This prevents import-order-dependent global mutation while preserving isolated typed installation for alternate runtimes and tests.Provider requests still use #96’s DNS-pinned HTTPS transport, original-host TLS SNI/certificate verification, proxy bypass, redirect rejection, and KV credential boundary.
Research and standards
Architecture and doctoring connect the implementation to Fugu, Conductor, TRINITY, adaptive test-time compute, RouteLLM, FrugalGPT, ISO/IEC 23894:2023, and ISO/IEC 42001:2023. APA 7 references and explicit claim boundaries are included in
docs/doctoring/adaptive-reasoning-control.md.TDD defects found and repaired
reasoning_profilepatch field is stripped before the existing core patch validator runs, then attached to the replacement frozen agent and re-saved through the durable pool store.nullreasoning parents cannot be replaced by nested defaults, and overlapping custom payload paths are rejected.custom_idcontracts rather than provider response ordering.Exact-head verification
Historical exact remote head:
2502915a8e90059074167e6306b47148a1d40fdc.Historical exact tree:
0d271151e73ce0e039f23cbd1f04f664f656ffae. The current exact contributor identity is recorded in the hosted-evidence section below.Ancestry: integration merge
97d2bbd15ed832706bf59c27ae46a305037cdef9(prior reasoning head plus exact #94 head73ed3a077f88a2f03cf734f1067bee2dcce2467f), followed by the full-suite import-path correction.The ordinary two-parent refresh preserves #94/#96's side-effect-free secure transport boundary while retaining the reasoning-control exports and explicit
enable_reasoning_control()composition-root API. The merge removed the obsolete import-time provider-transport monkeypatch inherited from the predecessor base because #96 integrates secure transport directly.Local verification of this exact tree established:
The first integrated Tests run
31324002684checked out exact predecessor head97d2bbd15ed832706bf59c27ae46a305037cdef9and failed collection because seven reasoning tests import the test-onlytests/reasoning_fakes.pymodule while the general Tests workflow did not exposetests/onPYTHONPATH. The dedicated reasoning workflow and local verification already used that test-only path. The narrow correction scopesPYTHONPATHto the full-suite step; it does not publish the fakes as package API or change production imports.Exact-head GitHub evidence now succeeds on the unchanged head:
31324164670, job93271746567: success; exact checkout2502915a8e90059074167e6306b47148a1d40fdc, 721 tests passed, 5,056 statements and 1,468 branches at 100%, public docstrings 100%;31324164668: success; CodeQL job93271746520and supply-chain/SBOM job93271746626both succeeded;31324164706: success; Hypothesis job93271775681and Atheris job93271775698succeeded, with crash upload skipped only because no crash artifact existed;31324164655, job93271746474: success; exact checkout2502915a8e90059074167e6306b47148a1d40fdc, 721 tests passed twice, 1,103 reasoning statements and 432 branches at 100%, public docstrings 100%;All predecessor and base results are historical only. Central policy candidates ContextualWisdomLab/.github#937 and #939 remain read-only prerequisites at exact heads
8726df151e64eecb89d91a4c029e809a785ee126andac5665148bb113f92e97d2fc49a729bca2f050b5; neither is protected-main evidence or qualifying approval.The realistic recovery test fixes a deterministic arithmetic failure: low effort returns
41, verification rejects it, one bounded escalation to medium returns the expected42, verification accepts it, and synthesis produces the final correct result. Fixed-effort ablation proves the lower-effort cell consumes fewer reasoning tokens. The retry-usage regression proves a replacement invocation without usage cannot inherit or count superseded token evidence.Merge acceptance
Do not merge, publish, or release until the exact integrated head passes repository Tests, Fuzz, Security, Security Scan, SAST Semgrep, complete production statement/branch/docstring gates, package build/install smoke tests, and independent current-head review. No ancestor result or local-only slice result is sufficient.
Current exact-head local-discovery repair
b80a30eb4bf9cc0f7c77c58e4d429c9d9fe268dbon unchanged base73ed3a077f88a2f03cf734f1067bee2dcce2467f.pytestinvocation failed collection in seven reasoning modules withModuleNotFoundError: reasoning_fakes; the prior green paths depended on workflow-onlyPYTHONPATHinjection.[tool.pytest.ini_options]now exposestestsfor every pytest invocation; both workflow-only environment overrides are removed; and a contract prevents regression to CI-only path state.git diff --checkpass.31532820922is success. Job93916711236checked outb80a30eb4bf9cc0f7c77c58e4d429c9d9fe268db, passed 722 tests twice, and proved 100% reasoning-module statement/branch coverage (1,103 statements / 432 branches) plus 100% public-docstring coverage.31532820928/ job93916714945: success, 722 passed, 100% production statement/line coverage (5,056/5,056), 100% branch coverage (1,468/1,468), and 100% public-docstring coverage.31532820812: success. Supply-chain job93916713049found no known vulnerabilities and published CycloneDX SBOM artifact9118143328with archive digestsha256:297cad9fbaa43d9b656677c1cbd81c0b5f49847f21cec397183fde2bac3ecb66; CodeQL job93916713253scanned 85/85 Python files and 3/3 GitHub Actions files successfully.31532820933: success. Hypothesis job93916714565passed 8 property tests; Atheris job93916714288completed four bounded targets with 8,144,882 / 9,831,756 / 539,354 / 3,500 runs and no crash artifact.31532820922/ job93916711236: success, with 722 passed, 100% owned changed-module statement/line coverage (1,103/1,103), 100% branch coverage (432/432), and 100% public-docstring coverage.b80a30eb4bf9cc0f7c77c58e4d429c9d9fe268dbwith checkout credentials disabled. Predecessor evidence does not transfer.Exact-head hosted evidence for
b80a30eb4bf9cc0f7c77c58e4d429c9d9fe268dbAll repository-local workflows explicitly fetched and checked out the exact contributor head with checkout credentials disabled:
31532820928, job93916714945: success, 722 passed, 100% owned production statement and branch coverage (5,056 statements / 1,468 branches, zero misses or partials), and 100% public-docstring coverage.31532820922, job93916711236: success. The complete suite passed twice; the changed reasoning modules report 100% statement and branch coverage (1,103 statements / 432 branches), and their public-docstring gate passed at 100%.31532820812: success. Python supply-chain job93916713049found no known vulnerabilities and published CycloneDX SBOM artifact9118143328with archive digestsha256:297cad9fbaa43d9b656677c1cbd81c0b5f49847f21cec397183fde2bac3ecb66; CodeQL job93916713253completed successfully on the same exact head.31532820933: success. Hypothesis job93916714565passed 8 property tests; Atheris job93916714288completed all four 61-second targets with 8,144,882 / 9,831,756 / 539,354 / 3,500 runs and no crash artifact.This exact-head proof validates the import-boundary repair without transferring predecessor evidence. The PR remains Draft because upstream #94/#96 are unintegrated and required automated/independent review authority is absent.
Live dependency refresh (2026-08-12 05:11 UTC)
Read-only refetch superseding every earlier dependency snapshot in this body:
b80a30eb4bf9cc0f7c77c58e4d429c9d9fe268dbon exact feat: add free-first model fallback policy #94 base73ed3a077f88a2f03cf734f1067bee2dcce2467f; feat: add free-first model fallback policy #94 remains stacked on Draft fix(security): pin provider egress and repair the Atheris lock #96 exact head3703d0da9823b8258a0be94f1801aa5d61bfad9f.mainremains6841b71935e0b7cb98fb52bcb4709cc5100c8d87; protected central.github/mainremains6eb06cdd08c79a06f7b390069d4ffa49e2eb7dba.67d834f510fe044dd9d53cd4f4b9783353e303bdwith 11 terminal-success exact-head workflows, zero unresolved threads, and no qualifying approval.ac5665148bb113f92e97d2fc49a729bca2f050b5with nine terminal-success exact-head workflows, zero unresolved threads, and no formal review.601b254f3a8ea4cc593e7089d6baeadd9d8d3ee4with nine terminal-success exact-head workflows, zero unresolved threads, and no formal review; it is the bounded trusted-download User-Agent repair and does not replace #939's separate review-status semantics.Every dependency remains planning evidence only. No predecessor, status-only, synthetic-merge, queued, or unintegrated central evidence transfers to this contributor head.
Live central review-authority correction (2026-08-12 06:29 UTC)
Read-only dependency refetch: protected central
mainremains6eb06cdd08c79a06f7b390069d4ffa49e2eb7dba. Central #937 remains open at67d834f510fe044dd9d53cd4f4b9783353e303bdwith eleven terminal-success workflows, zero unresolved threads, and one OpenCodeAPPROVEDformal model review. That model review is not a qualifying independent human approval and does not make the central branch protected authority. Central #939 remains open atac5665148bb113f92e97d2fc49a729bca2f050b5with nine terminal-success workflows, zero threads, and no formal review; #943 remains open at601b254f3a8ea4cc593e7089d6baeadd9d8d3ee4with the same nine-success/zero-thread/no-review classification.This repository loop did not mutate the central repository. This PR's unchanged source head and local workflow evidence remain
active_pr; protected central integration and qualifying independent non-author approval remain absent. Keep the PR Draft.