Repository navigation
fix(placement): refuse unsafe memory checkpoints - #296
Tatsat (Tats) Mishra 🐉 (Tatsinnit) wants to merge 5 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The refusal test never cancels and joins Exec, leaving its goroutine, live connection, and session guard running indefinitely after successful assertions.
1 open issue
1 file not reviewed
api/genpb/session_grpc.pb.go: Generated file
What changed in this PR
This PR addresses #98 by preventing memory checkpoints that could cause recovery to apply RAM mutations twice. It coordinates checkpoint admission with execution state and journal publication.
Changes:
- Adds a controller-owned checkpoint validator for incomplete executions and approval states.
- Makes stateful Fork refuse active turns without cancelling them, and binds memory Suspend publication to the validated journal head.
- Publishes
CHECKPOINT_INCOMPLETE_TURN, strengthens the Runtime contract, and updates tests and documentation.
| File | Description |
|---|---|
| spec.md | Defines checkpoint safety, admission, and error contracts. |
| session/service.go | Maps checkpoint and Suspend admission errors. |
| session/fork_wake_test.go | Removes the obsolete fork-versus-wake race test. |
| session/errors.go | Adds the incomplete-checkpoint error reason. |
| session/error_reasons_test.go | Tests checkpoint error mappings. |
| session/checkpoint_test.go | Tests admission failures and non-cancelling Fork refusal. |
| session/approval_override_test.go | Checks refusal of interrupted memory overrides. |
| placement/transport_test.go | Updates stream tests for non-cancelling checkpoint refusal. |
| placement/suspend_test.go | Covers incomplete turns, journal races, and capture quarantine. |
| placement/session_guard.go | Updates guard documentation. |
| placement/resume_cas_test.go | Tests Fork refusal during Resume restoration. |
| placement/registry.go | Documents shared non-cancelling Fork admission. |
| placement/registry_add_test.go | Tests refusal across dynamically added Placers. |
| placement/placement.go | Implements checkpoint validation, guarding, and exact-head publication. |
| placement/placement_test.go | Uses completed histories in memory-fork fixtures. |
| placement/memory_approval_test.go | Tests refusal of decided approval checkpoints. |
| placement/legacy_inventory_test.go | Updates legacy fork fixtures to completed turns. |
| placement/fork_verify_test.go | Updates the tampered-parent test fixture. |
| placement/compute_guard.go | Updates checkpoint cleanup commentary. |
| placement/compute_guard_test.go | Removes obsolete checkpoint-supersession cases. |
| placement/cleanup_resources_test.go | Checks refusal before child allocation tracking. |
| placement/approval_test.go | Updates decided-approval fork expectations. |
| docs/substrate-conformance.md | Documents checkpoint admission and race guarantees. |
| docs/faq.md | Explains contention and incomplete-turn refusal. |
| docs/architecture.md | Describes safe memory checkpoint coordination. |
| docs/api-reference.md | Updates generated error and Suspend documentation. |
| controller/checkpoint.go | Adds journal-based checkpoint safety classification. |
| controller/checkpoint_test.go | Covers execution and approval checkpoint states. |
| changelog/unreleased/incomplete-memory-checkpoint.md | Records safety changes and Runtime obligations. |
| api/session.proto | Documents the new reason and Suspend admission behavior. |
| api/runtime.go | Requires rejection of unrecorded retained captures. |
| api/genpb/session_grpc.pb.go | Synchronizes generated service comments. |
Review effort: Balanced
There was a problem hiding this comment.
🔵 Needs a closer look
A maintainer should confirm that deployed custom memory backends quarantine captures after a failed journal CAS, as checkpoint safety now depends on this newly mandatory Runtime SPI behavior.
No open issues 🎉
1 resolved since last review
1 file not reviewed
api/genpb/session_grpc.pb.go: Generated file
Review effort: Balanced
Anish Ramasekar (aramase)
left a comment
There was a problem hiding this comment.
The fix for #98 looks right; one changelog gap blocks it, plus a few small things.
Nits:
spec.md:1426still says the reference host accepts Suspend on a session that is already cold. A parked memory session with a decided gate now refuses a second Suspend with CHECKPOINT_INCOMPLETE_TURN; qualify the sentence with the OPS-3 exception.api/session.proto:472-478and:490-497: the Suspend and Fork comments don't mention CHECKPOINT_INCOMPLETE_TURN (FAILED_PRECONDITION) or Fork's new SESSION_BUSY refusal of a running turn. One sentence each, then regenerate genpb and api-reference.placement/placement.go:1736,:988-1030:endHarnessesis a no-op now thatbeginCheckpointreturns no connections, andsuperseded/checkSuperseded/errSuperseded(placement.go:807-860,:568-573,cleanup.go:135) are unreachable. Delete them here or in a follow-up.placement/placement.go:1727-1729: the comment breaks mid-sentence; rewrap to 100 columns.
|
Thank you for the careful review. I addressed the remaining nits in 4b746b8: qualified the already-cold Suspend text with the OPS-3 exception; documented the Suspend and Fork refusals in the proto and regenerated genpb/API reference; removed the now-unreachable |
There was a problem hiding this comment.
🟡 Changes recommended
A concurrent approval result during automatic handoff can be misclassified as an incomplete checkpoint, causing an INTERNAL error instead of the expected ABORTED / STALE_CURSOR conflict.
1 open issue
1 file not reviewed
api/genpb/session_grpc.pb.go: Generated file
Review effort: Balanced
There was a problem hiding this comment.
🔵 Needs a closer look
Human assessment is needed because a concurrent peer append can cause checkpoint validation to report an incomplete turn instead of a retryable conflict, or snapshot a moved head.
No open issues 🎉
1 resolved since last review
1 file not reviewed
api/genpb/session_grpc.pb.go: Generated file
Review effort: Balanced
Anish Ramasekar (aramase)
left a comment
There was a problem hiding this comment.
Thanks, the earlier threads are all addressed, and the handoff head check at placement.go:993 fixes the Copilot 09:41Z race (reverting it fails both new test rows). Suspend's reread is fine too: it checks the head before classifying.
One blocker, inline: Fork's second read still classifies without re-checking the head.
Optional: in spec.md OPS-3 and the compat fragment, say that a turn still running on another writer sharing the journal is also reported as CHECKPOINT_INCOMPLETE_TURN, and that a retry after it ends succeeds. Today the text only says "abandoned".
|
Thank you for the follow-up. I also took the optional documentation suggestion in The focused regression passed 100 times under |
There was a problem hiding this comment.
🔵 Needs a closer look
Failed-publication safety depends on custom Runtime backends enforcing RecordedCheckpoint quarantine and coordinated upgrade/rollback ordering, both requiring maintainer validation beyond the in-memory conformance evidence.
No open issues 🎉
1 file not reviewed
api/genpb/session_grpc.pb.go: Generated file
Review effort: Balanced

Summary
CHECKPOINT_INCOMPLETE_TURN, strengthen the Runtime checkpoint contract, and update conformance/docsFixes #98.
Problem
A
REQUIRES_MEMORY_SNAPSHOTharness 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 lackedEND. 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.ValidateCheckpointStateverifies 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:Harness.RunIt refuses ordinary modern or legacy incomplete turns, modern
ERRORtails, markerless pending turns, decided approval gates without a receipt, receipted executions withoutEND, 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:
SESSION_BUSYCHECKPOINT_INCOMPLETE_TURNAfter the checkpoint mark is installed, the transient operation hold is released so calls during snapshot/fan-out retain
CHECKPOINT_IN_PROGRESSbehavior.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:
Snapshot(EXTERNAL)SUSPENDwith CAS at that validated head and fenceA 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:
FAILED_PRECONDITIONgoogle.rpc.ErrorInfo{domain: "agentsessions", reason: "CHECKPOINT_INCOMPLETE_TURN"}Active local contention remains
ABORTED / SESSION_BUSY. Tampered Suspend journals areDATA_LOSS. Memory-capable Suspend admission maps unavailable harnesses toUNAVAILABLE / HARNESS_UNAVAILABLE, and descriptor/class refusals toFAILED_PRECONDITION.Tests
Added or updated coverage for:
Verification
go test -race -shuffle=on ./controllergo test -race -shuffle=on ./placementgo test -race -shuffle=on ./sessiongo test -race -shuffle=on ./...inintegrations/substratego test -race -shuffle=on ./...inintegrations/claudecodego build ./...go vet ./...buf lintbuf breaking --against ".git#tag=v0.4.0,subdir=api"go run ./hack/doccheckpython3 hack/verify_chain.py --golden./hack/verify_chain.shgofmt -l .git diff --checkThe repository-wide root race run still reaches the pre-existing Python 3.9 portability failure in
internal/agentsessionsd.TestDocumentedPythonExecutorLogsStorageFailureWithoutPayload: Python reports the documented fallbacksqlite_errorname=unknownwhile the test expectsSQLITE_ERROR. The same targeted failure reproduces on cleanmain; all changed packages pass under the race detector.