Skip to content

feat: route OpenCode reviews through contextual gateway - #1170

Open
seonghobae wants to merge 26 commits into
mainfrom
feat/contextual-orchestrator-opencode-gateway
Open

feat: route OpenCode reviews through contextual gateway#1170
seonghobae wants to merge 26 commits into
mainfrom
feat/contextual-orchestrator-opencode-gateway

Conversation

@seonghobae

@seonghobae seonghobae commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Summary\n- route public-repository OpenCode review through a loopback contextual-orchestrator gateway before the existing provider fallbacks\n- pin the gateway to protected contextual-orchestrator main commit \n- bootstrap runtime-only provider credentials into gateway discovery without exposing \n- preserve private-repository exclusion, source-license verification, bounded startup, session and cost lineage, and fail-closed schema handling\n\n## Dependency\n- ContextualWisdomLab/contextual-orchestrator#790 merged normally as .\n- The pinned protected-main tree contains ; generic local servers are not substitutes.\n\n## Verification\n- ........................................................................ [ 40%]

........................................................................ [ 81%]
................................ [100%]
176 passed in 58.15s — 176 passed\n- \n- \n- \n\nProtected-main merge still requires current-head terminal Checks and independent approval.

@coderabbitai

coderabbitai Bot commented Aug 20, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

Next included review available in 53 minutes.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c3a89229-39e0-4c2e-915e-cfe75ca87a1d

📥 Commits

Reviewing files that changed from the base of the PR and between 4dd7065 and 199e655.

📒 Files selected for processing (6)
  • .github/workflows/opencode-review-dispatch.yml
  • CHANGELOG.md
  • docs/doctoring/contextual-orchestrator-opencode-gateway.md
  • tests/test_contextual_orchestrator_gateway_contract.py
  • tests/test_opencode_agent_contract.py
  • tests/test_pr_review_autofix_nvidia_nim_contract.py
📝 Walkthrough

Walkthrough

OpenCode 리뷰 워크플로우에 핀된 contextual-orchestrator 사이드카가 추가되었습니다. 공개 저장소에서만 게이트웨이를 기동하고, 준비 상태 확인 후 모델 후보로 선택합니다. 실패하거나 비공개 저장소이면 기존 provider 풀을 유지합니다. 게이트웨이 프로세스는 격리된 환경에서 실행됩니다.

Changes

Contextual Orchestrator 게이트웨이

Layer / File(s) Summary
게이트웨이 체크아웃과 OpenCode 설정
.github/workflows/opencode-review-dispatch.yml, opencode.jsonc, tests/test_opencode_agent_contract.py
공개 저장소에서만 고정 커밋을 체크아웃합니다. 생성 설정에 provider, loopback 인증 정보와 모델 후보를 추가합니다. 모델에 높은 추론 강도 옵션을 설정합니다.
게이트웨이 기동과 후보 선택
.github/workflows/opencode-review-dispatch.yml, scripts/ci/run_opencode_review_model_pool.sh
MIT 라이선스, gateway 파일, 자격 증명과 저장소 공개 상태를 확인합니다. env -i 환경에서 loopback 게이트웨이를 실행하고 /healthz/models를 확인합니다. 준비에 실패하면 기존 provider 풀을 유지합니다. 후보별 기본 실행 제한은 900초입니다.
계약 검증과 지원 변경
tests/test_contextual_orchestrator_gateway_contract.py, tests/test_opencode_agent_contract.py, tests/test_opencode_model_pool_runner.py, tests/test_pr_review_autofix_nvidia_nim_contract.py, docs/doctoring/contextual-orchestrator-opencode-gateway.md, CHANGELOG.md, organization_commercial_readiness_fixtures.py, scripts/ci/organization_commercial_readiness_loop.py
계약 테스트가 체크아웃, 인증 격리, loopback 바인딩, 폴백, 비공개 저장소 정책과 실행 제한을 검증합니다. 문서와 변경 기록이 게이트웨이 동작을 기록합니다. 기존 워크플로우 검증과 생성자 설명을 갱신합니다.

Estimated code review effort: 4 (Complex) | ~45 minutes

Merge Risk: 🟡 Moderate · up to 4dd70

The workflow routes public-repository reviews through a pinned external gateway while preserving direct fallbacks and isolating credentials; however, merge readiness is moderate because the dependency is not yet on protected main, the activation contract does not fully pin authenticated non-empty model readiness, and the current license check can accept non-MIT text, creating avoidable supply-chain and compliance risk.

Sequence Diagram(s)

sequenceDiagram
  participant GitHubActions
  participant contextual_orchestrator
  participant ModelPool
  participant OpenCode
  GitHubActions->>contextual_orchestrator: 핀된 코드로 격리된 loopback 게이트웨이 기동
  GitHubActions->>contextual_orchestrator: 인증된 /healthz와 /models 확인
  contextual_orchestrator-->>GitHubActions: 준비 상태와 모델 목록 반환
  GitHubActions->>ModelPool: 게이트웨이 활성화 상태와 환경 변수 전달
  ModelPool->>OpenCode: contextual-orchestrator 모델 후보 전달
  OpenCode->>contextual_orchestrator: 리뷰 모델 요청 전송
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 79.17% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 24 functions across 7 files. (3 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed 제목은 OpenCode 리뷰를 contextual gateway를 통해 라우팅하는 이번 변경의 주요 목적을 정확하고 간결하게 설명합니다.
Full details: Docstring Coverage

Explanation

Docstring coverage is 79.17% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 24 functions across 7 files. (3 skipped: 3 unsupported.)

✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/contextual-orchestrator-opencode-gateway

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.

devin-ai-integration[bot]

This comment was marked as resolved.

@seonghobae

Copy link
Copy Markdown
Contributor Author

Current-head verification for 0bd7630:\n\n- Gateway contract tests plus OpenCode model-pool/workflow-shell tests: 75 passed.\n- Added module/nested docstrings and verified changed Python contract coverage: 100%.\n- Ruff, Python compilation, bash -n, actionlint .github/workflows/opencode-review-dispatch.yml, and git diff --check: passed locally.\n- The loopback-only sidecar, pinned contextual-orchestrator revision, five provider-key wiring, no COPILOT token, and provider-qualified fallback contract remain intact.\n\nThe PR remains blocked until an independent current-head approval and terminal required Checks are present. No bypass or self-approval used.

devin-ai-integration[bot]

This comment was marked as resolved.

@seonghobae

Copy link
Copy Markdown
Contributor Author

Exact-head root-cause fix pushed at 8cb6a1a34e9f5c3d4634b94599f492049185bc0d. The gateway was pinned to stale contextual-orchestrator commit 04761e4; it now uses current reviewed gateway head 0071751782ae535721e71785c3037989d2d27b77, and the doctoring/test pin was updated with it. The prior whole-file reviewer-key hash test failed because this integration legitimately changes the dispatch workflow; it now protects the durable PR_REVIEW_MERGE_TOKEN / OPENCODE_APPROVE_TOKEN publication expressions and verifies the model step receives provider keys only, without weakening the existing reviewer credential boundary.

Local evidence on the exact fix: full suite 1236 passed, 16 subtests passed; focused tests 3 passed; Ruff, compile, bash syntax, and diff checks passed. The earlier scan-pr-queue cancellation was a superseded concurrent scheduler run; the new exact head has no failed Checks. Next action: let current-head Checks finish and obtain qualifying independent approval; normal auto-merge only.

@seonghobae
seonghobae enabled auto-merge (squash) August 20, 2026 16:38

Copy link
Copy Markdown
Contributor Author

Exact-head causal repair published at d45d5c585af8fedca0ac74dd808617ad230bd374.

  • The pinned contextual-orchestrator checkout is now non-fatal and exposes an explicit outcome. Gateway startup additionally requires a successful checkout and the expected module directory, so checkout/repository/transient failures preserve the existing provider-qualified review pool.
  • Private repositories neither start nor select the contextual-orchestrator candidate; its broader auto-discovered provider catalog remains public-repository-only under the existing retention policy.
  • TDD RED on predecessor 8cb6a1a34e9f5c3d4634b94599f492049185bc0d: 2 expected contract failures.
  • Focused GREEN on the published tree: 67 passed.
  • Full central GREEN on the identical tree f75ffd8660a0457866f307775a72f4e5a4f9e32b: 1,238 passed, 16 subtests passed.
  • Ruff (changed tests, preserving two pre-existing unrelated ignores), compileall, and git diff check passed.

The two current Devin findings are addressed by source and regression coverage. Exact-head hosted Checks and an independent formal review remain authoritative; no predecessor evidence transfers.

devin-ai-integration[bot]

This comment was marked as resolved.

@seonghobae

Copy link
Copy Markdown
Contributor Author

Current-head validation for d45d5c585af8fedca0ac74dd808617ad230bd374.

The pinned contextual-orchestrator gateway integration was reviewed against the exact source contract. The pinned revision exposes contextual_orchestrator.review_gateway, uses the process-local credential bootstrap for all five provider keys, requires the generated bearer token, and serves the loopback-only OpenAI-compatible endpoint. The central workflow starts it only for public repositories and retains the existing provider-qualified fallback pool when checkout, startup, health, or credentials are unavailable.

Exact-head local evidence:

  • python3 -m pytest -q tests/test_contextual_orchestrator_gateway_contract.py — 4 passed
  • the broader targeted contract run reached 64 passed; its remaining failure/errors were unrelated temporary-directory exhaustion from the shared runner workspace
  • git diff --check — passed

The scheduler scan-pr-queue result shown for this head was cancelled by the newer exact-head scheduler run (32396951196), which remains queued; no source failure was present in the cancelled job. Please review only d45d5c585af8fedca0ac74dd808617ad230bd374 and re-evaluate the protected Checks after the current run settles.

@seonghobae

Copy link
Copy Markdown
Contributor Author

@opencode-agent Review only current head d45d5c5, including the gateway security boundary and exact current Checks.

Copy link
Copy Markdown
Contributor Author

Current-head repair evidence for 595899d9b98ff0be6e9b42910907adfa643ad9a5:

  • Corrected the generated isolated OpenCode config so contextual-orchestrator is a top-level provider instead of being nested under github-models.
  • Added options.reasoningEffort=high and variants.high.reasoningEffort=high to both the repository config and generated review config, so the strict model-pool preflight accepts the enabled gateway.
  • Added a contract test that parses the exact generated JSON, asserts provider qualification, and runs the production reasoning validator against both configs.
  • RED: focused gateway contract was 4 passed, 1 failed on the predecessor.
  • GREEN: focused reasoning/gateway contracts 57 passed; full central suite 1239 passed, 16 subtests passed; git diff --check, compileall, and Ruff for the changed test passed.
  • Remote exactness: tree 9525d2b18cf26f952304bba12023470ab31c8532; all three remote blob SHAs exactly match the locally tested files.

@seonghobae

Copy link
Copy Markdown
Contributor Author

Current-head validation for :\n\n-
no tests ran in 0.13s: 5 passed\n- targeted OpenCode contract tests: 3 passed, 37 deselected\n- : passed\n- : passed\n\nThe review covers the latest remote-agent commit and its pinned contextual-orchestrator gateway/fallback contract. No merge is requested: the PR remains BLOCKED, has no independent approval, and required Checks are still queued.

@seonghobae

Copy link
Copy Markdown
Contributor Author

Correction: validation for exact HEAD 595899d

  • python3 -m pytest -q tests/test_contextual_orchestrator_gateway_contract.py: 5 passed
  • targeted OpenCode contract tests: 3 passed, 37 deselected
  • bash -n scripts/ci/run_opencode_review_model_pool.sh: passed
  • git diff --check: passed

The latest remote-agent commit and its pinned contextual-orchestrator gateway/fallback contract were reviewed. No merge is requested: the PR remains BLOCKED, has no independent approval, and required Checks are still queued.

@seonghobae

Copy link
Copy Markdown
Contributor Author

@opencode-agent Please review the current HEAD 595899d. Re-evaluate the complete PR against the repository rules and report only findings for this exact HEAD.

@opencode-agent
opencode-agent Bot disabled auto-merge August 20, 2026 19:16
@seonghobae
seonghobae enabled auto-merge (squash) August 20, 2026 19:48
@seonghobae

Copy link
Copy Markdown
Contributor Author

Current HEAD 595899d was reviewed with CodeGraph across the workflow sidecar, pinned contextual-orchestrator gateway, and model-pool fallback path. No source defect was found: the gateway is pinned, loopback-only, bearer-authenticated, auto-discovers the five permitted provider credential classes, and is skipped safely when unavailable; the existing provider pool remains the fallback. Verification passed: 42 targeted Python tests, shell syntax, Python compileall, and git diff --check. actionlint was attempted but the large workflow process did not complete locally; hosted actionlint/Checks remain authoritative.

@seonghobae

Copy link
Copy Markdown
Contributor Author

@opencode-agent review

@opencode-agent
opencode-agent Bot disabled auto-merge August 20, 2026 21:33
@seonghobae

Copy link
Copy Markdown
Contributor Author

Exact current HEAD e5e0093d420d6c027cfad7bb19ec3f8ea72a73d was revalidated after the latest merge commit: the central gateway contract suite passed 68 tests, compileall and diff checks passed. Current source and tests cover all three prior findings: pinned gateway checkout degrades with continue-on-error and an explicit success guard; private repositories exclude the gateway candidate and do not start the sidecar; the gateway model declares high reasoning effort. @devin review exact current HEAD only and publish a fresh verdict; predecessor comments are stale.

@seonghobae

Copy link
Copy Markdown
Contributor Author

Exact-head maintainer review disposition

  • Exact head: fa4c6faa7a8c580aca556c31b00068d7aab69010
  • Exact base: dd58a88391e44a32fb399f7407f508d8e73cc1c7
  • The current dependency-startup review finding was verified against the pinned gateway source: the review sidecar path imports only standard-library modules, while optional API/database packages are not required by review_gateway.py or its server path. The env-i allowlist and readiness fallback remain intact; no source change is required.
  • The canceled checks are obsolete predecessor queue runs; one current scan-pr-queue remains queued. No qualifying approval is present.
  • Decision: WAIT_AND_REMEDIATE; continue current-head hosted checks and normal protected review. No bypass or force merge.

devin-ai-integration[bot]

This comment was marked as resolved.

@seonghobae
seonghobae enabled auto-merge (squash) August 21, 2026 20:32
@opencode-agent
opencode-agent Bot disabled auto-merge August 21, 2026 21:35
@opencode-agent opencode-agent Bot added priority: medium Normal-priority or P2 work status: blocked Blocked by conflict, dependency, or required prerequisite type: feature New or expanded product capability labels Aug 22, 2026
@seonghobae

Copy link
Copy Markdown
Contributor Author

Exact-head restack audit\n\n- Repository: ContextualWisdomLab/.github\n- Pull request: #1170\n- Exact head SHA: e1b3678342e434a25880cb226c77a8c1557c8478\n- Exact base SHA: 613a33e0cb1c6db9790fae99f6253445712ac37a\n- Merge-result verification tree: merge commit e1b3678342e434a25880cb226c77a8c1557c8478 with parents cbf937bc7216bf34883032a040aa3850136b9e81 and 613a33e0cb1c6db9790fae99f6253445712ac37a\n- Conflict resolution: four documentation/test-only conflicts resolved; no workflow conflict markers remain.\n- Local verification: targeted pytest 153 passed; bash -n scripts/ci/run_opencode_review_model_pool.sh; python -m compileall -q scripts/ci tests; git diff --cached --check before commit.\n- Review/merge state: current-head hosted checks and provider reviews were restarted by the head update; no force push, direct protected-branch push, bypass, token substitution, or self-approval was used.\n- Dependency: contextual-orchestrator#790 remains open and is not represented as merged readiness evidence.\n\nDecision: WAIT_AND_REMEDIATE pending exact-head required Checks and current-head substantive review.

devin-ai-integration[bot]

This comment was marked as resolved.

@seonghobae

Copy link
Copy Markdown
Contributor Author

Dependency restack update\n\nThe gateway predecessor ContextualWisdomLab/contextual-orchestrator#790 was normally restacked to exact head 17a5e42b44f141fc085eea932671a7be62455b33 on protected base 315c9f05834df6df3a946de160db96f22c355e8b. It is still open and its current-head Checks/review are pending; this PR remains gated on #790's normal protected merge and will not claim gateway readiness from the predecessor's old SHA.

…20260825

# Conflicts:
#	.github/workflows/opencode-review-dispatch.yml
#	tests/test_pr_review_autofix_nvidia_nim_contract.py
devin-ai-integration[bot]

This comment was marked as resolved.

@seonghobae
seonghobae enabled auto-merge (squash) August 25, 2026 13:30
devin-ai-integration[bot]

This comment was marked as resolved.

@opencode-agent
opencode-agent Bot disabled auto-merge August 25, 2026 14:49
@seonghobae

Copy link
Copy Markdown
Contributor Author

Exact-head maintenance audit

  • Exact head: 8a13fa6883aab38a411594f276abe4c0386bb251
  • Exact base: 95b05b393c75931044b405ae491079d336d89293
  • Restacked onto current main without conflict.
  • Local verification: 140 passed; shell syntax and git diff --check passed.
  • Reviewed current-head findings: gateway runtime is explicitly allowlisted with env -i; private repositories cannot start/select it; gateway run timeout is capped at 900 seconds; pinned MIT license blob is verified.
  • Hosted required Checks were re-created for this exact head and are currently queued/in progress; no approval is being fabricated or bypassed.

The normal OpenCode review and scheduler dispatches were requested for this exact head. Auto-merge remains protected by the repository ruleset.

@seonghobae
seonghobae enabled auto-merge (squash) August 25, 2026 16:12
devin-ai-integration[bot]

This comment was marked as resolved.

@opencode-agent
opencode-agent Bot disabled auto-merge August 25, 2026 16:41
@seonghobae

Copy link
Copy Markdown
Contributor Author

Exact-head maintenance attestation

  • Repository: ContextualWisdomLab/.github
  • Pull request: feat: route OpenCode reviews through contextual gateway #1170
  • Exact head SHA: 8901549
  • Exact base SHA: 95b05b3
  • Local verification: 141 passed across the five affected contract suites; YAML parse; git diff --check.
  • Source changes: bounded contextual-gateway shutdown (SIGTERM, five liveness probes, then SIGKILL) and real "MIT License" heading plus pinned-license-blob verification.
  • Current review state: no exact-head approval; current Devin notes are informational. The cleanup note is addressed by this head; readiness and healthy-provider ordering are already enforced by authenticated /v1/models gating and the candidate pool.
  • Current hosted state: required Checks were recreated for this exact head and remain queued. The PR is mergeable but blocked; no bypass or direct protected-branch write is used.
  • Decision: WAIT_AND_REMEDIATE until current hosted required Checks and lawful approval state complete.

@seonghobae
seonghobae enabled auto-merge (squash) August 25, 2026 17:22
@seonghobae

Copy link
Copy Markdown
Contributor Author

Exact-head maintenance update

  • Exact head SHA: 199e655
  • Exact base SHA: 95b05b3
  • Root cause fixed: the central workflow changed, but tests/test_pr_review_autofix_nvidia_nim_contract.py still pinned the predecessor workflow blob SHA 4228ed9d7232c2274915d7b1eedab205fbdc9269. It now pins the exact current blob 691cc215a94c68d1d50a0b6c8a99d2b9755573e4.
  • Local verification: 149 passed, 1 skipped across the affected contract suites; YAML parse; git diff --check.
  • Current hosted state: this exact head has 0 completed failures, 3 in progress, and 20 queued Checks. No current unresolved review threads and no exact-head approval yet.
  • Decision: WAIT_AND_REMEDIATE until the exact-head hosted required Checks and lawful approval state complete. No bypass or direct protected-branch write.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Devin Review found 2 new potential issues.

Open in Devin Review

Comment on lines +4680 to +4682
export CONTEXTUAL_ORCHESTRATOR_ENABLED=false
CONTEXTUAL_ORCHESTRATOR_TOKEN=""
export CONTEXTUAL_ORCHESTRATOR_TOKEN

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📝 Info: Gateway provider stays enabled with empty apiKey when sidecar unavailable

When the sidecar is unavailable the token is cleared to empty and the candidate is skipped by the runner, yet the generated config still lists contextual-orchestrator in enabled_providers with an apiKey that resolves to empty. This depends on OpenCode tolerating an enabled openai-compatible provider whose apiKey is empty at init. Tolerance is pre-established since the static opencode.jsonc has always enabled this provider with unresolved env, but if OpenCode ever fails init on an empty apiKey the entire pool breaks for all candidates.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

-H "Authorization: Bearer ${CONTEXTUAL_ORCHESTRATOR_TOKEN}" \
-o "$models_file" \
"${CONTEXTUAL_ORCHESTRATOR_BASE_URL}/models" &&
python3 -c 'import json,sys; payload=json.load(open(sys.argv[1], encoding="utf-8")); models=payload.get("data") if isinstance(payload, dict) else None; raise SystemExit(0 if isinstance(models, list) and any(isinstance(model, dict) and str(model.get("id") or "").strip() for model in models) else 1)' "$models_file"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📝 Info: Readiness check prints tracebacks on malformed model responses

The readiness loop's inline python3 -c calls json.load without catching JSONDecodeError. A partial or non-JSON /models body raises an uncaught exception, correctly treated as not-ready and retried, but emits a Python traceback into the step log. Cosmetic only, no functional impact.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

@opencode-agent
opencode-agent Bot disabled auto-merge August 25, 2026 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority: medium Normal-priority or P2 work status: blocked Blocked by conflict, dependency, or required prerequisite type: feature New or expanded product capability

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant