Add Phase 16 agent state contract skeleton#2
Conversation
There was a problem hiding this comment.
Code Review
This pull request implements the Phase 16 Agent State Contract Skeleton, introducing commands to capture, verify, and report local agent state metadata securely. The feedback highlights a few key improvement opportunities: removing unreachable dead code in the file collection logic, addressing potential ID collisions in evidence entry generation, and aligning the sorting logic in the reporting handler with the capture handler for consistency.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| let should_include = ext == "rs" | ||
| || ext == "md" | ||
| || ext == "toml" | ||
| || (ext == "json" && path.to_string_lossy().contains(".comptext")); |
There was a problem hiding this comment.
The condition (ext == "json" && path.to_string_lossy().contains(".comptext")) is unreachable dead code. This is because the .comptext directory is explicitly skipped during the directory traversal on line 1710 (file_name == ".comptext"). To keep the file inclusion logic clean and avoid confusion, this redundant check should be removed.
| let should_include = ext == "rs" | |
| || ext == "md" | |
| || ext == "toml" | |
| || (ext == "json" && path.to_string_lossy().contains(".comptext")); | |
| let should_include = ext == "rs" | |
| || ext == "md" | |
| || ext == "toml"; |
| .map_err(|e| format!("failed to read file '{}': {e}", path.display()))?; | ||
| let sha = sha256_hex(&content); | ||
|
|
||
| let id = path_str.replace(['/', '.', '-'], "_"); |
There was a problem hiding this comment.
Replacing multiple distinct path separators and characters (/, ., -) with a single underscore (_) introduces a risk of ID collisions. For example, both src/foo-bar.rs and src/foo/bar.rs will produce the identical ID src_foo_bar_rs. When such collisions occur, handle_state_verify will fail with a duplicate evidence ID error, making the captured state invalid. Consider using a more robust mapping or appending a short hash of the original path_str to the ID if a collision is possible, or simply using the path_str itself as the unique identifier.
| // Sort evidence by ID to guarantee stable order | ||
| state.evidence.sort_by(|a, b| a.id.cmp(&b.id)); |
There was a problem hiding this comment.
For consistency and to guarantee a deterministic order even if duplicate IDs are present, the sorting logic in handle_state_report should match the sorting logic used in handle_state_capture (sorting by id and then by file_path).
| // Sort evidence by ID to guarantee stable order | |
| state.evidence.sort_by(|a, b| a.id.cmp(&b.id)); | |
| // Sort evidence by id, then by file_path to guarantee stable/deterministic order | |
| state.evidence.sort_by(|a, b| a.id.cmp(&b.id).then_with(|| a.file_path.cmp(&b.file_path))); |
Summary
Phase 16 adds local agent-state capture, verify, and report support as bounded evidence artifacts.
Implemented
ctxt state capture --task "..."ctxt state verify <path>ctxt state report <path>.comptext/agent_state.latest.jsonas ignored runtime statedocs/AGENT_STATE_CONTRACT.mddocs/EVIDENCE_CONTROL_PLANE.mdreports/phase_16_status.mdReview-Gate Safeguards
phase-16-agent-state-contractidandfile_pathbefore serializationValidation
cargo fmt --all --checkcargo checkcargo testcargo clippy -- -D warningsNext
Merge only after final PR diff review.