<!-- task=m-iop-agent-chronos-extraction-decoupling/04+03_bundle_exporter plan=2 tag=REFACTOR milestone-task=transfer -->

# Code Review Reference - REFACTOR

> **[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-01
task=m-iop-agent-chronos-extraction-decoupling/04+03_bundle_exporter, plan=2, tag=REFACTOR

## Archive Evidence Snapshot

- `agent-task/m-iop-agent-chronos-extraction-decoupling/04+03_bundle_exporter/plan_cloud_G10_0.log`와 `code_review_cloud_G10_0.log`는 exporter, state fixture, staging 검증을 한 child에 묶었던 split 전 구상이며 implementation evidence와 verdict가 없다.
- `agent-task/m-iop-agent-chronos-extraction-decoupling/04+03_bundle_exporter/plan_cloud_G09_1.log`와 `code_review_cloud_G09_1.log`는 exporter-only 미착수 pair다. checked item, actual verification output, verdict가 없으며 pinned Git tree와 current worktree를 구분하는 검증이 부족했다.
- 승계하는 사실은 Task 03의 source revision·303행·universe/duplicate 0 근거와 D04 replan의 current-byte manifest SHA-256 `7026fedc8b0eb24eab5c4124d3818400f66db5f1d116a71e7781f346fbd256a7`·`retain-generic=137` baseline, repository-neutral `acceptance-v1` layout뿐이다.

## 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-G10.md` → `code_review_cloud_G10_2.log` and `PLAN-cloud-G10.md` → `plan_cloud_G10_2.log`.
3. If PASS, write `complete.log` and move active task directory to `agent-task/archive/YYYY/MM/m-iop-agent-chronos-extraction-decoupling/04+03_bundle_exporter/`. 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 |
|------|---------|
| REFACTOR-1 Pinned Git tree와 deterministic exporter | [x] |

## Implementation Checklist

- [x] Confirm the exact predecessor 03 PASS row/universe evidence, the D04 current-byte manifest SHA-256 baseline, and availability of the pinned source revision.
- [x] Implement the fixed-Git-tree exporter, deterministic acceptance-v1 archive, external-output confinement, quiesced state guard, quarantine, and redacted receipt contract with canonical state logical-ID count/digest.
- [x] Add and run normal, drift, missing-blob, traversal/symlink, reproducibility, live-writer, and quarantine regression tests.
- [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_G10_2.log`.
- [x] Archive active `PLAN-*-G??.md` to `plan_cloud_G10_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`.
- [ ] If PASS, write `complete.log` based on `agent-ops/skills/common/code-review/templates/complete-log-template.md` and leave no active `.md` files.
- [ ] If PASS, move active task directory `agent-task/m-iop-agent-chronos-extraction-decoupling/04+03_bundle_exporter/` to `agent-task/archive/YYYY/MM/m-iop-agent-chronos-extraction-decoupling/04+03_bundle_exporter/` 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/m-iop-agent-chronos-extraction-decoupling/` or verify it was kept due to remaining siblings/files.
- [x] If WARN/FAIL, write the next filesystem state matching code-review verdict and do not write `complete.log`.

## Deviations from Plan

None. The implementation also runs an owner-state success case, a concurrent-writer rejection case, an exact archive-digest check, and the focused race suite as additive coverage.

## Key Design Decisions

- Resolve and require the exact 40-character commit, read the complete pinned tree once with `git ls-tree`, and batch-read only manifest-selected regular blobs with `git cat-file --batch`; current HEAD and worktree bytes are never source payload inputs.
- Keep the synthetic state fixture and owner-local snapshot modes mutually exclusive. Owner mode validates owner-only roots, rejects symlinks, sockets, special files, and two-pass snapshot drift, and packages private payloads without exposing host paths or raw state in the canonical index or receipt.
- Emit byte-sorted regular tar members with fixed modes, zero identities, epoch modification times, deterministic gzip metadata, per-item SHA-256 provenance, and a self-contained stdlib-only behavior module.
- Derive all receipt state facts from the canonical `acceptance-v1/state/state-export-v1.json` bytes and records. The exact 12-key receipt remains outside the archive so `bundle_sha` can cover the final gzip bytes without a digest cycle.
- An exploratory current-input export correctly failed closed because three current manifest file rows are absent from the pinned tree: `agent-roadmap/sdd/automation-runtime-bridge/iop-agent-chronos-extraction-decoupling/user_review_0.log`, `apps/node/internal/adapters/openai_compat/protocol_profile_test.go`, and `apps/node/internal/node/protocol_profile_tunnel_test.go`. No worktree fallback was added; the actual Task 06 bundle run requires its input provenance to reconcile those rows first.

## Reviewer Checkpoints

- Source payload bytes come from the pinned Git tree, not the newer/dirty worktree.
- Archive ordering and metadata produce stable item and aggregate digests.
- Unsafe roots, traversal, symlinks, missing blobs, duplicate paths and live writers fail closed.
- State quarantine is non-resumable and receipt/log output contains no private path, credential, or raw state.
- Exporter receives a non-existing output path, creates its root with filesystem mode `0700`, and emits archive/receipt files with filesystem mode `0600`. The receipt is an exact 12-key object with no extras and includes `version=1`, JSON string `archive_mode="0600"`, `state_logical_id_count=12` and canonical sorted logical-ID SHA-256 `9bce499e286514baeb7ad9bc7c59119a3b5725f69763706dfeba06569d7404b9`; `acceptance-v1/behavior` runs without the live IOP checkout.
- Gzip tar contains exactly one regular `acceptance-v1/state/state-export-v1.json` member, no unsafe/duplicate/link entries, and receipt `state_export_sha` plus all state counts/digests are derived from that member's exact bytes/content.

## Verification Results

> Paste actual stdout/stderr for every command below. Do not summarize or reconstruct output. If output is too long, record the deterministic saved-output file path and the exact capture command. Any replacement command requires a `Deviations from Plan` entry.

### Verification 1

Command: `bash -lc 'set -euo pipefail; mapfile -t predecessor_logs < <({ test ! -f agent-task/m-iop-agent-chronos-extraction-decoupling/03+02_inventory_closure/complete.log || printf "%s\n" agent-task/m-iop-agent-chronos-extraction-decoupling/03+02_inventory_closure/complete.log; find agent-task/archive -path "*/m-iop-agent-chronos-extraction-decoupling/03+02_inventory_closure/complete.log" -type f -print 2>/dev/null; } | sort -u); test "${#predecessor_logs[@]}" -eq 1; awk '\''BEGIN {in_summary=0; count=0} /^## Summary$/ {in_summary=1; next} in_summary && /^## / {in_summary=0} in_summary {line=$0; while (match(line, /final verdict: PASS/)) {count++; line=substr(line, RSTART+RLENGTH)}} END {exit count==1 ? 0 : 1}'\'' "${predecessor_logs[0]}"'`

_Actual stdout/stderr and exit code (or exact saved-output path and capture command):_

```text
(no stdout/stderr)
exit code: 0
```

### Verification 2

Command: `test "$(sha256sum scripts/fixtures/iop-agent-chronos-ownership-manifest.tsv | awk '{print $1}')" = 7026fedc8b0eb24eab5c4124d3818400f66db5f1d116a71e7781f346fbd256a7`

_Actual stdout/stderr and exit code (or exact saved-output path and capture command):_

```text
(no stdout/stderr)
exit code: 0
```

### Verification 3

Command: `git cat-file -e 3155be0e275437a8eedc1aa93497955a7d30465b^{commit} && test "$(git rev-parse HEAD)" != 3155be0e275437a8eedc1aa93497955a7d30465b`

_Actual stdout/stderr and exit code (or exact saved-output path and capture command):_

```text
(no stdout/stderr)
exit code: 0
```

### Verification 4

Command: `go test -count=1 ./cmd/iop-chronos-transfer`

_Actual stdout/stderr and exit code (or exact saved-output path and capture command):_

```text
ok  	iop/cmd/iop-chronos-transfer	2.900s
exit code: 0
```

### Verification 5

Command: `go vet ./cmd/iop-chronos-transfer`

_Actual stdout/stderr and exit code (or exact saved-output path and capture command):_

```text
(no stdout/stderr)
exit code: 0
```

---

> **[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: FAIL
- Dimension Assessment:
  - Correctness: Fail
  - Completeness: Fail
  - Test coverage: Fail
  - API contract: Fail
  - Code quality: Pass
  - Implementation deviation: Fail
  - Verification trust: Pass
  - Spec conformance: Fail
- Findings:
  - Required — `cmd/iop-chronos-transfer/main.go:729`: owner-state export assigns every logical ID except config/overlay/log/cache/temp to the same aggregate `state-root` digest and size, then marks six of those aliases resumable while marking the same bytes as `state:broken-residual-records` quarantine. The current owner-state success test even supplies arbitrary unvalidated state bytes, so the archive cannot prove which payload is a valid manager checkpoint, ledger, lease, registration, recovery locator, or broken residual and can present unowned/corrupt bytes as resumable, contrary to SDD D01 and the planned quarantine contract. Classify captured owner payloads into disjoint logical records using their actual durable-store identities, emit an exact payload member/digest/size for each record, route unknown or invalid residuals only to non-resumable quarantine, and add a regression that mixes valid and corrupt owner records and proves no payload appears in both resumable and quarantine sets.
  - Required — `cmd/iop-chronos-transfer/main.go:332`: shared-workspace confinement is enforced only when the repository parent is literally named `workspace` or already contains a `chronos` directory. A checkout such as `/srv/product/iop` therefore permits `/srv/product/private-output` before the Chronos sibling exists, violating the plan's requirement that output remain outside the repository/workspace/Chronos checkout. Derive or accept a canonical workspace boundary without basename/sibling heuristics, reject every output below it, and add coverage using an arbitrary workspace basename with no Chronos sibling.
- Routing Signals: `review_rework_count=1`, `evidence_integrity_failure=false`
- Next Step: Prepare and validate a freshly routed follow-up PLAN/CODE_REVIEW pair for the two Required fixes, then archive this active pair and materialize the routed follow-up state.
