---
title: "Task Diff"
method: GET
path: "/api/v1/dashboard/tasks/{task_id}/diff"
---

# Task Diff

`GET /api/v1/dashboard/tasks/{task_id}/diff`

Return the diff for a task's working branch against the base ref.

Strategy:
    1. Resolve the working branch from the task's ``assigned_agent`` --
       ``agent/<session-id>``. If no agent is assigned (or the branch
       does not exist yet), fall back to ``git diff HEAD`` so the user
       still sees uncommitted scratch work.
    2. Run ``git diff <base>...<branch>`` (three-dot, symmetric
       difference relative to the merge base) and parse the output into
       a structured per-file representation.
    3. Cap the unified diff at ``_DIFF_MAX_BYTES`` to keep payloads sane.

The sync ``_run_git`` helper is reused (it is also called from other
sync helpers in this module). To keep the event loop responsive under
load (issue #1723) every blocking ``_run_git`` invocation is offloaded
to the default executor via ``asyncio.to_thread``. The helper itself
stays sync so non-route callers keep working.

## Path parameters

- `task_id` string, required

## Response `200`

Successful Response

- TaskDiffResponse — Diff payload for a task's working branch vs the base ref.
  - `task_id` string, required
  - `branch` string, nullable, required
  - `base_ref` string, required
  - `head_ref` string, nullable, required
  - `additions` integer, required
  - `deletions` integer, required
  - `files` DiffFile[], required
    - `path` string, required
    - `old_path` string, nullable
    - `status` string
    - `additions` integer
    - `deletions` integer
    - `binary` boolean
    - `language` string, nullable
    - `hunks` DiffHunk[]
      - `header` string, required
      - `old_start` integer, required
      - `old_lines` integer, required
      - `new_start` integer, required
      - `new_lines` integer, required
      - `lines` string[], required
  - `unified` string, required
  - `truncated` boolean
  - `generated_at` number, required
  - `note` string, nullable

## Other responses

- `404` — Task not found
- `422` — Validation Error

---

[API](https://skmtc.net/sipyourdrink-ltd/apis/bernstein-task-server.md) · [All operations](https://skmtc.net/sipyourdrink-ltd/apis/bernstein-task-server/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/sipyourdrink-ltd/bernstein-task-server/revisions/86f514b4e920/schema)
