Skip to content

[BUG] Child task view can regress to Home when stale state snapshot completes late #1456

Description

@zoomote

Problem

During a subtask transition, the webview can render a ready child task and then regress to the Home/Recent Tasks screen when an older empty-message state snapshot completes later. Multiple overlapping publications can appear as an automatic Home/child loop.

Root cause

ClineProvider.postStateToWebview() and postStateToWebviewWithoutTaskHistory() increment clineMessagesSeq only after awaiting getStateToPostToWebview().

Snapshot construction is asynchronous. A request that captured the child while clineMessages was empty can finish after a newer ready-child request. The stale request then receives the higher sequence number, so the webview's stale-state guard accepts the empty messages as newer.

Child startup is particularly exposed because Task.startTask() intentionally clears clineMessages, posts state, and only then adds the child's first message.

Evidence

TLA+ TLC, Alloy 6, and SPIN independently produced the same counterexample:

  1. Capture child state with empty messages.
  2. Child publishes its first message.
  3. Deliver the ready-child snapshot.
  4. Deliver the older empty snapshot with the higher completion-order sequence.
  5. Webview accepts it and renders Home while the child remains current.

A focused Vitest reproduction against the production methods confirmed the ordering: the newer ready snapshot posted first with sequence 1, then the older empty snapshot posted with sequence 2.

Expected result

Message-state sequence numbers represent publication initiation order, or message-bearing publications are serialized, so a delayed older snapshot cannot replace newer child messages.

Acceptance criteria

  • Add a regression test that delays an older empty snapshot while a newer ready-child snapshot posts.
  • Verify the delayed snapshot has an older sequence and cannot replace the ready child messages.
  • Preserve existing state-post await semantics and non-message state merging.
  • Run the full Zoo Code test suite.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions