Skip to content
Agent Field Notes
Course contentsExpand a topic to choose a lesson.

SYSTEMATIC LEARNING / FOUR-LEVEL COURSE

Reconnecting clients and durable task state

Examine task and connection decoupling, event sequence number, reconnection and clear final state.

Learning objectives: The connection carries progress notifications, and task status is persisted by the backend. Reconnection only restores the observation position. Repeated submission, cancellation and business completion require independent and clear semantics.

Content checked: 2026-10-30 · Each level has independent explanations, tasks and inspections

Choose a starting point based on your familiarity with this topic. Current level: Debugging · Diagnose failures. After completing the task, continue to the next level. Reading and self-checks alone do not establish mastery.

On this level

Review the prerequisites

Suitable for: Backend developers learning Agent applications.

Reconnecting clients and durable task state
The connection carries progress notifications, and task status is persisted by the backend. Reconnection only restores the observation position. Repeated submission, cancellation and business completion require independent and clear semantics.

How does the mechanism work?

Step-by-step explanation
  1. What should I do if the last completed event is lost?

    After separating the task from the stream, handle lost terminal-state notifications.

  2. How to deal with the backlog logs of slow clients?

    Progress persistence also requires resource and retention boundaries.

  3. Should closing the page automatically cancel it?

    A user's connection status does not automatically express an intent to cancel the business operation.

Debugging · Diagnose failures

Trace counterexamples and failure windows

Objectives of this level: Repair duplicate text and gap skipping on the unchanged inputs.

Visual guide · Advance only through continuity

Advance only through continuity

A display cursor resumes observation, not business execution. Bind tenant and trace; a gap must not be hidden by jumping to the largest sequence. Select the figure to open it at full size.

Replay without inventing continuity

The first probe sends only seq=3 after last_seq=1: text and last_seq stay unchanged, status is waiting and need_seq=2. A loop that sorts and appends all received chunks hides missing content. Empty delta still advances a real sequence number; absence of an event does not.

The second probe supplies two new chunks with the same seq and different content: raise chunk_conflict before rendering a plausible winner. A mismatch in tenant or trace is stream_identity even if the text is identical. Old seq<=last_seq is ignored under this fixture; because checkpoint stores no old event hashes, it cannot detect a changed historical event. Add a persisted identity/hash ledger if your product must detect that case.

The third probe places an event after done. It is after_done even when an earlier sequence gap exists. On a failed client connection, inspect authoritative task state before offering “retry task”; presentation recovery should not create a second business job.

Continue the same implementation

Use the complete function contract and reproduction commands in the implementation layer. Public cases remain in cases/agent-streaming-resume.json inside the existing extended-agent-practice-v1.zip. These are local fixtures, not remote-model or production-load measurements.

code example

Trace counterexamples and failure windows

Replay without inventing continuity

The first probe sends only seq=3 after last_seq=1: text and last_seq stay unchanged, status is waiting and need_seq=2. A loop that sorts and appends all received chunks hides missing content. Empty delta still advances a real sequence number; absence of an event does not.

The second probe supplies two new chunks with the same seq and different content: raise chunk_conflict before rendering a plausible winner. A mismatch in tenant or trace is stream_identity even if the text is identical. Old seq<=last_seq is ignored under this fixture; because checkpoint stores no old event hashes, it cannot detect a changed historical event. Add a persisted identity/hash ledger if your product must detect that case.

The third probe places an event after done. It is after_done even when an earlier sequence gap exists. On a failed client connection, inspect authoritative task state before offering “retry task”; presentation recovery should not create a second business job.

Acceptance task for this level

Use the faulty function below in the learner module, grade the same inputs to a before report, then write your own repair/diff and rerun. Do not edit cases or expected values. The defect is given: this is public repair, not unseen independent diagnosis.

Acceptance self-checks

Reading this browser’s record…

Hide the answer and check your understanding

How do you prove duplicate text is fixed?

Further explanations and practice

When encountering unfamiliar principles, first read the implementation, continuous questioning and migration cases, and then independently explain the premise and boundaries. Answers and notes are saved to the original account record.

All linked explanations and exercises (1 )

Sources and verification scope

The principles are based on public information; the numbers, cases and tasks are the teaching design of this website. Offline experiments verify the range noted on this page, and the learning effect still needs to be judged through independent tasks and feedback.