Stream the changes of Missions as server-sent events.
API version mission-status unreleased
A change stream, served as text/event-stream. OpenAPI 3.1 has no native way to describe a stream of named events, so the stream is documented here as a convention; the schema of the 200 response is the schema of the data field of each event, not of the whole body.
Event names and data schemas. There are exactly three event names, each with one data schema, and no other event name is ever sent:
status-transition-> StatusTransitionEvent: a work package changed status lane.mission-lifecycle-> MissionLifecycleEvent: the Mission was created, or a planning phase started or completed.log-truncated-> LogTruncatedEvent: the Mission’s event log shrank or changed; resynchronise.
Framing. Each event is sent as an event: line with the event name, an id: line with the
StreamCursorString of the event, a data: line with the JSON of the data schema, and a blank
line. The id is the same string the streamCursor parameter and the Last-Event-ID header
accept. Two kinds of event carry no id: line, so that a browser’s automatic Last-Event-ID
never holds a position that cannot be resumed from. Every event of an unscoped stream (no
missionId) is sent without an id: line, because a cursor is a position in one Mission’s log
and the unscoped stream interleaves Missions. A log-truncated event is sent without an id:
line on every stream, because its own cursor is the reset position, offset 0, and resuming
from it would replay the whole log; the cursor stays inside its data. A heartbeat is a comment
line, : heartbeat, sent every 30 seconds; it carries no data and is not an event.
Projection. Raw rows of the Mission’s event log never appear. Only a status transition and seven lifecycle types (MissionCreated, SpecifyStarted, SpecifyCompleted, PlanStarted, PlanCompleted, TasksStarted, TasksCompleted) are forwarded; annotation rows, decision-point rows, retrospective rows, reviewer self-approval rows, work package creation rows and every unknown row are dropped, never forwarded. The seven lifecycle types are owned by this contract and are a subset of the runtime’s twelve; a type added upstream later is dropped.
Scope and ordering. With missionId the stream carries that Mission only; a missionId that names no Mission is answered with 404 before any event is sent. Without it the stream carries every Mission, live only: it never replays and no cursor can be used. A new connection without a cursor is live only from the moment it connects. Order is guaranteed per Mission, in the order of that Mission’s log; there is no order across Missions, and a log-truncated event of one Mission may arrive between events of others.
Resume. A cursor is a StreamCursor position in one Mission’s own physical event log (the
TailCursor of the tail reader, the same position spec-kitty events tail resumes from), so
it is valid for that log only and always needs missionId. Send the id of the last event you
consumed as streamCursor, or let the browser send it as Last-Event-ID. A cursor that cannot
be trusted is refused before any event is sent, with a problem whose code is negative,
out_of_range, misaligned or content_mismatch (the reasons of the tail reader’s
ResumeRefused), or cursor_without_mission when a cursor comes without missionId. The status
of each code is fixed: negative, misaligned and cursor_without_mission are 400; out_of_range
and content_mismatch are 409 (StreamRefusal states this as a checkable rule). A browser
EventSource cannot read the body of a refused connection, it only closes, so a consumer that
must tell these refusals apart opens the stream with a fetch that streams the response body
instead of EventSource. After a log-truncated event on a Mission-scoped stream the last id the
browser holds is the one before the truncation, and a reconnect with it is refused; the consumer
then resynchronises as below.
Consumer actions. On log-truncated, discard the stored cursor of that Mission, read the Mission detail again, and resume from the streamCursor of that detail; the cursor inside the event is only the reset one, offset 0 with the digest of the empty input. A value inside a known kind that a consumer does not know, such as an unlisted eventType, is treated as unknown and is not a failure; the schemas stay closed, so a producer must not send one.
Provisional. These parts are provisional: the framing of the stream and which events carry an id line, the text form of the cursor, the rule that streamCursor wins over Last-Event-ID, the HTTP status of each refusal and the heartbeat interval are conventions owned by this contract; the tail reader has no text form of a cursor and no transport. They are open on #5528 and may change before release. No emitter, server or transport exists yet: this describes a stream that a later change implements.
Parameters
Query Parameters
The canonical machine identity of a Mission: a 26-character Crockford ULID minted when the Mission is created and never changed. Never confuse it with displayNumber, which is display-only and repeats.
Restricts the stream to one Mission, by its 26-character ULID. Without it the stream carries the events of every Mission, live only, and no cursor can be used. The display number is never accepted.
The text form of a StreamCursor: the decimal byte offset, a colon, and the 64 lowercase hexadecimal characters of the invariant, for example an offset of 0 followed by a colon and the digest of the empty input. It is the value of the streamCursor query parameter, of the Last-Event-ID request header and of the SSE id field of the events of a Mission-scoped stream (log-truncated carries no id), all the same string. The offset has no leading zeros, so one cursor has exactly one text. The JSON object form, StreamCursor, is what travels inside the data of an event. It has no relationship to the opaque page cursor used for paging lists.
Resumes the stream of one Mission after the event that carried this cursor, in the text form offset, colon, invariant. It requires missionId: a cursor sent without one is refused with the code cursor_without_mission. The cursor is bound to one physical event log, so a cursor taken from another log is refused with content_mismatch.
Header Parameters
The text form of a StreamCursor: the decimal byte offset, a colon, and the 64 lowercase hexadecimal characters of the invariant, for example an offset of 0 followed by a colon and the digest of the empty input. It is the value of the streamCursor query parameter, of the Last-Event-ID request header and of the SSE id field of the events of a Mission-scoped stream (log-truncated carries no id), all the same string. The offset has no leading zeros, so one cursor has exactly one text. The JSON object form, StreamCursor, is what travels inside the data of an event. It has no relationship to the opaque page cursor used for paging lists.
The same text as streamCursor. A browser sends it by itself when it reconnects, with the id of the last event it received, so the stream resumes where it stopped. It requires missionId in the same way, and only a Mission-scoped stream sends event ids, so a browser never sends it to an unscoped stream. When both this header and streamCursor are sent, streamCursor is used.
Responses
200
The event stream. The connection stays open and carries named events and heartbeat comment lines until either side closes it.
The data of a status-transition event: one work package changed status lane. It is projected from a status-transition row of the Mission’s event log by an allow-list, so no other field of the row is ever shown. missionId is the identity stored in the Mission’s metadata (meta.json), never the aggregate_id of the row: aggregate_id is the Mission ULID only on MissionCreated, the slug on several other rows and the work package id on WPCreated. A row whose wp_id does not match WpId is not a valid event: it is dropped, never forwarded or repaired, and the drop is counted and reported. The allow-list deliberately leaves out these StatusEvent fields: reason, reason_source, review_ref, evidence, review_result, policy_metadata, execution_mode and mission_slug, so adding one later is a contract decision. The schema is closed.
object
Who made the transition, as three handles.
object
The handle of the agent profile the actor used, or null when unknown or not a valid handle.
The handle of the role the actor held, or null when unknown or not a valid handle.
The handle of the agent or tool that acted, or null when unknown or not a valid handle.
When the transition happened, an RFC 3339 date-time with an offset.
The identifier of the event, unique within the Mission’s event log.
True when the transition bypassed the usual guards.
The display state of a work package in the status model. Exactly nine values. The runtime enum also carries genesis and uninitialized, which are not display values: a work package with no events reads as a null status lane, never as one of those two. This is the status lane, not a code lane or the repo-root lane; the contract never groups these values into board columns.
The identity of the Mission whose log carried the transition, from the Mission’s metadata and never from aggregate_id.
The position just after this event in the Mission’s own event log; resume from it.
object
The 64-character lowercase hexadecimal SHA-256 digest of the last consumed line, or the digest of the empty input when the offset is 0. The stored attribute is named content_invariant.
The byte offset in the event log just after the last consumed line; 0 means nothing consumed yet.
The status lane the work package entered.
The work package that changed status lane.
The data of a mission-lifecycle event: a marker that the Mission was created or that one of its planning phases started or completed. Only seven lifecycle types are forwarded, a set owned by this contract and deliberately smaller than the runtime’s list of lifecycle types; a type added upstream later is dropped, not forwarded. missionId is the identity stored in the Mission’s metadata (meta.json), never the aggregate_id of the row. The schema is closed.
object
When the marker was recorded, an RFC 3339 date-time with an offset; the timestamp of the row.
The identifier of the event, unique within the Mission’s event log.
Which lifecycle marker this is. Exactly these seven values are forwarded; every other lifecycle type of the log is dropped. A consumer that meets another value inside this kind treats it as unknown and does not fail.
The identity of the Mission whose log carried the row, from the Mission’s metadata and never from aggregate_id.
The position just after this event in the Mission’s own event log; resume from it.
object
The 64-character lowercase hexadecimal SHA-256 digest of the last consumed line, or the digest of the empty input when the offset is 0. The stored attribute is named content_invariant.
The byte offset in the event log just after the last consumed line; 0 means nothing consumed yet.
The data of a log-truncated event: the Mission’s event log shrank or changed under the reader, so everything the consumer stored for that Mission is stale. It carries a reset cursor, offset 0 with the digest of the empty input. It is sent without an SSE id line, so a browser’s stored Last-Event-ID is never moved to the reset position. The consumer discards the Mission’s stored cursor, reads the Mission detail again and resumes from the streamCursor of that detail. The schema is closed.
object
The byte offset of the cursor the reader held when it detected the truncation.
The identity of the Mission whose log was truncated, from the Mission’s metadata.
Why the reader concluded the log was truncated: size_shrink when the file became shorter than the cursor, content_mismatch when the SHA-256 of the last complete line before the cursor’s offset no longer equals the cursor’s invariant. Only that one line is hashed, not the whole log before the offset. Exactly these two values exist.
The reset cursor: offset 0 and the SHA-256 digest of the empty input, the position of an empty log.
object
The 64-character lowercase hexadecimal SHA-256 digest of the last consumed line, or the digest of the empty input when the offset is 0. The stored attribute is named content_invariant.
The byte offset in the event log just after the last consumed line; 0 means nothing consumed yet.
400
The event stream request was refused before any event was sent. The body is a problem details object whose code names the refusal.
The problem details body of a refused event stream request. It is a Problem whose code is one of five values: negative, out_of_range, misaligned and content_mismatch, which are the reasons of the tail reader’s ResumeRefused, and cursor_without_mission, the refusal of a streamCursor or Last-Event-ID sent without a missionId. A refused request is answered before any event is sent; the stream never resynchronises silently. The status follows from the code: 400 for negative, misaligned and cursor_without_mission, 409 for out_of_range and content_mismatch. Consumers branch on code, never on title.
object
A stable machine-readable code for the problem, such as the name of a refusal reason. Consumers branch on it, never on the title.
A human-readable explanation specific to this occurrence of the problem.
A URI reference that identifies this occurrence of the problem.
The HTTP status code of this occurrence.
A short, human-readable summary of the kind of problem. It does not change between occurrences.
A URI reference that identifies the kind of problem. Absent means about:blank.
Negative: the offset is below 0. out_of_range: the offset is beyond the end of the log. misaligned: the offset is not at the start of a line. content_mismatch: the digest does not match the log at that offset. cursor_without_mission: a cursor was sent with no missionId.
The HTTP status of the refusal, fixed by its code: 400 for negative, misaligned and cursor_without_mission, 409 for out_of_range and content_mismatch.
404
The request failed. The body is a problem details object.
The only non-2xx body of any module. A problem details object in the sense of RFC 9457, served as application/problem+json.
object
A stable machine-readable code for the problem, such as the name of a refusal reason. Consumers branch on it, never on the title.
A human-readable explanation specific to this occurrence of the problem.
A URI reference that identifies this occurrence of the problem.
The HTTP status code of this occurrence.
A short, human-readable summary of the kind of problem. It does not change between occurrences.
A URI reference that identifies the kind of problem. Absent means about:blank.
409
The event stream request was refused before any event was sent. The body is a problem details object whose code names the refusal.
The problem details body of a refused event stream request. It is a Problem whose code is one of five values: negative, out_of_range, misaligned and content_mismatch, which are the reasons of the tail reader’s ResumeRefused, and cursor_without_mission, the refusal of a streamCursor or Last-Event-ID sent without a missionId. A refused request is answered before any event is sent; the stream never resynchronises silently. The status follows from the code: 400 for negative, misaligned and cursor_without_mission, 409 for out_of_range and content_mismatch. Consumers branch on code, never on title.
object
A stable machine-readable code for the problem, such as the name of a refusal reason. Consumers branch on it, never on the title.
A human-readable explanation specific to this occurrence of the problem.
A URI reference that identifies this occurrence of the problem.
The HTTP status code of this occurrence.
A short, human-readable summary of the kind of problem. It does not change between occurrences.
A URI reference that identifies the kind of problem. Absent means about:blank.
Negative: the offset is below 0. out_of_range: the offset is beyond the end of the log. misaligned: the offset is not at the start of a line. content_mismatch: the digest does not match the log at that offset. cursor_without_mission: a cursor was sent with no missionId.
The HTTP status of the refusal, fixed by its code: 400 for negative, misaligned and cursor_without_mission, 409 for out_of_range and content_mismatch.
default
The request failed. The body is a problem details object.
The only non-2xx body of any module. A problem details object in the sense of RFC 9457, served as application/problem+json.
object
A stable machine-readable code for the problem, such as the name of a refusal reason. Consumers branch on it, never on the title.
A human-readable explanation specific to this occurrence of the problem.
A URI reference that identifies this occurrence of the problem.
The HTTP status code of this occurrence.
A short, human-readable summary of the kind of problem. It does not change between occurrences.
A URI reference that identifies the kind of problem. Absent means about:blank.