> ## Documentation Index
> Fetch the complete documentation index at: https://docs.codecobra.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Reconnect Task Stream

> Reconnect to an active SSE stream for a task.
If a stream is currently in progress (or recently finished), replays all
buffered events and then subscribes to live events until the stream ends.
Returns 204 if no active stream exists for this task.

Uses Redis Streams for replay (XRANGE) and live following (XREAD BLOCK).
This is race-condition-free: XRANGE returns all events up to now, then
XREAD picks up exactly where XRANGE left off using the last event ID.
Keepalive events are sent every 15s during live following to prevent
proxy/client disconnects.

``after``: optional Redis Stream id (as returned in
``TaskMessageResponse.last_event_id``).  If present, only events
*strictly after* this id are replayed — this lets a reconnecting
client combine a DB snapshot with a live delta without duplicating
content already persisted.  If the cursor has fallen off the buffer
the response contains a single ``{type: "resync_required"}`` SSE event
and the client should refetch ``/messages`` as the source of truth.



## OpenAPI

````yaml /openapi.json get /api/tasks/{task_id}/stream
openapi: 3.1.0
info:
  description: >-
    Public CodeCobra API. Authenticate by sending a personal API key in the
    `Authorization: Bearer <key>` header. Generate keys from Settings → API keys
    in the CodeCobra dashboard.
  title: CodeCobra Public API
  version: 1.0.0
servers: []
security: []
paths:
  /api/tasks/{task_id}/stream:
    get:
      tags:
        - public
      summary: Reconnect Task Stream
      description: >-
        Reconnect to an active SSE stream for a task.

        If a stream is currently in progress (or recently finished), replays all

        buffered events and then subscribes to live events until the stream
        ends.

        Returns 204 if no active stream exists for this task.


        Uses Redis Streams for replay (XRANGE) and live following (XREAD BLOCK).

        This is race-condition-free: XRANGE returns all events up to now, then

        XREAD picks up exactly where XRANGE left off using the last event ID.

        Keepalive events are sent every 15s during live following to prevent

        proxy/client disconnects.


        ``after``: optional Redis Stream id (as returned in

        ``TaskMessageResponse.last_event_id``).  If present, only events

        *strictly after* this id are replayed — this lets a reconnecting

        client combine a DB snapshot with a live delta without duplicating

        content already persisted.  If the cursor has fallen off the buffer

        the response contains a single ``{type: "resync_required"}`` SSE event

        and the client should refetch ``/messages`` as the source of truth.
      operationId: reconnect_task_stream_api_tasks__task_id__stream_get
      parameters:
        - in: path
          name: task_id
          required: true
          schema:
            format: uuid
            title: Task Id
            type: string
        - in: query
          name: after
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            title: After
      responses:
        '200':
          content:
            application/json:
              schema: {}
          description: Successful Response
        '422':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
          description: Validation Error
      security:
        - HTTPBearer: []
components:
  schemas:
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          title: Detail
          type: array
      title: HTTPValidationError
      type: object
    ValidationError:
      properties:
        ctx:
          title: Context
          type: object
        input:
          title: Input
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          title: Location
          type: array
        msg:
          title: Message
          type: string
        type:
          title: Error Type
          type: string
      required:
        - loc
        - msg
        - type
      title: ValidationError
      type: object
  securitySchemes:
    HTTPBearer:
      scheme: bearer
      type: http

````