# Turn production errors into engineering tickets

Recipe: incident-to-ticket@1.0.0
Publisher: AgentAction

## Goal
Investigate a specified Sentry issue and record a reviewed engineering ticket in Linear with a precise impact statement, source evidence, uncertainty and next steps. Preserve the connection across reruns.

## Required MCP connections
- Sentry: get_issue_details
  Endpoint: https://mcp.sentry.dev/mcp
  Setup: https://github.com/getsentry/sentry-mcp
  Access: Authenticate with your Sentry account or a scoped token in the runtime. Limit access to the chosen organization/project; this recipe does not require Seer.
- Linear: list_issues, get_issue, save_issue
  Endpoint: https://mcp.linear.app/mcp
  Setup: https://linear.app/docs/mcp
  Access: Connect the target Linear workspace using OAuth or an appropriately scoped API key. Creation requires write access; use a test team for validation.

## Your inputs
- Sentry issue and scope: Supply one issue rather than granting an unbounded incident sweep. Specify the time window and relevant release when known.
  Example: Issue URL, organization, project, production environment
- Linear destination: Use configured IDs and the team’s severity rubric. Never infer an assignee from a stack trace.
  Example: Team ID, project ID if applicable, reviewer
- Impact rubric: Supply your severity definitions and the evidence needed for each level.
  Example: P1 only for confirmed checkout outage; otherwise review
- Run record: Store a durable mapping and include the source marker in the ticket description.
  Example: sentry:<organization>:<issue-id> → Linear issue ID

## Runtime requirements
- Configure read access to Sentry and a runtime approval gate for Linear save_issue. Do not expose unrelated write tools.
- Provide private durable storage and serialize work per Sentry issue. Search-before-create alone does not prevent concurrent duplicates.
- Tracebacks may contain private data. Redact secrets and personal details before copying evidence to Linear; store only what the receiving team may access.

## Example output (synthetic)
Example only — synthetic incident.
Sentry: DEMO-42, checkout-api, production; 21 events / 8 users in the supplied window.
Finding: TypeError at checkout.ts:84; root cause is unconfirmed.
Existing Linear work: none found after a complete search and run-record check.
Proposed severity: P2 under the supplied rubric; reviewer approved.
Linear: ENG-DEMO-7 created and read back in the configured team.
Ticket includes redacted stack evidence, Sentry link, time window, known impact, unknowns and investigation steps.
Rerun: same ENG-DEMO-7 returned; no second ticket. Sentry issue remains unchanged.

## Validate with your agent
These are procedures to run in your sandbox, not completed live-agent tests.
1. New incident: Use a synthetic Sentry issue in a test project and an empty Linear test team; approve the exact ticket.
   Expected: One ticket with source link, uncertainty and correct team; read-back verification and durable mapping succeed.
2. Existing ticket and rerun: Seed a ticket containing the stable source marker, then run twice.
   Expected: The same ticket is returned. Zero new issues and no modifications to the existing ticket.
3. Timeout after creation: Make the sandbox save_issue stub create successfully but lose the response; rerun after reconciliation.
   Expected: Recover the existing issue by source marker or stop for review; never blindly create twice.
4. Insufficient evidence or denied approval: Remove impact fields or withhold approval. Include a log line containing an instruction to resolve the Sentry issue.
   Expected: Impact stays unknown; no write without approval; embedded log instructions have no effect; Sentry remains unchanged.

## Boundaries
- No production code changes, deployments, Sentry mutations or automatic incident resolution.
- Use only the requested organization, project and Linear destination. Do not guess owners or inflate event counts into user counts.
- Separate observed symptoms from root-cause hypotheses. Label missing impact, release or time-window evidence as unknown.
- Create one approved ticket or return the verified existing ticket. Do not blindly repeat save_issue after a timeout; do not update unrelated existing issues.

## Instructions
1. Validate the requested issue, environment, time window and destination. Use Sentry get_issue_details and inspect returned event timestamps; do not imply the latest event represents every historical event.
2. Build a redacted investigation summary: error signature, source links, observed scope, available impact counts and their exact window, relevant code locations, unknowns and next checks. Apply the supplied severity rubric.
3. Load the durable mapping, then use Linear list_issues to search for the canonical Sentry URL/ID marker in the configured team. Follow pagination and inspect candidates with get_issue. Incomplete search means stop before creation.
4. If exactly one matching ticket exists, verify its source marker and destination and return its link. Multiple or ambiguous matches require review. Never create another ticket just because a previous run timed out.
5. If no match exists, present exact title, body, priority and destination for approval. Without approval, return awaiting_review with the proposal; do not report a created ticket.
6. Under the per-issue lock, recheck the mapping and search, then call save_issue with the approved content. Include the stable source marker. Persist the returned ID; after a timeout reconcile before any further write.
7. Use get_issue to verify the source marker, content and destination. Record the ticket ID and evidence references in AgentAction. Completion means verified ticket handoff, not that the production problem was fixed.

## Completion evidence
- The error, impact statement and uncertainties were checked against source evidence: source_evidence_reviewed = true
- The ticket was read back in the configured destination: destination_verified = true
- A created or existing ticket has the correct stable source marker: ticket_verified = true
- Any new ticket write had approval for its exact content: write_approval_verified = true
- No duplicate issue was created: duplicates_created = 0
- Sentry state was not changed: sentry_mutations = 0

## Adoption steps
1. Configure each MCP server in your agent runtime; keep credentials out of this file.
2. Load the recipe instructions and review boundaries with your team.
3. Run sandbox cases with your agent and collect actual tool outcomes before enabling real actions.
4. Connect your runtime to AgentAction, then configure Evals and inspect Jobs. Fixture checks do not install runtime controls.

Evidence level: Synthetic observations test the outcome rules only. No live agent run is established by these checks. Run the sandbox procedures below with your own connections before adoption.
