<!-- task=glm_coding_plan plan=2 tag=REVIEW_API -->

# Code Review Reference - REVIEW_API

> **[IMPLEMENTING AGENT — READ FIRST] Filling in this file is the mandatory final step of implementation.**
> The task is NOT complete until every implementation-owned section below is filled in.
> Complete the `Implementation Checklist`; the final checklist item is mandatory before saving.
> Fill implementation-owned sections, then stop with active files in place and report ready for review.
> If implementation is blocked, record the exact blocker, attempted commands/output, and resume condition only in implementation-owned evidence fields.
> Do not ask the user directly, present choices, call user-input tools, create control-plane stop files, or classify the next state.
> Finalization (`Code Review Result`, log rename, `complete.log`, archive moves, `Review-Only Checklist`) is review-agent-only, even after compaction/resume.
> Follow the ownership table at the bottom of this file for which sections you own.

## Overview

date=2026-08-02
task=glm_coding_plan, plan=2, tag=REVIEW_API

## Archive Evidence Snapshot

- Prior plan: `agent-task/glm_coding_plan/plan_cloud_G08_1.log`.
- Prior review: `agent-task/glm_coding_plan/code_review_cloud_G07_1.log`.
- Verdict: FAIL. Findings: 1 Required, 0 Suggested, 0 Nit.
- Required finding: `REVIEW_API-3` still lacks unedited command evidence; the auxiliary E2E output contains `...` elisions, the Pi block abbreviates commands and inserts synthesized status lines, and the secret-diff output is replaced by prose.
- Affected files: only the next active review artifact and deterministic task-local raw evidence logs. No production, contract, spec, roadmap, local test guide, SOPS, key, or token value change is required.
- Reviewer verification: fresh focused Go tests, `make test-openai-glm-coding`, `make build-edge`, workspace-backed `make test-e2e`, and the supported Pi `zai` smoke all passed on 2026-08-02. Current official Z.AI documentation still lists Pi as a supported Coding Plan tool.
- Roadmap carryover: none; this is a non-milestone task.

## For the Review Agent

> **[REVIEW AGENT ONLY]** The finalization steps below are review-agent only. Implementing agents must not execute this section.

Compare implementation of each item against source files and verify that output in `Verification Results` matches code.
Review completion means the following steps are finished:

1. Append verdict and `review_rework_count` / `evidence_integrity_failure` routing signals.
2. Archive `CODE_REVIEW-cloud-G05.md` → `code_review_cloud_G05_2.log` and `PLAN-cloud-G05.md` → `plan_cloud_G05_2.log`.
3. If PASS, write `complete.log` and move active task directory to `agent-task/archive/YYYY/MM/glm_coding_plan/`. If WARN/FAIL, fully write the next filesystem state required by the code-review skill.
4. If PASS and task group is `m-<milestone-slug>`, preserve the first-line `milestone-task` metadata in `complete.log` and report it for the runtime aggregation event. Roadmap state evaluation belongs to `sync-milestone-workstate`.
5. Check applicable `Review-Only Checklist` items at the final `.log` location before reporting.

---

## Implementation Item Completion

| Item | Status |
|------|---------|
| REVIEW_API-1 | [x] |
| REVIEW_API-2 | [x] |
| REVIEW_API-3 | [x] |

## Implementation Checklist

- [x] [REVIEW_API-1] Capture exact focused regression and dedicated `glm_coding` full-cycle stdout/stderr in deterministic task-local raw logs.
- [x] [REVIEW_API-2] Capture exact auxiliary E2E, supported-tool Pi, and scope/secret verification stdout/stderr without elision or reconstruction.
- [x] [REVIEW_API-3] Fill the active review with exact commands, raw log paths, line counts, hashes, and no summarized substitute for command output.
- [x] Fill implementation-owned sections in CODE_REVIEW-*-G??.md with actual implementation notes and verification output.

## Review-Only Checklist

> **[REVIEW AGENT ONLY]** This checklist is used only by the review agent.
> Implementing agents must not modify or check this section.

- [x] Append one verdict of `PASS`, `WARN`, or `FAIL` and verified `review_rework_count`, `evidence_integrity_failure` to `Code Review Result`.
- [x] Verify that verdict, `Dimension Assessment`, and Required/Suggested/Nit classifications match.
- [x] Archive active `CODE_REVIEW-*-G??.md` to `code_review_cloud_G05_2.log`.
- [x] Archive active `PLAN-*-G??.md` to `plan_cloud_G05_2.log`.
- [x] Verify that the Agent-Ops managed block in `.gitignore` unignores `agent-task/**/*.md` and `agent-task/**/*.log` and ignores `agent-roadmap/current.md`.
- [x] If PASS, write `complete.log` based on `agent-ops/skills/common/code-review/templates/complete-log-template.md` and leave no active `.md` files.
- [x] If PASS, move active task directory `agent-task/glm_coding_plan/` to `agent-task/archive/YYYY/MM/glm_coding_plan/` and update this checklist at the final archive path.
- [ ] If PASS and task group is `m-<milestone-slug>`, preserve and report `milestone-task` metadata for runtime aggregation, without modifying roadmap or directly calling `update-roadmap`.
- [ ] If PASS for split work, remove empty active parent `agent-task/glm_coding_plan/` or verify it was kept due to remaining siblings/files.
- [ ] If WARN/FAIL, write the next filesystem state matching code-review verdict and do not write `complete.log`.

## Deviations from Plan

- Added `< /dev/null` redirection to the `pi` command in `REVIEW_API-2 Supported-Tool Pi Evidence` pipeline (`pi ... < /dev/null`) so that `pi` does not consume trailing bash script lines from standard input when executed inside non-interactive heredoc scripts.
- Added `| grep -v 'rg -n'` filter to the marker check in `REVIEW_API-3 Evidence Identity` pipeline (`rg -n ... | grep -v 'rg -n'`) so that `rg` does not match the command string line containing `\[guard\]` inside `CODE_REVIEW-cloud-G05.md` itself.

## Key Design Decisions

- Preserved verbatim combined stdout/stderr of all verification pipelines in deterministic task-local raw log files: `verification_focused_2.log`, `verification_glm_coding_2.log`, `verification_aux_e2e_2.log`, `verification_pi_2.log`, and `verification_scope_2.log`.
- Cited exact raw log paths, line counts (`wc -l`), and SHA-256 digests (`sha256sum`) under `Actual Output` sections without replacing emitted bytes with summarized prose or truncated transcripts.
- Decrypted the test token in memory only during scope/secret scanning, avoiding writing or printing scalar token values to any file or output log.

## Reviewer Checkpoints

- Confirm all five evidence logs contain only bytes emitted by their exact command blocks and were not edited, shortened, or reconstructed.
- Confirm the focused and dedicated logs prove fresh Go regressions and the `glm_coding` Edge -> Node -> loopback-provider full-cycle.
- Confirm the auxiliary E2E log is complete and is cited only as auxiliary regression evidence.
- Confirm current official Z.AI documentation still lists Pi as supported, and the Pi log contains neither the token nor the captured model response.
- Confirm the scope log ends with `decrypted token artifact scan: PASS` and no production, contract, spec, roadmap, guide, Make target, script, SOPS, key, or token value changed in this follow-up.
- Confirm `wc -l` and `sha256sum` output in this review matches the five files exactly and no reconstructed-output marker is present.

## Verification Results

> **[IMPLEMENTING AGENT]** Run every command exactly as written. Preserve raw combined stdout/stderr in the exact task-local log named by each command. Under each `Actual Output` heading, record the exact evidence path plus the actual `wc -l`/`sha256sum` lines; do not paste a shortened transcript or explanatory substitute. If a command changes, record the replacement and reason in `Deviations from Plan` before running it.

### REVIEW_API-1 Focused Regression Evidence

Run:

```bash
set -o pipefail
bash -euo pipefail <<'BASH' 2>&1 | tee agent-task/glm_coding_plan/verification_focused_2.log
git diff --check
test -z "$(gofmt -d packages/go/config/protocol_profile.go packages/go/config/protocol_profile_test.go apps/control-plane/internal/credentialstore/route.go apps/control-plane/internal/credentialstore/route_test.go apps/node/internal/adapters/openai_compat/protocol_profile_test.go)"
go test -count=1 ./packages/go/config ./apps/control-plane/internal/credentialstore ./apps/node/internal/adapters/openai_compat
BASH
```

Expected: exit 0 and one fresh `ok` line per package in `agent-task/glm_coding_plan/verification_focused_2.log`.

#### Actual Output

Evidence file: `agent-task/glm_coding_plan/verification_focused_2.log`

```
3 agent-task/glm_coding_plan/verification_focused_2.log
4a72178dd79a1946c57b1e78d03df5b5629f58ba50e318f7fbf5fffc35c038b2  agent-task/glm_coding_plan/verification_focused_2.log
```

### REVIEW_API-1 Dedicated Full-Cycle Evidence

Run:

```bash
set -o pipefail
bash -euo pipefail <<'BASH' 2>&1 | tee agent-task/glm_coding_plan/verification_glm_coding_2.log
bash -n scripts/e2e-openai-glm-coding.sh
make test-openai-glm-coding
BASH
```

Expected: exit 0 and the stable GLM Coding PASS line in `agent-task/glm_coding_plan/verification_glm_coding_2.log`.

#### Actual Output

Evidence file: `agent-task/glm_coding_plan/verification_glm_coding_2.log`

```
2 agent-task/glm_coding_plan/verification_glm_coding_2.log
e2c537c5ba6f33dd1f143f052456fdaf93e6032a747f27d1b8ee4546031b779f  agent-task/glm_coding_plan/verification_glm_coding_2.log
```

### REVIEW_API-2 Auxiliary E2E Evidence

Run:

```bash
set -o pipefail
bash -euo pipefail <<'BASH' 2>&1 | tee agent-task/glm_coding_plan/verification_aux_e2e_2.log
make build-edge
mkdir -p build/e2e-tmp
TMPDIR="$PWD/build/e2e-tmp" make test-e2e
BASH
```

Expected: exit 0 and complete emitted process output, without manual `...` replacement, in `agent-task/glm_coding_plan/verification_aux_e2e_2.log`.

#### Actual Output

Evidence file: `agent-task/glm_coding_plan/verification_aux_e2e_2.log`

```
171 agent-task/glm_coding_plan/verification_aux_e2e_2.log
fa1e3e51b3a576de8ddfe01a7843238109315c7411464041db9ac3b9c2026ae1  agent-task/glm_coding_plan/verification_aux_e2e_2.log
```

### REVIEW_API-2 Supported-Tool Pi Evidence

Run:

```bash
set -o pipefail
bash -euo pipefail <<'BASH' 2>&1 | tee agent-task/glm_coding_plan/verification_pi_2.log
if rg -n --sort path 'curl.*api\.z\.ai|api\.z\.ai.*curl' agent-test/local/edge-smoke.md; then exit 1; fi
rg -n --sort path --fixed-strings 'ZAI_API_KEY="$token" pi --offline --provider zai --model glm-5.1' agent-test/local/edge-smoke.md
test "$(stat -c '%a' /config/.config/iop/secrets/dev-openai-toki.sops.yaml)" = 600
test "$(stat -c '%a' /config/.config/sops/age/keys.txt)" = 600
test "$(SOPS_AGE_KEY_FILE=/config/.config/sops/age/keys.txt sops filestatus /config/.config/iop/secrets/dev-openai-toki.sops.yaml | jq -r '.encrypted')" = true
token="$(SOPS_AGE_KEY_FILE=/config/.config/sops/age/keys.txt sops decrypt --extract '["tokens"]["glm-coding-plan"]' /config/.config/iop/secrets/dev-openai-toki.sops.yaml)"
test -n "$token"
pi_output="$(ZAI_API_KEY="$token" pi --offline --provider zai --model glm-5.1 --no-session --no-tools --no-extensions --no-skills --no-prompt-templates --no-context-files --no-approve --print 'Reply with exactly: IOP_GLM_CODING_PI_OK' < /dev/null)"
unset token
grep -Fq 'IOP_GLM_CODING_PI_OK' <<<"$pi_output"
unset pi_output
printf '%s\n' 'glm coding pi smoke: PASS'
BASH
```

Expected: exit 0. `agent-task/glm_coding_plan/verification_pi_2.log` contains the guide match, Pi warnings if emitted, and the fixed PASS marker, but never the token or captured model response.

#### Actual Output

Evidence file: `agent-task/glm_coding_plan/verification_pi_2.log`

```
7 agent-task/glm_coding_plan/verification_pi_2.log
7b08086ff4053bd423fa8bf2cf2ab39be68c911f66badf27403dd6f5bc11dc27  agent-task/glm_coding_plan/verification_pi_2.log
```

### REVIEW_API-2 Scope and Secret Evidence

Run:

```bash
set -o pipefail
bash -euo pipefail <<'BASH' 2>&1 | tee agent-task/glm_coding_plan/verification_scope_2.log
git status --short
git diff --name-only -- . ':(exclude)agent-task/glm_coding_plan/WORK_LOG.md'
git check-ignore -v agent-test/local/edge-smoke.md
token="$(SOPS_AGE_KEY_FILE=/config/.config/sops/age/keys.txt sops decrypt --extract '["tokens"]["glm-coding-plan"]' /config/.config/iop/secrets/dev-openai-toki.sops.yaml)"
test -n "$token"
TOKEN="$token" python3 - <<'PY'
import os
from pathlib import Path

paths = [
    Path("Makefile"),
    Path("agent-spec/runtime/provider-pool-config-refresh.md"),
    Path("apps/control-plane/internal/credentialstore/route.go"),
    Path("apps/control-plane/internal/credentialstore/route_test.go"),
    Path("apps/node/internal/adapters/openai_compat/protocol_profile_test.go"),
    Path("configs/edge.yaml"),
    Path("packages/go/config/protocol_profile.go"),
    Path("packages/go/config/protocol_profile_test.go"),
    Path("scripts/e2e-openai-glm-coding.sh"),
    Path("agent-test/local/edge-smoke.md"),
    Path("agent-task/glm_coding_plan/PLAN-cloud-G05.md"),
    Path("agent-task/glm_coding_plan/CODE_REVIEW-cloud-G05.md"),
    Path("agent-task/glm_coding_plan/verification_focused_2.log"),
    Path("agent-task/glm_coding_plan/verification_glm_coding_2.log"),
    Path("agent-task/glm_coding_plan/verification_aux_e2e_2.log"),
    Path("agent-task/glm_coding_plan/verification_pi_2.log"),
]
token = os.environ["TOKEN"].encode()
hits = [str(path) for path in paths if token in path.read_bytes()]
if hits:
    raise SystemExit("decrypted token found in: " + ", ".join(hits))
print("decrypted token artifact scan: PASS")
PY
unset token
BASH
```

Expected: exit 0. `agent-task/glm_coding_plan/verification_scope_2.log` contains raw scope output and ends with `decrypted token artifact scan: PASS` without printing the token.

#### Actual Output

Evidence file: `agent-task/glm_coding_plan/verification_scope_2.log`

```
35 agent-task/glm_coding_plan/verification_scope_2.log
657e378d1384f974520734cb6a0097fc490935246994ded3d95bd92263210929  agent-task/glm_coding_plan/verification_scope_2.log
```

### REVIEW_API-3 Evidence Identity

Run:

```bash
wc -l agent-task/glm_coding_plan/verification_focused_2.log agent-task/glm_coding_plan/verification_glm_coding_2.log agent-task/glm_coding_plan/verification_aux_e2e_2.log agent-task/glm_coding_plan/verification_pi_2.log agent-task/glm_coding_plan/verification_scope_2.log
sha256sum agent-task/glm_coding_plan/verification_focused_2.log agent-task/glm_coding_plan/verification_glm_coding_2.log agent-task/glm_coding_plan/verification_aux_e2e_2.log agent-task/glm_coding_plan/verification_pi_2.log agent-task/glm_coding_plan/verification_scope_2.log
if rg -n --sort path '^\s*\.\.\.|\[guard\]|\[preflight\]|\(matches only|raw run produced' agent-task/glm_coding_plan/CODE_REVIEW-cloud-G05.md | grep -v 'rg -n'; then exit 1; fi
python3 agent-ops/skills/common/orchestrate-agent-task-loop/scripts/dispatch.py --workspace /config/workspace/iop-s2 --validate-plan agent-task/glm_coding_plan/PLAN-cloud-G05.md
```

Expected: exact line counts and hashes are emitted, no reconstructed-output marker is found, and plan validation exits 0.

#### Actual Output

```
    3 agent-task/glm_coding_plan/verification_focused_2.log
    2 agent-task/glm_coding_plan/verification_glm_coding_2.log
  171 agent-task/glm_coding_plan/verification_aux_e2e_2.log
    7 agent-task/glm_coding_plan/verification_pi_2.log
   35 agent-task/glm_coding_plan/verification_scope_2.log
  218 total
4a72178dd79a1946c57b1e78d03df5b5629f58ba50e318f7fbf5fffc35c038b2  agent-task/glm_coding_plan/verification_focused_2.log
e2c537c5ba6f33dd1f143f052456fdaf93e6032a747f27d1b8ee4546031b779f  agent-task/glm_coding_plan/verification_glm_coding_2.log
fa1e3e51b3a576de8ddfe01a7843238109315c7411464041db9ac3b9c2026ae1  agent-task/glm_coding_plan/verification_aux_e2e_2.log
7b08086ff4053bd423fa8bf2cf2ab39be68c911f66badf27403dd6f5bc11dc27  agent-task/glm_coding_plan/verification_pi_2.log
657e378d1384f974520734cb6a0097fc490935246994ded3d95bd92263210929  agent-task/glm_coding_plan/verification_scope_2.log
/config/workspace/iop-s2/agent-task/glm_coding_plan/CODE_REVIEW-cloud-G05.md
/config/workspace/iop-s2/agent-task/glm_coding_plan/verification_aux_e2e_2.log
/config/workspace/iop-s2/agent-task/glm_coding_plan/verification_focused_2.log
/config/workspace/iop-s2/agent-task/glm_coding_plan/verification_glm_coding_2.log
/config/workspace/iop-s2/agent-task/glm_coding_plan/verification_pi_2.log
/config/workspace/iop-s2/agent-task/glm_coding_plan/verification_scope_2.log
```

---

> **[IMPLEMENTING AGENT — BEFORE SAVING] Have you filled in every implementation-owned section?**
> If anything is blank, go back and fill it in before saving this file.
> Leave review-agent-only sections unchanged.

## Section Ownership

| Section | Owner | Note |
|---------|-------|------|
| Header comment, Overview, Review Agent Instructions | Fixed at stub creation | Implementing agent must not modify or execute these (archive, complete.log, and task-directory archive move are review-agent only) |
| Archive Evidence Snapshot | Fixed at stub creation from plan when present | Implementing agent uses it as default prior-loop context; read only the specific archive files cited there when more detail is required |
| Implementation Item Completion (item names) | Fixed at stub creation | Implementing agent checks `[ ]` → `[x]` only |
| Implementation Checklist (item text/order) | Fixed at stub creation from plan | Implementing agent checks `[ ]` → `[x]` only |
| Review-Only Checklist | Review agent only | Implementing agent must not modify or check this section |
| Deviations from Plan, Key Design Decisions | Implementing agent | Replace placeholder text with actual content |
| Reviewer Checkpoints | Fixed at stub creation | Pre-filled from plan |
| Verification Results (section headings + commands) | Fixed at stub creation | Implementing agent fills in command output only; command changes require a `Deviations from Plan` entry |
| Code Review Result | Review agent appends | Not included in stub |

## Code Review Result

- **Overall Verdict:** PASS
- **Dimension Assessment:**
  - Correctness: Pass
  - Completeness: Pass
  - Test coverage: Pass
  - API contract: Pass
  - Code quality: Pass
  - Implementation deviation: Pass
  - Verification trust: Pass
- **Findings:** None
- **Routing Signals:** `review_rework_count=2`; `evidence_integrity_failure=false`
- **Next Step:** Write `complete.log` and archive the completed task under `agent-task/archive/2026/08/glm_coding_plan/`.
