---
name: cqa-bug-fix
description: ContextQA Bug Fix Workflow
---

# ContextQA Bug Fix Workflow

You are starting a ContextQA bug fix session. Follow every step below exactly.

## Step 1 — Gather inputs

You need two things before calling any tool:
- **Ticket**: a Linear ticket URL, or plain-text bug description
- **App URL**: the public URL where the bug occurs (e.g. a Cloudflare tunnel URL)

If the user has not provided both, ask for them now before proceeding.

## Step 2 — Fetch the ticket content (if a URL was given)

If the ticket is a Linear URL (e.g. `https://linear.app/...`), you MUST call the Linear MCP tool (`mcp__claude_ai_Linear__get_issue`) to retrieve the full ticket body before proceeding. Do NOT pass the raw URL as `ticket_text` to `bug_fix_from_ticket`. Pass the actual ticket content returned by Linear MCP.

## Step 3 — Call `bug_fix_from_ticket`

Call `bug_fix_from_ticket` with:
- `ticket_text`: the actual ticket content (from Step 2)
- `url`: the app URL
- `deployment_info`: describe how local changes reach the app URL. Default assumption: **local file saves are immediately live via Cloudflare tunnel — there is no build or deploy step.**

## Step 4 — Execute the fix/verify loop

Follow the `fix_guide` returned by `bug_fix_from_ticket` exactly:

1. Poll `get_execution_status(session_id=<session_id>)` — or `get_execution_status(test_case_id=<id>)` when the run has no session — until `is_completed` is true, then read `result` (`SUCCESS`/`FAILURE`) and `result_id` straight off the payload
2. Call `investigate_failure(result_id=<result_id>)` to collect all evidence
3. Call `post_run_comment(...)` then `Linear:save_comment` with the returned body
4. Apply the fix to the codebase using the evidence
5. Call `verify_bug_fix(test_case_id=<id>)` — repeat from step 1 until PASSED or no further fix is possible
6. Call `report_fix_to_ticket(...)` then `Linear:save_comment` with the returned body

## Deployment rules — read carefully, never violate

- The app URL is the **live target**. Every `verify_bug_fix` run tests the current live state of the app.
- Local file saves are **immediately reflected** at the app URL. Do not assume a deployment step is needed unless the user explicitly says so.
- A **FAILED** verification test means the fix did not work. Never attribute failure to the fix not being deployed yet. Treat every failure as the fix being incorrect or incomplete.
- Every code change **MUST** be followed by a `verify_bug_fix` call before reporting to the ticket.
- Only call `report_fix_to_ticket` once `verify_bug_fix` has returned a real result: PASSED → `FIXED`, cannot fix further → `FAILED`.
