← Back to Pull requests

fix(placement): refuse unsafe memory checkpoints #296

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Nov 27, 2026 08:38 UTC
Author

Summary

  • refuse memory-tier Suspend and Fork when the latest execution can be re-driven

  • stop stateful Fork from cancelling a live parent turn, and bind memory Suspend to an exact validated journal head

  • publish CHECKPOINT_INCOMPLETE_TURN, strengthen the Runtime checkpoint contract, and update conformance/docs
  • Fixes #98.

    Problem

    A REQUIRES_MEMORY_SNAPSHOT harness can mutate RAM before its next durable sink record. Previously, a stateful Fork could fence and close that turn, then snapshot the mutated RAM while its journal still lacked END. Suspend could also snapshot an abandoned incomplete execution. A later Resume restored that RAM and re-drove the incomplete turn, applying the mutation twice.

    The same mismatch could occur when another host advanced the journal while public Suspend was capturing RAM: Suspend used to append at the post-snapshot current head rather than the head it validated before capture.

    Design

    Controller-owned checkpoint classifier

    controller.ValidateCheckpointState verifies the supplied hash chain and reuses the controller's execution and approval projections. A memory checkpoint is accepted only when recovery cannot re-run captured mutations:

  • empty, lifecycle-only, or completed history

  • a strict partial-input prefix that never reached Harness.Run

  • an owned undecided approval park, where recovery parks without running the harness

  • an inherited unresolved approval, where recovery refuses before running the harness
  • It refuses ordinary modern or legacy incomplete turns, modern ERROR tails, markerless pending turns, decided approval gates without a receipt, receipted executions without END, and malformed evidence.

    A decided gate is deliberately refused: an earlier recovery may have changed RAM before failing without a receipt.

    Stateful Fork admission

    A memory-tier Fork temporarily takes the existing session operation guard through journal validation and checkpoint-mark installation. Therefore:

  • a locally active turn or pre-journal Connect preparation returns retryable SESSION_BUSY

  • the turn is not cancelled, fenced, or disconnected

  • an abandoned incomplete journal tail returns CHECKPOINT_INCOMPLETE_TURN

  • the refusal happens before a fence, snapshot, child allocation plan, runtime Fork, or child journal write
  • After the checkpoint mark is installed, the transient operation hold is released so calls during snapshot/fan-out retain CHECKPOINT_IN_PROGRESS behavior.

    Stateless forks are unchanged.

    Memory Suspend publication

    On a memory-capable backend, Suspend admits the harness to determine whether it is memory-tier. A memory-tier Suspend:

    1. verifies and classifies the current records
    2. mints a fence before capture
    3. rereads and revalidates the same exact head
    4. calls Snapshot(EXTERNAL)
    5. appends SUSPEND with CAS at that validated head and fence

    A peer writer can therefore invalidate publication, but cannot widen the accepted checkpoint boundary over its incomplete turn. If the physical capture landed before the CAS failed, the Runtime contract now requires a memory backend to quarantine it by refusing a mismatched RecordedCheckpoint; Substrate already enforces that rule.

    Stateless Suspend keeps its existing replay-safe behavior.

    Public errors

    Abandoned incomplete memory checkpoints map to:

  • gRPC FAILED_PRECONDITION

  • google.rpc.ErrorInfo{domain: "agentsessions", reason: "CHECKPOINT_INCOMPLETE_TURN"}
  • Active local contention remains ABORTED / SESSION_BUSY. Tampered Suspend journals are DATA_LOSS. Memory-capable Suspend admission maps unavailable harnesses to UNAVAILABLE / HARNESS_UNAVAILABLE, and descriptor/class refusals to FAILED_PRECONDITION.

    Tests

    Added or updated coverage for:

  • modern, legacy, malformed, partial-input, approval, inherited, decided and receipted checkpoint states

  • active turns across the same Placer, another Registry Placer, and dynamically added Placers

  • no stream cancellation, fence, snapshot, journal movement, child publication, runtime Fork, or cleanup allocation row on refusal

  • peer movement before capture and during capture

  • quarantine of an unrecorded physical capture

  • tampered Suspend journals

  • memory-capable Suspend admission status mapping

  • generated protobuf/API reference and public ErrorInfo reason
  • Verification

  • go test -race -shuffle=on ./controller

  • go test -race -shuffle=on ./placement

  • go test -race -shuffle=on ./session

  • go test -race -shuffle=on ./... in integrations/substrate

  • go test -race -shuffle=on ./... in integrations/claudecode

  • go build ./...

  • go vet ./...

  • buf lint

  • buf breaking --against ".git#tag=v0.4.0,subdir=api"

  • go run ./hack/doccheck

  • python3 hack/verify_chain.py --golden

  • ./hack/verify_chain.sh

  • gofmt -l .

  • git diff --check
  • The repository-wide root race run still reaches the pre-existing Python 3.9 portability failure in internal/agentsessionsd.TestDocumentedPythonExecutorLogsStorageFailureWithoutPayload: Python reports the documented fallback sqlite_errorname=unknown while the test expects SQLITE_ERROR. The same targeted failure reproduces on clean main; all changed packages pass under the race detector.

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: aramase Review duration: 2649m
    All Vouch review confidence checks passed
    Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #296"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 27.7% · Safe to merge
    27.7%