Skip to content

feat: add adaptive provider reasoning control - #99

Closed
seonghobae wants to merge 39 commits into
feat/free-first-model-fallback-policyfrom
feat/adaptive-reasoning-control
Closed

feat: add adaptive provider reasoning control#99
seonghobae wants to merge 39 commits into
feat/free-first-model-fallback-policyfrom
feat/adaptive-reasoning-control

Conversation

@seonghobae

@seonghobae seonghobae commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

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@8726df151e64eecb89d91a4c029e809a785ee126 and .github#939@ac5665148bb113f92e97d2fc49a729bca2f050b5 were 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:

  1. merge fix(security): pin provider egress and repair the Atheris lock #96;
  2. integrate and revalidate feat: add free-first model fallback policy #94 on the exact security base;
  3. update this branch to the integrated exact base and run the complete repository gate;
  4. only then return this PR to Ready.

The PR remains Draft.

Product behavior

  • explicit per-agent reasoning capability profiles; no model-name inference;
  • canonical levels none < minimal < low < medium < high < xhigh < max;
  • adaptive, fixed, and disabled policy modes;
  • role-specific defaults for thinker, worker, verifier, and synthesizer;
  • workflow position, recursion depth, decomposition count, and access-list fan-in as bounded test-time-compute evidence;
  • multiple-signal complexity and high-impact thresholds so one keyword cannot force maximum effort;
  • absolute model-specific caps;
  • provider projection for OpenAI-compatible effort, NVIDIA reasoning effort, Nemotron thinking controls, Gemini thinking levels, and validated custom nested mappings;
  • caller-owned reasoning fields preserved, including explicit null;
  • one canonical decision remapped to each failover candidate’s declared capability;
  • coverage across chat, streaming, full-shape chat/Responses passthrough, Batch JSONL, generated planning, model judging, route, and conduct paths;
  • exactly one next-supported-level worker retry after verifier rejection, followed by only the affected verifier and synthesizer recomputation;
  • fixed-effort ablation with verifier acceptance plus provider-reported reasoning and total token counts;
  • profile visibility in configuration and admin views, preservation across frozen-agent replacement and durable re-save;
  • no private intermediate reasoning text retained.

Standalone and modular activation boundary

Importing contextual_orchestrator no longer activates or monkey-patches the optional adaptive-reasoning extension. The public enable_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

  1. The extension-only reasoning_profile patch 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.
  2. After verifier-triggered worker escalation, recomputed verifier and synthesizer trace entries refresh their reasoning decision and usage evidence from the exact second invocation.
  3. Caller-owned scalar or null reasoning parents cannot be replaced by nested defaults, and overlapping custom payload paths are rejected.
  4. Batch evidence is keyed to original custom_id contracts rather than provider response ordering.
  5. Planner, verification judge, streaming, cache, and durable-record paths preserve exact role, context-lifetime, policy, and usage evidence.
  6. A fresh-interpreter regression first proved package import was mutating runtime classes and that no explicit CLI activator existed. The implementation now keeps import side-effect free and makes activation explicit and idempotent.
  7. Generated-plan cursor sizing was extracted behind a documented test seam so list/non-list plans and active/absent workflow contexts are all covered.
  8. A retry that replaces a worker, verifier, or synthesizer invocation but receives no provider usage now removes the superseded usage record instead of retaining and counting stale token evidence from the replaced call.

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 head 73ed3a077f88a2f03cf734f1067bee2dcce2467f), 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:

focused reasoning/fallback/provider suite: 289 passed
full repository suite under the permanent Tests workflow environment: 721 passed
production coverage: 5,056 statements and 1,468 branches, 100%
public docstrings: 100%
git diff --check: passed

The first integrated Tests run 31324002684 checked out exact predecessor head 97d2bbd15ed832706bf59c27ae46a305037cdef9 and failed collection because seven reasoning tests import the test-only tests/reasoning_fakes.py module while the general Tests workflow did not expose tests/ on PYTHONPATH. The dedicated reasoning workflow and local verification already used that test-only path. The narrow correction scopes PYTHONPATH to 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:

  • Tests run 31324164670, job 93271746567: success; exact checkout 2502915a8e90059074167e6306b47148a1d40fdc, 721 tests passed, 5,056 statements and 1,468 branches at 100%, public docstrings 100%;
  • Security run 31324164668: success; CodeQL job 93271746520 and supply-chain/SBOM job 93271746626 both succeeded;
  • Fuzz run 31324164706: success; Hypothesis job 93271775681 and Atheris job 93271775698 succeeded, with crash upload skipped only because no crash artifact existed;
  • Reasoning control quality run 31324164655, job 93271746474: success; exact checkout 2502915a8e90059074167e6306b47148a1d40fdc, 721 tests passed twice, 1,103 reasoning statements and 432 branches at 100%, public docstrings 100%;
  • CodeRabbit: successful status only;
  • formal current-head reviews: none;
  • unresolved review threads: none;
  • independent current-head approval: absent.

All predecessor and base results are historical only. Central policy candidates ContextualWisdomLab/.github#937 and #939 remain read-only prerequisites at exact heads 8726df151e64eecb89d91a4c029e809a785ee126 and ac5665148bb113f92e97d2fc49a729bca2f050b5; 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 expected 42, 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

  • Exact contributor head: b80a30eb4bf9cc0f7c77c58e4d429c9d9fe268db on unchanged base 73ed3a077f88a2f03cf734f1067bee2dcce2467f.
  • RED: a plain repository-root pytest invocation failed collection in seven reasoning modules with ModuleNotFoundError: reasoning_fakes; the prior green paths depended on workflow-only PYTHONPATH injection.
  • Root cause: the shared test fake was repository test infrastructure, but its import authority existed only in CI jobs rather than the repository's pytest configuration.
  • Repair: [tool.pytest.ini_options] now exposes tests for every pytest invocation; both workflow-only environment overrides are removed; and a contract prevents regression to CI-only path state.
  • GREEN locally: the focused reasoning set passed 29 tests before the final redundant-override cleanup; the strengthened import-boundary contract passes 3 tests; the complete plain suite passed 722 tests; owned production statement/branch coverage is 100% (5,056 statements / 1,468 branches); public-docstring coverage is 100%; compilation and git diff --check pass.
  • Exact-head Reasoning control quality run 31532820922 is success. Job 93916711236 checked out b80a30eb4bf9cc0f7c77c58e4d429c9d9fe268db, passed 722 tests twice, and proved 100% reasoning-module statement/branch coverage (1,103 statements / 432 branches) plus 100% public-docstring coverage.
  • Tests 31532820928 / job 93916714945: success, 722 passed, 100% production statement/line coverage (5,056/5,056), 100% branch coverage (1,468/1,468), and 100% public-docstring coverage.
  • Security 31532820812: success. Supply-chain job 93916713049 found no known vulnerabilities and published CycloneDX SBOM artifact 9118143328 with archive digest sha256:297cad9fbaa43d9b656677c1cbd81c0b5f49847f21cec397183fde2bac3ecb66; CodeQL job 93916713253 scanned 85/85 Python files and 3/3 GitHub Actions files successfully.
  • Fuzz 31532820933: success. Hypothesis job 93916714565 passed 8 property tests; Atheris job 93916714288 completed four bounded targets with 8,144,882 / 9,831,756 / 539,354 / 3,500 runs and no crash artifact.
  • Reasoning-control quality 31532820922 / job 93916711236: 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.
  • Every listed job explicitly fetched and checked out exact contributor head b80a30eb4bf9cc0f7c77c58e4d429c9d9fe268db with checkout credentials disabled. Predecessor evidence does not transfer.
  • The PR remains Draft and stacked on feat: add free-first model fallback policy #94/fix(security): pin provider egress and repair the Atheris lock #96. All exact-head checks, current review evidence, zero valid unresolved findings, protected-base reconciliation, and qualifying independent approval remain required before readiness or merge.

Exact-head hosted evidence for b80a30eb4bf9cc0f7c77c58e4d429c9d9fe268db

All repository-local workflows explicitly fetched and checked out the exact contributor head with checkout credentials disabled:

  • Tests run 31532820928, job 93916714945: 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.
  • Reasoning control quality run 31532820922, job 93916711236: 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%.
  • Security run 31532820812: success. Python supply-chain job 93916713049 found no known vulnerabilities and published CycloneDX SBOM artifact 9118143328 with archive digest sha256:297cad9fbaa43d9b656677c1cbd81c0b5f49847f21cec397183fde2bac3ecb66; CodeQL job 93916713253 completed successfully on the same exact head.
  • Fuzz run 31532820933: success. Hypothesis job 93916714565 passed 8 property tests; Atheris job 93916714288 completed all four 61-second targets with 8,144,882 / 9,831,756 / 539,354 / 3,500 runs and no crash artifact.
  • Formal reviews: zero. Unresolved inline review threads: zero. Qualifying independent non-author approval: absent.

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:

  • This Draft PR remains exact head b80a30eb4bf9cc0f7c77c58e4d429c9d9fe268db on exact feat: add free-first model fallback policy #94 base 73ed3a077f88a2f03cf734f1067bee2dcce2467f; feat: add free-first model fallback policy #94 remains stacked on Draft fix(security): pin provider egress and repair the Atheris lock #96 exact head 3703d0da9823b8258a0be94f1801aa5d61bfad9f.
  • Protected repository main remains 6841b71935e0b7cb98fb52bcb4709cc5100c8d87; protected central .github/main remains 6eb06cdd08c79a06f7b390069d4ffa49e2eb7dba.
  • Ready central #937 remains 67d834f510fe044dd9d53cd4f4b9783353e303bd with 11 terminal-success exact-head workflows, zero unresolved threads, and no qualifying approval.
  • Ready central #939 remains ac5665148bb113f92e97d2fc49a729bca2f050b5 with nine terminal-success exact-head workflows, zero unresolved threads, and no formal review.
  • Ready central #943 advanced to 601b254f3a8ea4cc593e7089d6baeadd9d8d3ee4 with 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.
  • This PR has zero formal reviews, zero unresolved threads, and no qualifying independent approval.

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 main remains 6eb06cdd08c79a06f7b390069d4ffa49e2eb7dba. Central #937 remains open at 67d834f510fe044dd9d53cd4f4b9783353e303bd with eleven terminal-success workflows, zero unresolved threads, and one OpenCode APPROVED formal 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 at ac5665148bb113f92e97d2fc49a729bca2f050b5 with nine terminal-success workflows, zero threads, and no formal review; #943 remains open at 601b254f3a8ea4cc593e7089d6baeadd9d8d3ee4 with 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.

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.
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 4f23ca22-df28-45ea-b7ee-057bf05393e6

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

❤️ Share

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

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.

Copy link
Copy Markdown
Contributor Author

@coderabbitai review
@opencode-agent @cwl-noema-review

Review exact current head d1d3242fc9e71ffdb2fe94ee06e8a880c08bc558 only. The permanent read-only quality workflow checked out this SHA and passed: 451 tests; 1,082 statements and 418 branches at 100%; docstrings 100%; compileall and diff checks passed. Verify explicit side-effect-free package import, idempotent composition-root activation before agent loading, role/topology/workload allocation, provider mapping and caller ownership, failover projection, generated-plan sizing, bounded verifier escalation, current invocation usage evidence, Batch custom_id alignment, hidden-reasoning privacy, and APA 7 doctoring. The PR must remain Draft until #96 and #94 are integrated. Submit a formal exact-head review or actionable findings; do not reuse ancestor-head evidence.

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
🧩 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.py

Length 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.md

Length 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.md

Length 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.py

Length of output: 63513


@seonghobae, I reviewed exact commit d1d3242fc9e71ffdb2fe94ee06e8a880c08bc558 only.

Finding — current invocation usage can remain stale after retry

_retry_rejected_worker_once() updates worker["usage"], verifier["usage"], and synthesizer["usage"] only when the recomputation returns non-None usage. If the original call reported usage but the retry does not, the trace retains usage from the original invocation.

This conflicts with the current-invocation usage evidence requirement. It can also cause sum_usage_tokens() in a fixed-effort ablation to count tokens from the replaced invocation.

Affected locations:

  • contextual_orchestrator/_reasoning_workflow.py, Line 138
  • contextual_orchestrator/_reasoning_workflow.py, Line 167
  • contextual_orchestrator/_reasoning_workflow.py, Line 207

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 None. Assert that each recomputed trace row has no stale usage and that reasoning-token evidence is None.

I also verified these static properties at the exact head:

  • Importing contextual_orchestrator does not activate adaptive-reasoning hooks.
  • The CLI activates reasoning control before agent loading and orchestrator construction.
  • enable_reasoning_control() is idempotent for the built-in runtime.
  • The policy uses role, complexity, risk, workflow depth, decomposition, and access-list fan-in under profile caps.
  • Provider projection preserves caller-owned fields, including complete null paths.
  • Failover projects one canonical decision to the selected model profile.
  • Batch projection uses custom_id.
  • Reasoning evidence stores decisions and token counts, not intermediate reasoning text.
  • Doctoring defines claim boundaries and includes the requested APA-style references.

The PR should remain Draft until #96 and #94 are integrated and the complete integrated-head gate passes.

⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown
Contributor Author

@opencode-agent @cwl-noema-review

Review exact current contributor head b80a30eb4bf9cc0f7c77c58e4d429c9d9fe268db against exact live base 73ed3a077f88a2f03cf734f1067bee2dcce2467f. All repository-local deterministic and product-specific workflows are terminal-success on this exact head. Treat predecessor-head reviews, approvals, requested changes, checks, and synthetic evidence as historical. Report only current-head actionable findings; model evidence is not qualifying independent approval. Keep this stacked PR Draft while its prerequisite remains unintegrated.

Copy link
Copy Markdown
Contributor Author

@coderabbitai full review
@opencode-agent
@cwl-noema-review

Review exact contributor head b80a30eb4bf9cc0f7c77c58e4d429c9d9fe268db against exact stacked base 73ed3a077f88a2f03cf734f1067bee2dcce2467f. Treat predecessor, status-only, author-only, synthetic-merge, and model results as non-transferable. Exact-head Tests 31532820928, Security 31532820812, Fuzz 31532820933, and Reasoning control quality 31532820922 are terminal-success, but they do not substitute for current review or qualifying independent approval. Report only current-head actionable findings; keep this Draft behind #94/#96.

@seonghobae

Copy link
Copy Markdown
Contributor Author

Closed by autonomous commercial loop: PR targets non-main base feat/free-first-model-fallback-policy (stack intermediate). Re-open against current main after #111#114 land if the product gap remains. (feat: add adaptive provider reasoning control)

@seonghobae seonghobae closed this Aug 12, 2026
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