Docs

Watch an Operation to its end How-to

Updated View as Markdown

You want to know the moment a durable call ends, without reading its Operation again and again. A watch sends each change of one Operation as it happens, and it closes when the work ends.

Before you start

Read these first if a step below is new to you.

  1. Call operation.watch with the Operation's identity. Over HTTP, read the answer as a Server-Sent Events stream. A browser EventSource does this for you.
  2. Read the first event. It is the submission of the work.
  3. Read each later event. Each one is a change of state, or the Operation being held for a person to look at. While nothing changes, a heartbeat arrives, and it needs nothing from you.
  4. If the connection drops, reconnect with the Last-Event-ID header set to the id of the last event you received. The stream continues after that event, and a browser EventSource sends the header for you.
  5. Read the last event. It states how the work ended, it carries the result, and the stream closes. Where it carries a reference to the result instead of the result itself, read the Operation to get it.

You are done when the stream closes after an event that states how the work ended. If the watch is refused before its first event, no stream opens, and the answer carries the refusal's code. If the stream closes with a refusal code instead, a Mandate you watch under was revoked or your Principal was barred while you watched. If the work had already ended when you opened the stream, you receive its history and its last event at once, and then the stream closes.

Sources

  1. Operations
  2. Workspace REST and MCP reference