Overview
This playbook teaches you to resolve bugs systematically using an AI coding agent connected to CoreStory’s code intelligence via MCP. Instead of grep-wandering through a codebase, the agent queries CoreStory to understand how the system should work, generates hypotheses about what went wrong, writes a failing test to confirm the bug, and implements a minimal fix — all with architectural context that would normally require senior-engineer-level familiarity with the code. CoreStory serves two roles in this workflow:- Oracle — answers questions about intended system behavior, invariants, business rules, and design history. This is context you can’t get from code search alone; it synthesizes PRDs, technical specs, user stories, and code history into coherent answers.
- Navigator — points to specific files, methods, and code paths relevant to a bug. Instead of blind searching, the agent gets directed guidance on where to look.
Prerequisites
Required:- A CoreStory account with at least one project that has completed ingestion
- The CoreStory MCP server installed and configured in your AI agent
- A code repository the agent can read and write to
- A ticketing system MCP (GitHub Issues, Jira, Azure DevOps, or Linear) so the agent can fetch ticket details and post updates automatically
- Agent-specific configuration files (skill files, custom instructions, project rules) — covered in the Agent Implementation Guides section below
How It Works
The Six-Phase Workflow
The workflow has six phases. The first three gather context; the last three act on it. Phase 1 — Bug Intake. The agent pulls the bug ticket (or accepts a description), selects the relevant CoreStory project, and creates a dedicated investigation conversation. This conversation persists as institutional knowledge. Phase 2 — Oracle Phase. The agent queries CoreStory to understand how the system is supposed to work: which files implement the affected feature, what data structures and invariants are involved, and what design history exists. This happens before looking at code. Phase 3 — Navigator Phase. The agent asks CoreStory to map the bug’s symptoms to specific code paths, generate ranked root cause hypotheses, and identify exact files and methods to investigate. Phase 4 — Test-First Investigation. The agent writes a failing test that reproduces the bug before reading any implementation code. It validates the test with CoreStory, then reads the identified code to pinpoint the root cause. Phase 5 — Solution Development. The agent implements a minimal fix, verifies the test passes, validates the fix with CoreStory against architectural constraints, adds edge case tests, and runs the full test suite. Phase 6 — Completion. The agent updates the ticket, commits with a structured message explaining the root cause and fix rationale, renames the CoreStory conversation to mark it resolved, and reports results.CoreStory MCP Tools Used
| Tool | Purpose |
|---|---|
CoreStory:list_projects | Find available projects |
CoreStory:get_project | Verify project status and details |
CoreStory:get_project_stats | Check ingestion/processing status |
CoreStory:create_conversation | Start a dedicated investigation thread |
CoreStory:send_message | Query code intelligence (streaming) |
CoreStory:get_conversation | Retrieve conversation history |
CoreStory:rename_conversation | Mark conversation as resolved |
CoreStory:get_project_prd | Access PRD for requirements context |
CoreStory:get_project_techspec | Access technical specifications |
Ticketing MCP Integrations (Optional)
The agent can fetch ticket details and post updates automatically if you configure a ticketing MCP server. Each platform now offers an official MCP server — check their documentation for current setup instructions:| System | Official MCP Server | Sample Prompt |
|---|---|---|
| GitHub Issues | GitHub MCP Server | ”Fetch GitHub issue #6992 from pydata/xarray” |
| Jira | Atlassian Rovo MCP Server — see our Jira Integration playbook for setup | ”Fetch Jira ticket PROJ-1234” |
| Azure DevOps | Azure DevOps MCP Server | ”Get work item 12345 from Azure DevOps” |
| Linear | Linear MCP Server | ”Retrieve Linear issue ENG-456” |
Step-by-Step Walkthrough
This section is agent-agnostic. The prompts work with any MCP-connected agent. Agent-specific configuration is in the Implementation Guides below.Phase 1: Bug Intake & Context Gathering
Goal: Import bug details and prepare the investigation environment. Step 1 — Pull the bug ticket. If you have a ticket ID, ask the agent to fetch it:conversation_id and uses it for all subsequent queries. This conversation becomes searchable institutional knowledge — future engineers investigating similar bugs can reference it.
Phase 2: Understanding System Behavior (Oracle Phase)
Goal: Establish ground truth about how the system should work before investigating what’s wrong. This phase is the key differentiator. Without it, you risk fixing symptoms instead of root causes, breaking adjacent functionality, or missing architectural constraints that explain why the code works the way it does. Query 1 — Architecture Discovery:Phase 3: Hypothesis Generation (Navigator Phase)
Goal: Translate symptoms into specific, actionable investigation targets. Query 1 — Map symptoms to code paths:Phase 4: Test-First Investigation
Goal: Write a failing test before reading implementation code. This is non-negotiable. Why test-first for bugs? A failing test proves the bug exists, a passing test proves it’s fixed, and the test prevents the bug from recurring. It also forces the agent to articulate what “correct behavior” means before getting lost in implementation details. Step 1 — Write a reproduction test. Based on the expected behavior (Phase 2) and symptoms (Phase 1):Phase 5: Solution Development
Goal: Implement a minimal fix, verify it, and add comprehensive test coverage. Step 1 — Implement the minimal fix. The smallest change that restores the invariant, following architectural patterns CoreStory described. Step 2 — Verify the test passes. Run the reproduction test from Phase 4. If it still fails, the fix is incomplete. Step 3 — Validate with CoreStory:Phase 6: Completion & Knowledge Capture
Goal: Close the loop and preserve knowledge. Step 1 — Update the ticket (if ticketing MCP is configured). Add investigation summary, root cause, fix description, and commit link. Step 2 — Commit with structured context:Prompting Patterns Reference
These patterns work with any MCP-connected agent querying CoreStory.Investigation Patterns
Architecture Discovery:Validation Patterns
Fix Validation:Context Patterns
Historical Context:Efficient Multi-Query Pattern
When you want comprehensive context in one shot:Advanced Patterns
Security-Sensitive Bugs
When the bug involves authentication, authorization, data handling, or external input, add a security check to Phase 2:Integration Impact Analysis
When the bug is in a shared component, check downstream effects in Phase 3:Performance Bugs
When investigating slowness, timeouts, or resource issues:Related Bug Clusters
When multiple tickets look related:Agent Implementation Guides
Claude Code
Setup
- Configure the CoreStory MCP server in your Claude Code settings (see CoreStory MCP Server Setup Guide).
-
Add the skill file. Claude Code uses skills (
.claude/skills/directory) as its preferred mechanism for teaching Claude specialized workflows. Create the skill:
.claude/skills/bug-resolver/SKILL.md with the content from the skill file below.
- (Optional) Add the slash command. Slash commands provide a shortcut to invoke the workflow:
.claude/commands/fix-bug.md with the content from the command file below.
- Commit to version control for team sharing:
Usage
The skill activates automatically when Claude Code detects bug-related requests:Tips
- Skills auto-load from directories added via
--add-dir, so team-shared skills work across machines. - Claude Code detects file changes during sessions — you can edit the skill file and it takes effect immediately.
- Keep the SKILL.md under 500 lines for reliable loading.
- The skill file includes structured output templates so Claude reports progress at each phase.
Skill File
Save as.claude/skills/bug-resolver/SKILL.md:
Slash Command
Save as.claude/commands/fix-bug.md:
GitHub Copilot
Setup
- Configure the CoreStory MCP server in your VS Code settings. Add it to your MCP server configuration (typically in VS Code settings JSON or the MCP configuration UI).
-
Add custom instructions. Copilot reads project-level instructions from
.github/copilot-instructions.md. This is the primary mechanism for teaching Copilot specialized workflows:
.github/copilot-instructions.md with the content from the custom instructions file below.
-
(Optional) Add a reusable prompt file. Prompt files (
.github/prompts/fix-bug.prompt.md) provide reusable task templates. See the prompt file below. - Commit to version control:
Usage
In Copilot Chat (agent mode), natural language triggers the workflow:Tips
- Copilot’s agent mode (available in VS Code) can execute terminal commands and edit files autonomously — this workflow works best in agent mode.
- You can add path-specific instruction files (e.g.,
.github/instructions/backend.instructions.mdwithapplyTo: "src/backend/**") for component-specific guidance. - On Team/Enterprise plans, organization-level instructions apply across all repositories.
- Copilot automatically references
.github/copilot-instructions.mdin chat responses.
Custom Instructions
Save as.github/copilot-instructions.md:
Prompt File (Optional)
Save as.github/prompts/fix-bug.prompt.md:
Cursor
Setup
- Configure the CoreStory MCP server in Cursor’s MCP settings (Settings → MCP Servers, or edit the MCP config JSON directly).
-
Add project rules. Cursor uses rules in
.cursor/rules/directories. Each rule folder contains aRULE.mdfile:
.cursor/rules/bug-resolver/RULE.md with the content from the rule file below.
- Commit to version control:
Usage
In Cursor’s Composer or Chat, the rule activates automatically for bug-related requests:Tips
- Rules with
alwaysApply: trueload in every session. Set this if your team regularly fixes bugs. Otherwise, usealwaysApply: falsewith a gooddescriptionso Cursor loads it intelligently when relevant. - The legacy
.cursorrulesfile still works but the.cursor/rules/directory structure is the current recommended approach. - Rules apply to Composer and Chat but do not affect Cursor Tab or inline edits (Cmd/Ctrl+K).
- On Team/Enterprise plans, team rules apply across all members.
Project Rule
Save as.cursor/rules/bug-resolver/RULE.md:
Factory.ai
Setup
-
Configure the CoreStory MCP server in your Factory.ai environment. Verify with the
/mcpcommand that CoreStory tools are accessible. -
Add the custom droid. Factory.ai uses droids stored in
.factory/droids/(project-level) or~/.factory/droids/(personal):
.factory/droids/bug-resolver.md with the content from the droid file below.
- Commit to version control (for project-level droids):
Usage
Invoke the droid via the Task tool:Tips
- Use
model: inheritin the YAML frontmatter to use whatever model the session is configured with. - The
toolsfield in frontmatter can explicitly list required MCP tools if you want to restrict the droid’s capabilities. - The Task tool that invokes droids requires experimental features to be enabled.
- For complex bugs, the droid’s CoreStory queries may produce long streaming responses — this is expected.
Custom Droid
Save as.factory/droids/bug-resolver.md:
Tips & Best Practices
Ask specific questions. “Tell me everything about reset_index” gets a sprawling response. “What is the relationship between _coord_names and _variables during reset_index with drop=True?” gets a precise, useful answer. Paste code in your CoreStory queries. When validating a hypothesis or fix, include the actual code snippet. CoreStory gives much better answers when it can see what you’re looking at. Trust the test-first discipline. It’s tempting to skip straight to reading code, especially when you think you know where the bug is. The failing test is worth the five minutes — it catches false assumptions, documents the bug, and prevents regressions. Use the CoreStory conversation as a review artifact. Before your fix goes through code review, share the CoreStory conversation link. Reviewers can see the full investigation context: what invariants were identified, what hypotheses were considered, and why this fix was chosen. Name conversations descriptively. “Bug Investigation: #6992 - reset_index coord_names cleanup” is searchable and useful six months later. “Bug fix” is not. Don’t fight the phases. If you’re tempted to jump from Phase 1 to Phase 5, you’re optimizing for speed on this bug at the cost of quality. The Oracle Phase in particular catches architectural constraints that would otherwise become failed code reviews or production regressions. Let the agent complete the workflow. Interrupting mid-workflow loses accumulated context. If you need to redirect, explain why rather than just changing the subject.Troubleshooting
CoreStory returns generic answers. Your queries are too broad. Instead of “Tell me about the auth system,” try “What files handle JWT token validation? What invariants must the token payload satisfy?” Include specific variable names, method names, or code snippets. Project not found or ingestion incomplete. RunCoreStory:get_project_stats to check status. If ingestion is still running, wait for it to complete — queries against partially-ingested projects give incomplete answers. Verify the project name matches exactly.
The reproduction test passes (bug not reproduced).
Three possibilities: the bug was already fixed, the reproduction steps are wrong, or the test isn’t testing what you think it is. Ask CoreStory to verify your understanding of expected behavior. Check if the bug is environment-specific or version-specific.
Fix causes regressions.
Don’t commit. Run CoreStory:send_message asking about integration impacts: “What other components depend on [feature]? What downstream effects could my change to [behavior] have?” Revise the fix to be more targeted, or add compatibility handling for dependent components.
CoreStory response is too long or gets cut off.
Break your query into smaller, more specific questions. Instead of one query covering architecture + invariants + history, send them separately.
Agent doesn’t follow the workflow.
If you’re using the agent configuration files (skill/instructions/rules/droid) and the agent still doesn’t follow the six-phase workflow, check that the configuration file is in the correct location and format for your agent. See the Agent Implementation Guides above for exact paths.