Repository navigation
fix(task): return a skipped subtask handoff to the orchestrator (issue 2677) #2856
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| ---- MODULE SubtaskReturn ---- | ||
| \* Models the orchestrator subtask handoff: AttemptCompletionTool.execute with a | ||
| \* set parentTaskId, reopenParentFromDelegation, and the provider onTaskCompleted | ||
| \* listener (src/core/webview/ClineProvider.ts). | ||
| \* Source: the child records its final response and asks to return to the parent, | ||
| \* or the TaskCompleted event reaches the provider listener. | ||
| \* Sink: the parent record leaves delegated/awaiting, or a "completed" write lands | ||
| \* on a child its parent still awaits. | ||
| \* Failure: after one transient handoff skip, the user accepts the completion ask | ||
| \* or the listener fires; an unguarded writer records the child "completed" while | ||
| \* the parent still awaits it, and every later attempt_completion then reads | ||
| \* "completed", stops as a stale replay, and the result never reaches the | ||
| \* orchestrator (issue 2677). | ||
| \* Invariant NoPoisonedCompletion: no reachable state records the child | ||
| \* "completed" while the parent record still awaits that child. | ||
| \* Modes: "Guarded" (fix - the accept re-runs the handoff while the parent | ||
| \* awaits, and the listener write defers to completeDelegatedChild), "Poison" | ||
| \* (pre-fix - accept and listener write "completed" in place), and | ||
| \* "PoisonListener" (only the listener guard removed; the accept keeps the fix). | ||
| \* Result: "Poison" fails NoPoisonedCompletion (reproduction). "PoisonListener" | ||
| \* fails it through ListenerObserve alone: its guarded accept cannot reach the | ||
| \* poisoned state. "Guarded" holds, and the listener can write there (free | ||
| \* parent) - the hold comes from the guard, not from a dead action. | ||
| \* Model-checked 2026-12-05, tla2tools 1.7.4: SubtaskReturn.cfg pass | ||
| \* (6 states), SubtaskReturn.PoisonListener.cfg fail (5 states), | ||
| \* SubtaskReturn.Poison.cfg fail (5 states). Counts vary run to run. | ||
| \* Review: 0 covered, 1 added (PR 2856 round 1, thread SubtaskReturn.tla:60 - | ||
| \* ListenerObserve action + PoisonListener sabotage), 1 gap (the | ||
| \* provider-dispose test-hygiene finding is not a modeled-system behavior; | ||
| \* fixed in the TS spec file). | ||
| \* Not modeled: approval denial, persistence retries, cancellation, grandchild | ||
| \* delegation, and the message content itself (oracle: taskLifecycle.ts). | ||
|
|
||
| EXTENDS Naturals | ||
|
|
||
| CONSTANTS Mode | ||
|
|
||
| VARIABLES parentAwaiting, childStatus, phase | ||
| vars == <<parentAwaiting, childStatus, phase>> | ||
|
|
||
| \* Two starts a real system can be in when the child finishes: the parent | ||
| \* record still awaits this child, or the parent record is free (gone, or no | ||
| \* longer awaiting) while the child task is still active. | ||
| Init == \/ /\ parentAwaiting = "child" | ||
| /\ childStatus = "active" | ||
| /\ phase = "running" | ||
| \/ /\ parentAwaiting = "none" | ||
| /\ childStatus = "active" | ||
| /\ phase = "running" | ||
|
|
||
| \* The child streams its final response. The handoff either completes (the | ||
| \* reopen succeeds: the pair update frees the parent and completes the child) | ||
| \* or is skipped once (transient gate miss or reopen failure) and the tool | ||
| \* falls through to the plain completion ask. | ||
| AttemptReturn == | ||
| /\ phase = "running" | ||
| /\ IF parentAwaiting = "child" | ||
| THEN \/ /\ phase' = "handedOff" | ||
| /\ parentAwaiting' = "none" | ||
| /\ childStatus' = "completed" | ||
| \/ /\ phase' = "askUser" | ||
| /\ UNCHANGED <<parentAwaiting, childStatus>> | ||
| ELSE /\ phase' = "askUser" | ||
| /\ UNCHANGED <<parentAwaiting, childStatus>> | ||
|
|
||
| \* The provider onTaskCompleted listener fires for the finished child. The | ||
| \* guarded form writes "completed" only when the parent record is free; a | ||
| \* still-awaited child defers the write to completeDelegatedChild. The | ||
| \* unguarded form (Poison, PoisonListener) writes "completed" regardless. | ||
| \* An already completed child makes the write a no-op. | ||
| ListenerObserve == | ||
| /\ phase \in {"running", "askUser"} | ||
| /\ IF childStatus = "completed" | ||
| THEN UNCHANGED vars | ||
| ELSE IF Mode = "Guarded" /\ parentAwaiting = "child" | ||
| THEN UNCHANGED vars | ||
| ELSE /\ childStatus' = "completed" | ||
| /\ phase' = "closed" | ||
| /\ UNCHANGED parentAwaiting | ||
|
|
||
| \* The user answers the completion ask. "Poison" records the child completed | ||
| \* in place; the parent record keeps awaiting. The other modes re-run the | ||
| \* handoff while the parent still awaits this child; only a free child | ||
| \* completes in place. A poisoned child can never re-run the handoff: the | ||
| \* stale-replay gate reads "completed" and skips delegation forever. | ||
| AcceptCompletion == | ||
| /\ phase = "askUser" | ||
| /\ IF Mode # "Poison" | ||
| THEN IF parentAwaiting = "child" | ||
| THEN /\ phase' = "handedOff" | ||
| /\ parentAwaiting' = "none" | ||
| /\ childStatus' = "completed" | ||
| ELSE /\ childStatus' = "completed" | ||
| /\ phase' = "closed" | ||
| /\ UNCHANGED parentAwaiting | ||
| ELSE /\ childStatus' = "completed" | ||
| /\ phase' = "closed" | ||
| /\ UNCHANGED parentAwaiting | ||
|
|
||
| \* The user re-prompts the model. A live child retries the handoff; a child | ||
| \* already recorded "completed" is treated as a stale replay and stays stuck. | ||
| PromptAgain == | ||
| /\ phase \in {"running", "closed"} | ||
| /\ IF childStatus = "active" /\ parentAwaiting = "child" | ||
| THEN phase' = "running" | ||
| ELSE phase' = phase | ||
| /\ UNCHANGED <<parentAwaiting, childStatus>> | ||
|
|
||
| Next == AttemptReturn \/ AcceptCompletion \/ ListenerObserve \/ PromptAgain | ||
|
|
||
| Spec == Init /\ [][Next]_vars | ||
|
|
||
| TypeOK == /\ parentAwaiting \in {"child", "none"} | ||
| /\ childStatus \in {"active", "completed"} | ||
| /\ phase \in {"running", "askUser", "handedOff", "closed"} | ||
|
|
||
| NoPoisonedCompletion == ~(childStatus = "completed" | ||
| /\ parentAwaiting = "child") | ||
|
|
||
| ==== | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.