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

# Task Graph Diff

> Return the net delta per resource for a task.

Every ``task->mutated->resource`` edge is rolled up server-side
into a per-resource net delta: create + many updates collapses to
a single ``create``; create + delete collapses to a ``noop``; etc.
The fields_changed list on each entry is the union of top-level
fields that differ between the earliest before and the latest
after snapshots.

The endpoint scans up to ``settings.MAX_GRAPH_DIFF_MUTATIONS``
edges per request. Tasks with more mutations than the cap return
a partial rollup marked ``truncated=true`` — use the paginated
``/mutations`` endpoint for the full audit trail.

Sensitive fields on the snapshots are masked by default. Pass
``reveal=true`` to return actual values, matching the
``/resources`` endpoint's convention.

Returns:
    ``GraphDiff`` with per-resource net deltas and the raw mutation
    count.

Raises:
    NotFoundError: If task not found.



## OpenAPI

````yaml https://api.pragmatiks.io/openapi.json get /agents/tasks/{task_id}/graph-diff
openapi: 3.1.0
info:
  title: Pragma API
  version: 0.1.0
servers: []
security: []
paths:
  /agents/tasks/{task_id}/graph-diff:
    get:
      tags:
        - tasks
      summary: Task Graph Diff
      description: |-
        Return the net delta per resource for a task.

        Every ``task->mutated->resource`` edge is rolled up server-side
        into a per-resource net delta: create + many updates collapses to
        a single ``create``; create + delete collapses to a ``noop``; etc.
        The fields_changed list on each entry is the union of top-level
        fields that differ between the earliest before and the latest
        after snapshots.

        The endpoint scans up to ``settings.MAX_GRAPH_DIFF_MUTATIONS``
        edges per request. Tasks with more mutations than the cap return
        a partial rollup marked ``truncated=true`` — use the paginated
        ``/mutations`` endpoint for the full audit trail.

        Sensitive fields on the snapshots are masked by default. Pass
        ``reveal=true`` to return actual values, matching the
        ``/resources`` endpoint's convention.

        Returns:
            ``GraphDiff`` with per-resource net deltas and the raw mutation
            count.

        Raises:
            NotFoundError: If task not found.
      operationId: tasks-task_graph_diff
      parameters:
        - name: task_id
          in: path
          required: true
          schema:
            type: string
            title: Task Id
        - name: reveal
          in: query
          required: false
          schema:
            type: boolean
            description: Reveal sensitive field values on before/after snapshots
            default: false
            title: Reveal
          description: Reveal sensitive field values on before/after snapshots
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GraphDiff'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
components:
  schemas:
    GraphDiff:
      properties:
        task_id:
          type: string
          title: Task Id
        resources:
          items:
            $ref: '#/components/schemas/ResourceNetDelta'
          type: array
          title: Resources
        total_mutations:
          type: integer
          title: Total Mutations
        total_mutations_scanned:
          type: integer
          title: Total Mutations Scanned
        truncated:
          type: boolean
          title: Truncated
          default: false
        has_more:
          type: boolean
          title: Has More
          default: false
      type: object
      required:
        - task_id
        - resources
        - total_mutations
        - total_mutations_scanned
      title: GraphDiff
      description: |-
        Top-level graph diff response for a task.

        Attributes:
            task_id: Task SurrealDB record id part. Echoed back so clients
                can correlate the response with the request.
            resources: Net delta per affected resource. Ordered by
                ``(resource_table, resource_id)`` for deterministic output.
            total_mutations: Raw mutation edge count folded into the
                rollup. When ``truncated`` is ``True`` this is the cap,
                not the real total — the real total is not known without
                a full scan.
            total_mutations_scanned: Number of mutation edges actually
                consumed from the database before the rollup was cut off.
                Equals ``total_mutations`` in the common (non-truncated)
                case. Exposed so clients can surface "5000 mutations
                scanned" when ``truncated`` is ``True``.
            truncated: ``True`` when the task had more mutation edges than
                the configured cap (``settings.MAX_GRAPH_DIFF_MUTATIONS``).
                The rollup is still safe to display but does not reflect
                every mutation. Clients should direct users to the
                paginated ``/mutations`` endpoint for the full audit trail.
            has_more: Alias for ``truncated`` — kept for clients that use
                the has-more convention.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    ResourceNetDelta:
      properties:
        resource_table:
          type: string
          title: Resource Table
        resource_id:
          type: string
          title: Resource Id
        net_operation:
          type: string
          enum:
            - create
            - update
            - delete
            - noop
          title: Net Operation
        before:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Before
        after:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: After
        fields_changed:
          items:
            type: string
          type: array
          title: Fields Changed
          default: []
        mutation_count:
          type: integer
          title: Mutation Count
          default: 0
      type: object
      required:
        - resource_table
        - resource_id
        - net_operation
      title: ResourceNetDelta
      description: |-
        Net delta for a single resource across a task's mutation sequence.

        The net delta is the last-winning projection of every mutation for
        the same ``(resource_table, resource_id)`` pair ordered by timestamp.
        Create + delete collapses to ``net_operation = "noop"`` because the
        resource neither exists before nor after the task — there is nothing
        for the reviewer to scan.

        Attributes:
            resource_table: SurrealDB table for the affected resource.
            resource_id: SurrealDB record id part (no table prefix).
            net_operation: One of:
                - ``create`` — resource did not exist before the task and
                  exists after (any number of intermediate updates collapse
                  into this one shape).
                - ``update`` — resource existed before and after the task,
                  with at least one mutation that changed its observable
                  state.
                - ``delete`` — resource existed before the task and does not
                  after.
                - ``noop`` — resource was created and then deleted inside the
                  same task; the net effect is that the resource never
                  existed. Also used when a no-op update produced no field
                  changes.
            before: First observed before snapshot, or ``None`` when the
                net effect is a create (nothing to compare against) or a
                noop via create+delete.
            after: Last observed after snapshot, or ``None`` when the net
                effect is a delete or noop.
            fields_changed: Union of all top-level fields that differ between
                the earliest before and the latest after snapshots. Built
                from the same pure diff helper the storage layer uses.
            mutation_count: Number of raw ``mutated`` edges collapsed into
                this net delta. Useful for rendering "3 changes" badges.
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
        ctx:
          type: object
          title: Context
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError

````