Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:777genius Agent teams ai Review Decision Persistence

From Leeroopedia
Knowledge Sources
Domains Code_Review, Persistence
Last Updated 2026-10-22 00:00 GMT

Overview

Pattern for persisting file-level and hunk-level code review decisions with optimistic concurrency, scope-based locking, and snapshot validation.

Description

Review Decision Persistence stores accept/reject decisions for each file and hunk in a review scope. Decisions are persisted as JSON files with revision numbers for optimistic concurrency control, scope tokens (sha256 hashes) for security validation, and snapshot validation to ensure data integrity.

Key mechanisms:

  • Optimistic concurrency: The `save()` method accepts an `expectedRevision` number; if the current revision on disk does not match, the save is rejected (or merged depending on strategy).
  • Idempotency keys: A `mutationId` field allows safe retry of save operations — a duplicate mutation with the same ID is detected and skipped.
  • Scope validation: Team names and scope keys are validated against patterns (`TEAM_NAME_PATTERN`, `SCOPE_KEY_PATTERN`) to prevent path traversal.
  • Snapshot validation: `assertValidSnapshot()` validates hunk decisions, file decisions, context hashes, action history, and redo history before persisting.
  • Scope locking: `withReviewPersistenceScopeLock()` uses a SQLite lease database to serialize concurrent writes to the same review scope, with heartbeat-based ownership verification.

Usage

Use this principle when designing a persistence layer for collaborative review decisions where multiple writers may conflict. Applicable to any system requiring optimistic concurrency with file-based persistence and scope-based mutual exclusion.

Theoretical Basis

The persistence follows an optimistic concurrency with scope locking pattern:

# Abstract algorithm (NOT real implementation)
async def save(team_name, scope_key, data):
    validate_scope(team_name, scope_key, data.scope_token)
    validate_snapshot(data)

    current = await load_internal(team_name, scope_key, data.scope_token)
    current_revision = current.revision if current else 0

    # Optimistic concurrency check
    if data.expected_revision is not None:
        if data.expected_revision != current_revision:
            raise ConFLICT_ERROR

    # Idempotency check
    if data.mutation_id and current.last_mutation_id == data.mutation_id:
        return current_revision  # Skip duplicate

    new_revision = current_revision + 1
    snapshot = {
        hunkDecisions: data.hunk_decisions,
        fileDecisions: data.file_decisions,
        revision: new_revision,
        mutationId: data.mutation_id
    }
    await atomic_write(resolve_path(team_name, scope_key), serialize(snapshot))
    return new_revision

Related Pages

Implemented By

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment