Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 77 additions & 8 deletions .github/workflows/opencode-review-dispatch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5623,8 +5623,56 @@ jobs:
exit 0
}

retry_inline_comments_one_at_a_time() {
local batch_payload_file="$1" review_body="$2"
local split_dir comment_file wrapped_file error_file response_file
local attached=0
local found=0

split_dir="$(mktemp -d)"
if ! python3 "$GITHUB_WORKSPACE/scripts/ci/opencode_inline_comment_fallback.py" \
--split-payload "$batch_payload_file" \
--output-dir "$split_dir"; then
rm -rf "$split_dir"
return 1
fi
for comment_file in "$split_dir"/comment-*.json; do
[ -f "$comment_file" ] || continue
found=1
wrapped_file="$(mktemp)"
error_file="$(mktemp)"
response_file="$(mktemp)"
if [ "$attached" -eq 0 ]; then
jq --arg body "$review_body" --arg event "REQUEST_CHANGES" \
'.event = $event | .body = $body' "$comment_file" >"$wrapped_file"
else
cp "$comment_file" "$wrapped_file"
fi
if post_pull_review_with_retry \
"inline review one-at-a-time" \
"$review_write_token" \
"$wrapped_file" \
"$error_file" \
"$response_file"; then
attached=1
fi
rm -f "$wrapped_file" "$error_file" "$response_file"
if [ "${REVIEW_PUBLICATION_STALE_HEAD:-}" = "1" ]; then
rm -rf "$split_dir"
return 1
fi
done
rm -rf "$split_dir"
if [ "$found" -eq 0 ] || [ "$attached" -eq 0 ]; then
return 1
fi
return 0
}

create_pull_review_with_payload() {
local event="$1" body="$2" review_payload_file="$3" fallback_body_file="$4"
local source_body_file="${5:-}"
local control_json="${6:-}"
local gh_error_file
local rewritten_payload_file
local review_response_file
Expand All @@ -5640,6 +5688,19 @@ jobs:
emit_review_body_to_action_log "$event" "$body" "$review_payload_file"
if ! post_pull_review_with_retry "inline review" "$review_write_token" "$review_payload_file" "$gh_error_file" "$review_response_file"; then
warn_gh_publication_failure "pull review inline comments" "$gh_error_file"
if [ "${REVIEW_PUBLICATION_STALE_HEAD:-}" != "1" ] \
&& python3 "$GITHUB_WORKSPACE/scripts/ci/opencode_inline_comment_fallback.py" \
--is-unprocessable --error-file "$gh_error_file"; then
if retry_inline_comments_one_at_a_time "$review_payload_file" "$body"; then
rm -f "$gh_error_file" "$review_response_file"
update_review_overview "$event" "$body"
return 0
fi
fi
if [ -n "$source_body_file" ] && [ -n "$control_json" ]; then
build_inline_comment_failure_body \
"$source_body_file" "$fallback_body_file" "$control_json" "$gh_error_file" || true
fi
rm -f "$gh_error_file" "$review_response_file"
if [ "${REVIEW_PUBLICATION_STALE_HEAD:-}" = "1" ]; then
printf '::error::OpenCode inline review publication stopped because PR head advanced beyond %s.\n' "$HEAD_SHA"
Expand Down Expand Up @@ -5766,12 +5827,20 @@ jobs:
build_inline_comment_failure_body() {
local body_file="$1"
local output_file="$2"

{
cat "$body_file"
printf '\n## Inline comment publishing failed\n\n'
printf 'GitHub did not accept the inline review comments for the cited finding lines, so OpenCode did not copy suggested diffs into this PR-level body. Re-run the review after the findings are anchored to changed diff lines, or inspect the workflow log/control JSON and apply the changes manually.\n'
} >"$output_file"
local control_json="$3"
local error_file="${4:-}"
local -a fallback_args

fallback_args=(
python3 "$GITHUB_WORKSPACE/scripts/ci/opencode_inline_comment_fallback.py"
--control "$control_json"
--body "$body_file"
--output "$output_file"
)
if [ -n "$error_file" ]; then
fallback_args+=(--error-file "$error_file")
fi
"${fallback_args[@]}"
}

publish_request_changes_from_control() {
Expand All @@ -5785,8 +5854,8 @@ jobs:
fallback_body_file="$(mktemp)"
format_request_changes_body "$control_json" "$body_file"
build_request_changes_review_payload "$control_json" "$body_file" "$payload_file"
build_inline_comment_failure_body "$body_file" "$fallback_body_file"
create_pull_review_with_payload "REQUEST_CHANGES" "$(cat "$body_file")" "$payload_file" "$fallback_body_file"
build_inline_comment_failure_body "$body_file" "$fallback_body_file" "$control_json"
create_pull_review_with_payload "REQUEST_CHANGES" "$(cat "$body_file")" "$payload_file" "$fallback_body_file" "$body_file" "$control_json"
rm -f "$body_file" "$payload_file" "$fallback_body_file"
}

Expand Down
7 changes: 7 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,10 @@

<!-- CWL-ENTRY -->
> **Agents: read the master context FIRST.** Before any work, read [`docs/CWL-MASTER-CONTEXT.md`](docs/CWL-MASTER-CONTEXT.md) (mission · naruon-as-platform + inter-component UML · cross-cutting disciplines · conventions · roadmap · current state), the live **GitHub Project #1** <https://github.com/orgs/ContextualWisdomLab/projects/1> (work/roadmap source of truth), the full spec **ContextualWisdomLab/naruon#974**, and operate the Project per [`docs/agent-github-project-protocol.md`](docs/agent-github-project-protocol.md). The repo/Project — not any private agent memory — is the source of truth.
Materialize accepts only exact SHA-256 pins or a bounded relative `-r` include (no `.`/`..`); a lone `--require-hashes` directive is not trust evidence. See [`docs/doctoring/review-inline-comment-422-fallback.md`](docs/doctoring/review-inline-comment-422-fallback.md).

One-at-a-time 422 retries must keep multi-line start_line/start_side.
One-at-a-time 422 retries are capped at 20 comments; leftovers become deferred path:line rows.
One-at-a-time 422 retries strip leftover ```diff/```patch fences so unapplyable leftover diffs cannot 422 the retry.
Leftover overview receipts sanitize path and phrase so a leftover cannot close the HTML comment or reopen a suggestion fence.
Leftover overview paths that contain `-->`, `<!--`, or a suggestion fence are omitted.
80 changes: 80 additions & 0 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Architecture — ContextualWisdomLab `.github`

This repository is the organization control plane. It is not naruon and it
does not own product data. Sibling products remain standalone modules; this
repo publishes org profile assets, reusable required workflows, and the
review/merge schedulers those products consume.

## System context

```mermaid
flowchart LR
Buyer["Commercial buyer / reviewer"]
Agents["Agents on AGENTS.md"]
Project["GitHub Project #1"]
Hub["This repo: org .github"]
Products["Owned products<br/>naruon · orchestrator · engines"]
Runner["Required workflows in each repo context"]

Buyer --> Hub
Agents --> Project
Agents --> Hub
Project --> Hub
Hub --> Runner
Runner --> Products
Products -->|"standalone or as module"| Buyer
```

## Inline-comment 422 classification gate

```mermaid
flowchart TD
Err["gh api review write error"]
Kind{"HTTP 422 line, Unprocessable Entity, or JSON errors[].message?"}
Retry["Split batch and retry one comment"]
Fail["Do not treat SHA or issue 422 as unprocessable"]

Err --> Kind
Kind -->|"yes"| Retry
Kind -->|"no"| Fail
```

CWE-1288: a bare `422` substring is not an HTTP status.

## Control-plane data flow

```mermaid
sequenceDiagram
participant PR as Pull request
participant RW as Required workflows
participant OC as OpenCode reviewer
participant SV as sandboxed_verify / web E2E
participant MS as Merge scheduler

PR->>RW: pull_request_target on trusted base
RW->>OC: bounded evidence + NVIDIA NIM / OpenCode
OC->>SV: PoC command in isolated copy
SV-->>OC: redacted stdout/stderr + command metadata
OC-->>PR: APPROVE or request changes
MS->>PR: merge only on current-head approval + green checks
```

## Trust boundaries

- Required review workflows execute **base-branch** scripts.
- Reviewer agents stay `edit: deny`.
- Logs redact credential shapes. They do not mask operational PII.
- LLM and scheduled agents bind `NVIDIA_NIM_API_KEY`. They never use
`COPILOT_GITHUB_TOKEN`.
- Rust remains the psychometric arithmetic owner.

## Quality gates

`scripts/ci/` ships with 100% statement/branch coverage and 100%
docstrings.

## Related durable documents

- [`docs/CWL-MASTER-CONTEXT.md`](docs/CWL-MASTER-CONTEXT.md)
- [`docs/doctoring/review-inline-comment-422-fallback.md`](docs/doctoring/review-inline-comment-422-fallback.md)
- [`docs/agent-github-project-protocol.md`](docs/agent-github-project-protocol.md)
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ Semantic Versioning where the repository publishes a release.

### Fixed

- Omitted leftover 422-fallback paths that contain `-->`, `<!--`, or a suggestion fence so a leftover cannot close `<!-- opencode-review-overview -->` or reopen an applyable GitHub suggestion block (CWE-116).
- Sanitized leftover overview receipt path and phrase so a leftover cannot close `<!-- opencode-review-overview -->` or reopen a GitHub suggestion fence (CWE-116).
- Materialized base Python locks only when every package line is an exact SHA-256 pin or a bounded relative `-r`/`--requirement` include. A lone `--require-hashes` directive, a dotted include such as `./lock.txt`, or `-r other-hashes.txt` no longer enters the trusted build context.
- Stripped leftover unapplyable `` ```diff `` / `` ```patch `` fences from one-at-a-time OpenCode inline retries so leftover manual diffs cannot 422 the retry, while applyable `` ```suggestion `` fences stay on the surviving hunk.
- Capped one-at-a-time OpenCode inline retries at 20 comments and recorded leftover `path:line` rows past that cap so a batch 422 cannot open unbounded `gh api` writes.
- Kept `start_line`/`start_side` on one-at-a-time 422 retries so a multi-line GitHub suggestion still posts as one range instead of a single comment on the last line.
- After a batch GitHub 422, retried OpenCode inline comments one at a time so comments on surviving hunks still attach instead of dropping the entire review thread. Classification now requires an `HTTP 422` line, `Unprocessable Entity`, or a JSON error phrase — a `422` substring inside a SHA or issue number no longer starts that retry (CWE-1288). Receipt phrases now escape backticks and HTML metacharacters before they are written into the overview body.
- Stored each refused OpenCode inline comment as a durable overview receipt that pairs the trusted `path:line` with the GitHub 422 error phrase from `gh api` stderr or JSON `errors[].message`.
- Named each trusted `path:line` in the OpenCode GitHub 422 inline-comment fallback so a refused attach still tells the author the exact current-head location instead of a generic “cited finding lines” sentence.
- Bounded the Strix quality self-test's deterministic timeout fixtures to 3-second process and 5-second fake-sleep budgets so exact-head policy evidence completes inside the existing job limit without changing production Strix scanner timeouts, providers, credentials, or review semantics.
- Allowed commas and ASCII parentheses in the bounded Strix changed-file path policy so legal tracked Packrat fixtures can receive exact-head security analysis, while rejecting raw `..` components before normalization and keeping controls, backslashes, whitespace ambiguity, and shell punctuation fail-closed.
- Bound each review-agent invocation key to the wrapper's complete canonical payload, including the base branch and requesting actor; altered fields with a valid-format key now fail before durable-leader election or forwarding, and wrapper write permission is job-scoped.
Expand Down
3 changes: 3 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ Details: `README.md` and `PR_GOVERNANCE_AUDIT.md`.
dependency sets (see below).
- `fuzz/` + `.clusterfuzzlite/` — Atheris fuzz targets for the review-output normalizer and the
ClusterFuzzLite discovery marker.
- `ARCHITECTURE.md` — control-plane mermaid (system context, 422
classification gate, review sequence, trust boundaries). Reconstruct
from the repo, not private agent memory.
- `docs/` — master context, Project protocol, `org-required-workflow-rollout.md`,
`scorecard-governance.md`, SBOM inventory.
- `.jules/` — recorded performance (`bolt.md`) and security (`sentinel.md`) learnings from past work
Expand Down
91 changes: 91 additions & 0 deletions docs/doctoring/review-inline-comment-422-fallback.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# GitHub 422 inline-comment fallback cites trusted path:line

검토 기준일: **2026-08-13**

## Incident

When GitHub rejects an OpenCode `REQUEST_CHANGES` review because one or more
inline comments cannot attach, the publisher already falls back to a PR-level
body and does not copy suggested diffs into that body. The fallback sentence
said only “the cited finding lines.” Authors then had to open the workflow log
or control JSON to learn *which* `path:line` GitHub refused (GitHub, n.d.-a,
n.d.-b). That is weaker than the line-anchored review artifact modern code
review expects (Bacchelli & Bird, 2013).

## Decision

Leftover overview paths that contain `-->`, `<!--`, or a suggestion fence are omitted so a leftover cannot close the HTML comment.
Materialize accepts only exact SHA-256 pins or a bounded relative `-r` include; a lone `--require-hashes` line is not lock evidence.

Leftover overview receipts sanitize path and phrase; a leftover cannot close the HTML comment or reopen a suggestion fence.

`scripts/ci/opencode_inline_comment_fallback.py` reads the trusted control
JSON, keeps first-seen safe relative `path` plus positive integer `line`
pairs, and appends them to the fallback body as `` `path:line` `` list
items. Unsafe paths (`..`, absolute, drive, backslash) and non-positive
lines are omitted. An empty location set is stated explicitly.

After a refused attach, the publisher first checks that the failure is
HTTP 422, splits the batch `comments` array into at most 20
single-comment review payloads (`OPENCODE_INLINE_COMMENT_RETRY_LIMIT`,
default 20), and retries each with the same write helper. Comments past
that cap are recorded as not retried instead of opening unbounded `gh
api` writes. Leftover unapplyable `` ```diff `` / `` ```patch ``
fences are stripped from each retry body so a leftover manual diff
cannot 422 a comment that still has prose (GitHub, n.d.-a). Applyable
`` ```suggestion `` fences stay. The first success
uses `REQUEST_CHANGES` plus the review body; later successes use
`COMMENT`. Survivors therefore still appear on Files changed. Remaining
failures still rebuild the fallback from the `gh api` error file and
write durable receipts into the OpenCode overview comment
(`<!-- opencode-review-overview -->`). Each receipt is
`` `path:line` — GitHub HTTP 422: <phrase> ``. The phrase prefers JSON
`errors[].message` (for example `pull_request_review_thread.path is
invalid`) and otherwise the first `HTTP 422` line. URLs are stripped and
the phrase is bounded to 240 characters. Backticks and HTML
metacharacters are escaped before the phrase is written into the
overview body.

The publisher calls this helper from `build_inline_comment_failure_body`
with the same control object used to build the inline `comments` array.
Suggested diffs stay out of the PR-level body.

CWE-1288: classify a 422 only from an `HTTP 422` line, the
`Unprocessable Entity` reason phrase, or a JSON `errors[].message`
already rendered as `GitHub HTTP 422`. A bare `422` substring (commit
SHA, issue number) must not start the one-at-a-time retry.

## Verification contract

- `tests/test_opencode_inline_comment_fallback.py` pins safe-pair extraction,
the exact location list, GitHub JSON `errors[].message` phrases, HTTP 422
line fallback, empty-set sentence, CLI success with `--error-file`,
fail-closed unreadable control or error input, batch-to-single comment
splitting, leftover `` ```diff `` fence stripping, and
`--is-unprocessable` classification.
- `tests/test_opencode_agent_contract.py` and
`scripts/ci/test_strix_quick_gate.sh` pin the workflow call with
`$control_json`.

## Rollback

If GitHub later accepts off-diff comments, keep citing the attempted
`path:line` in the fallback. Do not restore a location-free sentence.

## References (APA 7th)

MITRE. (2026). *CWE-1288: Improper validation of syntactic correctness of
input*. https://cwe.mitre.org/data/definitions/1288.html

Bacchelli, A., & Bird, C. (2013). Expectations, outcomes, and challenges of
modern code review. In *Proceedings of the 35th International Conference on
Software Engineering* (pp. 712–721). IEEE.
https://doi.org/10.1109/ICSE.2013.6606617

GitHub. (n.d.-a). *Create a review for a pull request*. GitHub Docs. Retrieved
August 13, 2026, from
https://docs.github.com/en/rest/pulls/reviews#create-a-review-for-a-pull-request

GitHub. (n.d.-b). *Create a review comment for a pull request*. GitHub Docs.
Retrieved August 13, 2026, from
https://docs.github.com/en/rest/pulls/comments#create-a-review-comment-for-a-pull-request
Loading
Loading