<!-- task=m-iop-agent-chronos-extraction-decoupling/03+02_inventory_closure plan=1 tag=REVIEW_TEST -->

# Close the logical state ownership inventory

## For the Implementing Agent

Filling the implementation-owned sections of `CODE_REVIEW-cloud-G04.md` is mandatory. Implement only this follow-up scope, run every verification command exactly, paste actual output, keep the active pair in place, and report ready for review. Finalization belongs to the code-review agent. If blocked, record the exact blocker, attempted commands/output, and resume condition only in implementation-owned evidence fields; do not ask the user, call user-input tools, create control-plane stop files, classify the next state, archive logs, or write `complete.log`.

## Background

The first closure proved exact equality for 293 repository paths, but its state check passed with zero logical state rows. The selected Milestone and approved SDD explicitly require existing registration, configuration, durable runtime, recovery, log, and client-process state in the ownership/disposition manifest. This follow-up adds the contract-derived state universe and makes an empty or partial state inventory fail deterministically.

## Archive Evidence Snapshot

- Prior task path: `agent-task/m-iop-agent-chronos-extraction-decoupling/03+02_inventory_closure`
- Prior plan: `agent-task/m-iop-agent-chronos-extraction-decoupling/03+02_inventory_closure/plan_local_G04_0.log`
- Prior review: `agent-task/m-iop-agent-chronos-extraction-decoupling/03+02_inventory_closure/code_review_cloud_G04_0.log`
- Verdict: FAIL; Required=1, Suggested=0, Nit=0.
- Required finding: the 293 filesystem rows are complete, but `logical_state_rows=0` and `kind_state_rows=0`; the prior naming-only state check succeeds vacuously.
- Verified retained evidence: predecessor `02+01_disposition` is PASS; repository path universe and manifest path set both contain 293 rows with `missing=0`, `orphans=0`, and `duplicates=0`.
- Roadmap carryover: SDD S01 and Milestone Task `inventory` remain incomplete until the full file and logical-state ownership surfaces pass together.

## Roadmap Targets

- Milestone: `agent-roadmap/phase/automation-runtime-bridge/milestones/iop-agent-chronos-extraction-decoupling.md`
- Milestone link: [Milestone document](agent-roadmap/phase/automation-runtime-bridge/milestones/iop-agent-chronos-extraction-decoupling.md)
- Task ids:
  - `inventory`: fix the source revision and complete the ownership/disposition manifest for every active asset
- Completion mode: check-on-pass

## Analysis

### Files Read

- `agent-roadmap/phase/automation-runtime-bridge/PHASE.md`
- `agent-roadmap/phase/automation-runtime-bridge/milestones/iop-agent-chronos-extraction-decoupling.md`
- `agent-roadmap/sdd/automation-runtime-bridge/iop-agent-chronos-extraction-decoupling/SDD.md`
- `agent-contract/index.md`
- `agent-contract/inner/iop-agent-cli-runtime.md`
- `agent-contract/inner/agent-runtime.md`
- `agent-spec/index.md`
- `agent-spec/runtime/iop-agent-cli-runtime.md`
- `scripts/fixtures/iop-agent-chronos-ownership-manifest.tsv`
- `agent-task/m-iop-agent-chronos-extraction-decoupling/03+02_inventory_closure/inventory-audit.log`
- `agent-task/m-iop-agent-chronos-extraction-decoupling/03+02_inventory_closure/PLAN-local-G04.md`
- `agent-task/m-iop-agent-chronos-extraction-decoupling/03+02_inventory_closure/CODE_REVIEW-cloud-G04.md`
- `agent-task/archive/2026/08/m-iop-agent-chronos-extraction-decoupling/02+01_disposition/complete.log`
- `agent-ops/rules/project/domain/testing/rules.md`
- `agent-test/local/rules.md`
- `agent-test/local/testing-smoke.md`

### SDD Criteria

- The approved and unlocked SDD is `agent-roadmap/sdd/automation-runtime-bridge/iop-agent-chronos-extraction-decoupling/SDD.md`.
- Target S01 maps to Milestone Task `inventory`; its Evidence Map requires the source revision, import graph, disposition audit, and a manifest connecting every related asset to transfer/removal without a duplicate generic owner.
- Milestone lines 40 and 50 explicitly include `state`, and the runtime contract lines 56-87 define the host-owned configuration, registrations, manager checkpoint, leases, recovery locators, workspace records, logs, ledgers, and client-process records that shape the exact state checklist below.

### Verification Context

- No handoff was supplied. Repository-native evidence is the approved SDD, the two runtime contracts, the current TSV, the prior FAIL review, and the exact archived predecessor `complete.log`.
- Fresh review commands confirmed `universe_paths=293`, `manifest_paths=293`, `missing=0`, `orphans=0`, `duplicates=0`, but also `logical_state_rows=0`, `kind_state_rows=0`, `expected_states=10`, and `missing_states=10`.
- Verification is local, deterministic, secret-free, and does not launch `iop-agent`, a provider, a remote runner, or any external service. Confidence is high.

### Test Coverage Gaps

- No product behavior changes. The regression oracle is the manifest audit itself.
- The current state test only validates naming for rows that already exist; it does not assert a non-empty or exact contract-derived state universe.

### Symbol References

- None. No source symbol changes are planned.

### Split Judgment

- Keep one compact follow-up because the manifest rows and their audit are one completeness invariant and cannot independently PASS.
- Directory dependency `+02` is satisfied by `agent-task/archive/2026/08/m-iop-agent-chronos-extraction-decoupling/02+01_disposition/complete.log`, whose final verdict is PASS.

### Scope Rationale

- Change only the ownership manifest, deterministic audit evidence, and active review evidence.
- Do not modify runtime code, contracts, specs, roadmap documents, Chronos, or device-local state. This task inventories state families; later transfer tasks own export implementation and data movement.

### Final Routing

- `evaluation_mode=isolated-reassessment`; finalizer=`finalize-task-policy.sh`, mode=`pair`.
- Build closures are all true. Scores=`1,0,0,2,1`, grade=`G04`, base=`local-fit`, final route=`recovery-boundary`, lane=`cloud`.
- Review closures are all true. Scores=`1,0,0,2,1`, route=`official-review`, lane=`cloud`, grade=`G04`.
- `large_indivisible_context=false`; positive loop risks=`boundary_contract` (1); `review_rework_count=1`; `evidence_integrity_failure=true`; no capability gap.
- Canonical files: `PLAN-cloud-G04.md`, `CODE_REVIEW-cloud-G04.md`.

## Dependencies and Execution Order

1. Preserve the PASS predecessor at `agent-task/archive/2026/08/m-iop-agent-chronos-extraction-decoupling/02+01_disposition/complete.log`.
2. Add the exact logical state rows, then regenerate the combined path/state audit evidence.

## Implementation Checklist

- [ ] Add all ten contract-derived logical state families to the ownership manifest with exact transfer/remove mappings and S01/S02/S03/S05 evidence.
- [ ] Replace the vacuous state check with an exact non-empty bidirectional state-universe oracle and record fresh combined path/state audit output in `inventory-audit.log`.
- [ ] Fill implementation-owned sections in CODE_REVIEW-*-G??.md with actual implementation notes and verification output.

### [REVIEW_TEST-1] Inventory and verify device-local state families

**Problem**

The TSV schema at `scripts/fixtures/iop-agent-chronos-ownership-manifest.tsv:1` has no logical state rows. The check at `agent-task/m-iop-agent-chronos-extraction-decoupling/03+02_inventory_closure/CODE_REVIEW-cloud-G04.md:155` only rejects malformed rows that already exist, so an empty state inventory passes despite the Milestone and SDD state requirement.

```text
# before: current audit evidence
logical_state_rows=0
kind_state_rows=0
expected_states=10
missing_states=10
```

**Solution**

Append the sorted, contract-derived logical state universe. Every row uses `kind=state`, `disposition=transfer`, `bundle_path=legacy-state/<state-name>`, `iop_action=remove`, `neutral_successor=-`, and `evidence_map=S01,S02,S03,S05`. Extend the evidence log with an exact expected-state list, bidirectional difference counts, and the combined seven-field/disposition audit.

```text
# after: exact logical state keys
state:broken-residual-records
state:client-process-records
state:device-and-resource-leases
state:local-control-ledger
state:manager-checkpoint
state:process-session-recovery-locators
state:project-registrations
state:project-work-logs
state:user-local-runtime-config
state:workspace-overlay-change-set-integration-records
```

**Modified Files and Checklist**

- [ ] `scripts/fixtures/iop-agent-chronos-ownership-manifest.tsv` — add the ten sorted logical state rows with exact bundle/action/evidence mappings.
- [ ] `agent-task/m-iop-agent-chronos-extraction-decoupling/03+02_inventory_closure/inventory-audit.log` — replace the state-only naming result with exact path/state universe, structural, and disposition output.
- [ ] `agent-task/m-iop-agent-chronos-extraction-decoupling/03+02_inventory_closure/CODE_REVIEW-cloud-G04.md` — record actual implementation decisions and command output.

**Test Strategy**

No product test file is added because this changes a data manifest and its deterministic evidence artifact only. The regression is an exact expected-state set comparison plus the existing fixed-revision path comparison; both directions, counts, row structure, dispositions, bundle paths, and evidence maps must pass.

**Verification**

- Run the exact logical-state universe command from Final Verification 2; expect `expected_states=10 actual_states=10 missing_states=0 orphan_states=0`.
- Run the structural/disposition command from Final Verification 3; expect `rows=303 file_rows=293 state_rows=10` and every `bad_*` counter to be zero.

## Modified Files Summary

| File | Item |
|------|------|
| `scripts/fixtures/iop-agent-chronos-ownership-manifest.tsv` | REVIEW_TEST-1 |
| `agent-task/m-iop-agent-chronos-extraction-decoupling/03+02_inventory_closure/inventory-audit.log` | REVIEW_TEST-1 |
| `agent-task/m-iop-agent-chronos-extraction-decoupling/03+02_inventory_closure/CODE_REVIEW-cloud-G04.md` | REVIEW_TEST-1 |

## Final Verification

1. `awk 'BEGIN {in_summary=0} /^## Summary$/ {in_summary=1; next} in_summary && /final verdict: PASS/ {found=1} END {printf "predecessor_exact_pass=%d\n", found+0; exit found?0:1}' agent-task/archive/2026/08/m-iop-agent-chronos-extraction-decoupling/02+01_disposition/complete.log`
2. `printf '%s\n' 'state:broken-residual-records' 'state:client-process-records' 'state:device-and-resource-leases' 'state:local-control-ledger' 'state:manager-checkpoint' 'state:process-session-recovery-locators' 'state:project-registrations' 'state:project-work-logs' 'state:user-local-runtime-config' 'state:workspace-overlay-change-set-integration-records' > /tmp/iop-agent-expected-state-universe.txt && awk -F '\t' 'NR>1 && $2=="state" {print $1}' scripts/fixtures/iop-agent-chronos-ownership-manifest.tsv | LC_ALL=C sort -u > /tmp/iop-agent-manifest-state-universe.txt && expected_states=$(wc -l < /tmp/iop-agent-expected-state-universe.txt) && actual_states=$(wc -l < /tmp/iop-agent-manifest-state-universe.txt) && missing_states=$(comm -23 /tmp/iop-agent-expected-state-universe.txt /tmp/iop-agent-manifest-state-universe.txt | wc -l) && orphan_states=$(comm -13 /tmp/iop-agent-expected-state-universe.txt /tmp/iop-agent-manifest-state-universe.txt | wc -l) && printf 'expected_states=%s actual_states=%s missing_states=%s orphan_states=%s\n' "$expected_states" "$actual_states" "$missing_states" "$orphan_states" && test "$expected_states" -eq 10 && test "$actual_states" -eq 10 && test "$missing_states" -eq 0 && test "$orphan_states" -eq 0`
3. `awk -F '\t' 'NR==1 {if ($0!="path\tkind\tdisposition\tbundle_path\tiop_action\tneutral_successor\tevidence_map") bad_header++; next} {rows++; path_state=($1~/^state:/); kind_state=($2=="state"); if (NF!=7) bad_fields++; if (path_state!=kind_state) bad_state_pair++; if ($7!~/(^|,)S01(,|$)/) missing_s01++; if (kind_state) {state_rows++; name=$1; sub(/^state:/,"",name); if ($3!="transfer" || $4!="legacy-state/" name || $5!="remove" || $6!="-" || $7!="S01,S02,S03,S05") bad_state_contract++} else {file_rows++; if ($4!="source/" $1) bad_bundle++; if ($3=="transfer" && ($5!="remove" || $6!="-")) bad_pair++; else if ($3=="retain-generic" && (($5!="rewrite" && $5!="rename") || $6=="-")) bad_pair++; else if ($3=="reference" && ($5!="none" || $6!="-")) bad_pair++; else if ($3!="transfer" && $3!="retain-generic" && $3!="reference") bad_disposition++}} END {printf "rows=%d file_rows=%d state_rows=%d bad_header=%d bad_fields=%d bad_state_pair=%d bad_state_contract=%d bad_bundle=%d bad_pair=%d bad_disposition=%d missing_s01=%d\n",rows,file_rows,state_rows,bad_header+0,bad_fields+0,bad_state_pair+0,bad_state_contract+0,bad_bundle+0,bad_pair+0,bad_disposition+0,missing_s01+0; exit(rows!=303 || file_rows!=293 || state_rows!=10 || bad_header || bad_fields || bad_state_pair || bad_state_contract || bad_bundle || bad_pair || bad_disposition || missing_s01)}' scripts/fixtures/iop-agent-chronos-ownership-manifest.tsv`
4. `{ git ls-tree -r --name-only 3155be0e275437a8eedc1aa93497955a7d30465b -- apps/agent cmd/iop-provider-smoke packages/go/agentconfig packages/go/agentguard packages/go/agentpolicy packages/go/agentprovider packages/go/agentruntime packages/go/agentstate packages/go/agenttask packages/go/agentworkspace proto/iop/agent.proto proto/gen/iop/agent.pb.go configs/iop-agent.local.example.yaml configs/iop-agent.providers.yaml configs/iop-agent.runtime.yaml scripts/e2e-iop-agent-logged-smoke.sh scripts/fixtures/iop-agent-smoke-manifest.schema.json packages/flutter/iop_console; rg --sort path -l -i 'iop-agent|apps/agent|packages/go/agent|iop/agent|agent\.proto|IopAgentPanel|agentruntime|agentprovider|agentconfig|agentguard|agentpolicy|agentstate|agenttask|agentworkspace' README.md HANDOFF.md Makefile agent-contract agent-spec agent-ops/rules/project agent-roadmap agent-ui apps cmd packages proto configs scripts --glob '!agent-roadmap/archive/**' --glob '!agent-ui/**/archive/**' --glob '!agent-spec/archive/**' --glob '!scripts/fixtures/iop-agent-chronos-ownership-manifest.tsv'; } | sed 's#^\./##' | LC_ALL=C sort -u > /tmp/iop-agent-asset-universe.txt && awk -F '\t' 'NR>1 && $2!="state" {print $1}' scripts/fixtures/iop-agent-chronos-ownership-manifest.tsv | LC_ALL=C sort -u > /tmp/iop-agent-manifest-paths.txt && universe_paths=$(wc -l < /tmp/iop-agent-asset-universe.txt) && manifest_paths=$(wc -l < /tmp/iop-agent-manifest-paths.txt) && missing=$(comm -23 /tmp/iop-agent-asset-universe.txt /tmp/iop-agent-manifest-paths.txt | wc -l) && orphans=$(comm -13 /tmp/iop-agent-asset-universe.txt /tmp/iop-agent-manifest-paths.txt | wc -l) && printf 'universe_paths=%s manifest_paths=%s missing=%s orphans=%s\n' "$universe_paths" "$manifest_paths" "$missing" "$orphans" && test "$universe_paths" -eq 293 && test "$manifest_paths" -eq 293 && test "$missing" -eq 0 && test "$orphans" -eq 0`
5. `cut -f1 scripts/fixtures/iop-agent-chronos-ownership-manifest.tsv | tail -n +2 | LC_ALL=C sort | uniq -d | awk 'NF {bad=1} END {printf "duplicates=%d\n", bad+0; exit bad}'`
6. `git diff --check`

All commands require fresh current-checkout output; no test cache applies. No external smoke or full-cycle runtime is required because this follow-up changes only the ownership manifest and deterministic audit evidence.

After completing all code changes, fill implementation-owned sections in `CODE_REVIEW-*-G??.md`.
