Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/architecture/task-lifecycle-model.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,11 @@ The production-backed lifecycle checker already models the current serial owners
- delegated parent reopen success or failure after durable child history; and
- emitting completion.

The model cancel event also represents a failed stream that cancels only its current persistence generation. The task can recover with a new turn.

The model abstracts restart visibility as the `durable` history phase. It allows an already-started write to finish after cancellation because the filesystem operation itself is not cancellable, but it forbids starting a retry write or emitting completion after cancellation. The retry bound is two write starts (the initial attempt plus one retry), which is sufficient to cover the ordering and cancellation state classes without mirroring the production retry count.

Seven semantic landmarks keep the intended positive and negative paths reachable: delayed completion remains pending, failed completion remains pending, exhausted retries settle without completion, cancellation can win after retry delay but before persistence, delegated reopen failure emits no delegated completion, and both standalone and delegated tasks can complete after durable history. The checker explores all reachable states through depth 10 and fails rather than reporting a truncated pass if an unseen successor remains.
Eight semantic landmarks keep the intended positive and negative paths reachable: a failed delegated turn cancels its persistence wait without completing or reopening its parent, delayed completion remains pending, failed completion remains pending, exhausted retries settle without completion, cancellation can win after retry delay but before persistence, delegated reopen failure emits no delegated completion, and both standalone and delegated tasks can complete after durable history. The checker explores all reachable states through depth 10 and fails rather than reporting a truncated pass if an unseen successor remains.

## Invariants

Expand Down
5 changes: 5 additions & 0 deletions docs/architecture/tla/StreamReadCancellation.Dropped.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SPECIFICATION Spec
CHECK_DEADLOCK FALSE
CONSTANTS
DropReason <- DroppedReason
INVARIANTS TypeOK AbortReasonPreserved
5 changes: 5 additions & 0 deletions docs/architecture/tla/StreamReadCancellation.Leak.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SPECIFICATION Spec
CHECK_DEADLOCK FALSE
CONSTANTS
CleanOnSettle <- LeakySettle
INVARIANTS TypeOK NoSettledReadListener
5 changes: 5 additions & 0 deletions docs/architecture/tla/StreamReadCancellation.Reason.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SPECIFICATION Spec
CHECK_DEADLOCK FALSE
CONSTANTS
PreserveReason <- GenericReason
INVARIANTS TypeOK AbortReasonPreserved
3 changes: 3 additions & 0 deletions docs/architecture/tla/StreamReadCancellation.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SPECIFICATION Spec
CHECK_DEADLOCK FALSE
INVARIANTS TypeOK NoSettledReadListener AbortReasonPreserved
52 changes: 52 additions & 0 deletions docs/architecture/tla/StreamReadCancellation.tla
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---- MODULE StreamReadCancellation ----
\* Source: Task.nextChunkWithAbort awaits iterator.next. Sink: read settlement and the request error handler.
\* Failure: completed or failed reads leave abort listeners attached. Invariant: NoSettledReadListener.
\* Failure: cancellation replaces the request's abort reason. Invariant: AbortReasonPreserved.
\* Expect the old listener race to fail after one settled read and to replace user and deadline reasons.
\* Replay success, failure, pre-aborted reads, and cancellation during a pending read through Task's real request lease.
\* The shared raceAbort helper removes its listener on either settlement path and propagates the signal reason.
\* Reference: https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal#removing_the_abort_event_listener
\* Result: the old model fails after Read and Settle (5 states). All four Task regression cases fail before reuse.
\* Fixed holds (15 states). Leak and Reason fail separately. Four Task cases and 326 focused tests pass after reuse.
\* Task now reuses detachOnAbort. One drain catch owns consumption errors; detached reporting stays independent.
\* Existing ThoughtSignaturePersistence and ThoughtSignatureRecovery gates retain all positive and negative results.
\* Null result: no extra failure in the fixed bounded model. An abort race does not stop an uncooperative iterator.
\* Review counts remain 2 covered, 14 added, 0 gap. This refactor follows the user's simplification request.
\* listeners counts only the Task read's listeners. Transport listeners are outside this model.
\* Validation: all 14 full-test tasks pass, including 15,551 extension tests. Lifecycle, types, lint, formatting, and Knip pass.
\* Suppression counts stay equal. Cost: about 6 agent minutes. The two simplifications remove 24 runtime lines.
\* Review: https://github.com/Zoo-Code-Org/Zoo-Code/pull/2643#discussion_r4674161290
\* Expect dropped delivery to pass the old invariant. Track the delivery obligation independently of the delivered value.
\* Result: Dropped passes the old invariant (11 states), which confirms the missing delivery obligation.
\* deliveryRequired now records pending-read cancellation and reads made after abort, independently of delivered.
\* Fixed holds (15 states). Dropped, Reason and Leak fail separately. Abort with no read stays valid.
\* This spec adds the cancellation finding. ThoughtSignatureRecovery records the review round totals.
\* Validation: all 14 full-test tasks pass, including 15,554 extension tests. Types, lint, formatting, and both Knip checks pass.
\* Lifecycle checks and all three relevant TLA+ gates pass. Suppression counts stay equal. Cost: about 15 agent minutes.
EXTENDS Naturals
VARIABLES reads, pending, listeners, reason, delivered, deliveryRequired
vars == <<reads, pending, listeners, reason, delivered, deliveryRequired>>
CleanOnSettle == TRUE
PreserveReason == TRUE
DropReason == FALSE
Init == /\ reads = 0 /\ pending = FALSE /\ listeners = 0 /\ reason = "none" /\ delivered = "none" /\ deliveryRequired = FALSE
Read == /\ reads < 2 /\ ~pending /\ reads' = reads + 1
/\ pending' = (reason = "none") /\ deliveryRequired' = (reason # "none")
/\ listeners' = IF reason = "none" THEN listeners + 1 ELSE listeners
/\ delivered' = IF reason = "none" THEN "none" ELSE IF DropReason THEN "none" ELSE IF PreserveReason THEN reason ELSE "generic"
/\ UNCHANGED reason
Settle == /\ pending /\ pending' = FALSE
/\ listeners' = IF CleanOnSettle THEN listeners - 1 ELSE listeners
/\ UNCHANGED <<reads, reason, delivered, deliveryRequired>>
Abort(value) == /\ deliveryRequired' = (deliveryRequired \/ pending) /\ reason = "none" /\ reason' = value /\ pending' = FALSE /\ listeners' = 0
/\ delivered' = IF pending THEN IF DropReason THEN "none" ELSE IF PreserveReason THEN value ELSE "generic" ELSE delivered
/\ UNCHANGED reads
Next == Read \/ Settle \/ (\E value \in {"user", "deadline"} : Abort(value))
Spec == Init /\ [][Next]_vars
TypeOK == /\ reads \in 0..2 /\ pending \in BOOLEAN /\ listeners \in 0..2
/\ deliveryRequired \in BOOLEAN
/\ reason \in {"none", "user", "deadline"} /\ delivered \in {"none", "user", "deadline", "generic"}
NoSettledReadListener == ~pending => listeners = 0
AbortReasonPreserved == /\ (deliveryRequired => delivered = reason /\ delivered # "none")
/\ (delivered # "none" => delivered = reason)
====
6 changes: 6 additions & 0 deletions docs/architecture/tla/StreamReadCancellationMC.tla
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---- MODULE StreamReadCancellationMC ----
EXTENDS StreamReadCancellation
LeakySettle == FALSE
GenericReason == FALSE
DroppedReason == TRUE
====
7 changes: 7 additions & 0 deletions docs/architecture/tla/ThoughtSignature.EchoReasoning.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SPECIFICATION Spec
CHECK_DEADLOCK FALSE
CONSTANTS
MaxTurns = 2
EchoSignedReasoning <- EchoUnsigned
CONSTRAINT Bounded
INVARIANTS NoUnsignedThought TypeOK NoRejectedCall NoCorruptIdDecode SignatureDelivered
7 changes: 7 additions & 0 deletions docs/architecture/tla/ThoughtSignature.EncodedFirst.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SPECIFICATION Spec
CHECK_DEADLOCK FALSE
CONSTANTS
MaxTurns = 2
PreferExplicit <- EncodedFirst
CONSTRAINT Bounded
INVARIANTS SignatureSourcePriority NoUnsignedThought TypeOK NoRejectedCall NoCorruptIdDecode SignatureDelivered
7 changes: 7 additions & 0 deletions docs/architecture/tla/ThoughtSignature.ForeignEncoded.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SPECIFICATION Spec
CHECK_DEADLOCK FALSE
CONSTANTS
MaxTurns = 2
KeepForeignEncodedIds <- KeepEncodedIds
CONSTRAINT Bounded
INVARIANTS NoForeignEncodedSignature
7 changes: 7 additions & 0 deletions docs/architecture/tla/ThoughtSignature.FrozenCursor.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SPECIFICATION Spec
CHECK_DEADLOCK FALSE
CONSTANTS
MaxTurns = 2
AdvanceReplayCursor <- FrozenCursor
CONSTRAINT Bounded
INVARIANTS OccurrenceReplayAfterTurn
7 changes: 7 additions & 0 deletions docs/architecture/tla/ThoughtSignature.IdOnly.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SPECIFICATION Spec
CHECK_DEADLOCK FALSE
CONSTANTS
MaxTurns = 2
CaptureFromId <- IgnoreId
CONSTRAINT Bounded
INVARIANTS TypeOK NoRejectedCall NoCorruptIdDecode SignatureDelivered
7 changes: 7 additions & 0 deletions docs/architecture/tla/ThoughtSignature.NextResult.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SPECIFICATION Spec
CHECK_DEADLOCK FALSE
CONSTANTS
MaxTurns = 2
ResultAtNext <- NextResult
CONSTRAINT Bounded
INVARIANTS OccurrenceReplayAfterTurn
7 changes: 0 additions & 7 deletions docs/architecture/tla/ThoughtSignature.NoMarker.cfg

This file was deleted.

7 changes: 7 additions & 0 deletions docs/architecture/tla/ThoughtSignature.ReusedId.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SPECIFICATION Spec
CHECK_DEADLOCK FALSE
CONSTANTS
MaxTurns = 2
ReplayByOccurrence <- IdOnlyReplay
CONSTRAINT Bounded
INVARIANTS OccurrenceReplayAfterTurn
7 changes: 7 additions & 0 deletions docs/architecture/tla/ThoughtSignature.StreamFirstWins.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SPECIFICATION Spec
CHECK_DEADLOCK FALSE
CONSTANTS
MaxTurns = 2
CaptureStream <- KeepFirstCaptured
CONSTRAINT Bounded
INVARIANTS StreamPriorityAfterTurn
7 changes: 7 additions & 0 deletions docs/architecture/tla/ThoughtSignature.UnpairedIds.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SPECIFICATION Spec
CHECK_DEADLOCK FALSE
CONSTANTS
MaxTurns = 2
RewriteToolResultIds <- KeepResultIds
CONSTRAINT Bounded
INVARIANTS ToolResultIdsMatch
7 changes: 7 additions & 0 deletions docs/architecture/tla/ThoughtSignature.UnsignedResult.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SPECIFICATION Spec
CHECK_DEADLOCK FALSE
CONSTANTS
MaxTurns = 2
RetainUnsignedResult <- KeepSignedResult
CONSTRAINT Bounded
INVARIANTS OccurrenceReplayAfterTurn
2 changes: 1 addition & 1 deletion docs/architecture/tla/ThoughtSignature.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ CHECK_DEADLOCK FALSE
CONSTANTS
MaxTurns = 2
CONSTRAINT Bounded
INVARIANTS TypeOK NoRejectedCall NoCorruptIdDecode SignatureDelivered
INVARIANTS OccurrenceReplayAfterTurn ToolResultIdsMatch NoForeignEncodedSignature StreamPriorityAfterTurn SignatureSourcePriority NoUnsignedThought TypeOK NoRejectedCall NoCorruptIdDecode SignatureDelivered
Loading
Loading