Principle:777genius Agent teams ai Change Review State Management
| Knowledge Sources | |
|---|---|
| Domains | Code_Review, State_Management |
| Last Updated | 2026-10-22 00:00 GMT |
Overview
Pattern for managing reactive code review state in a client-side store, tracking file-level and hunk-level accept/reject decisions with content versioning and invalidation.
Description
Change Review State Management is the practice of holding code review decisions (which files to accept, which hunks to reject) in a reactive Zustand store that the UI subscribes to for real-time rendering. The store tracks file contents, hunk context hashes, and content version numbers to detect when a file's underlying diff has changed and previously-made decisions need invalidation.
Key challenges addressed:
- Content invalidation: When a file's diff changes (e.g., the agent made new edits), previously-made hunk decisions must be invalidated. Content version numbers track this.
- Alias handling: File paths can have aliases (e.g., renamed files); decisions must be invalidated across all aliases.
- Chunk-level context: Hunk decisions are keyed by context hashes that identify the specific code region, preventing mismatched decisions after content changes.
- Scope tokens: Review scopes (per-task or per-agent) are identified by sha256 tokens for security.
Usage
Use this principle when designing a reactive review system where users make file-level and hunk-level decisions that must remain consistent with evolving file content. Applicable to any diff-based review interface where the underlying files may change between decision and application.
Theoretical Basis
The state management follows a versioned content invalidation pattern:
# Abstract algorithm (NOT real implementation)
def build_resolved_file_invalidation(state, file_path):
aliases = collect_aliases(state.active_change_set, file_path)
# Bump content version for each alias
for alias in aliases:
state.file_content_version_by_path[alias] += 1
# Clear cached content and decisions
for alias in aliases:
del state.file_contents[alias]
del state.file_chunk_counts[alias]
del state.file_contents_loading[alias]
# Clear hunk context hashes
review_key = get_review_key(state.active_change_set, file_path)
del state.hunk_context_hashes_by_file[review_key]
for alias in aliases:
del state.hunk_context_hashes_by_file[alias]