A small FastAPI payment service with a deliberate double-credit bug, used to show how ByteRover and Claude Code analyze, fix and document an incident so the knowledge is available at coding time.
This repo shows how to capture incident knowledge inside a codebase with ByteRover and Claude Code. It uses a deliberately flawed FastAPI payment service: a rollback operation credits user balances but is not idempotent, so retries cause duplicate credits.
The workflow is to analyze the code, document it, reproduce and fix the bug, store the incident as structured context, and then query that context before changing related code. The point is that a postmortem is present when code is written, not only afterwards.
- Codebase curation:
brv curatehas Claude generate structured documentation from the code alone: overview, entry points, execution paths, shared state, bug analysis and a demo workflow. - Reproducible bug:
demo.pydrives the API through a charge that fails, is rolled back and is retried, which triggers the double credit. - Idempotent fix: an idempotency guard, enforced state transitions and no duplicate balance updates, with rollout and reconciliation steps documented.
- Queryable memory:
brv queryreturns the original bug, why it happened, the approved pattern, code references and rollout constraints. - Context next to code: the generated context tree lives in
.brv/context-tree/in the repo.
| Layer | Tool |
|---|---|
| Context and memory | ByteRover CLI |
| Coding agent | Claude Code |
| Service | FastAPI and Uvicorn |
| Language | Python 3.10 or later |
- Python 3.10 or later
- ByteRover CLI, installed and authenticated
- Claude Code with the ByteRover integration
- Basic familiarity with FastAPI
git clone https://github.com/Studio1HQ/incident-memory.git
cd incident-memory
pip install -r requirements.txtStart the service, then run the demo script that reproduces the bug:
uvicorn app.main:app --port 8000
python demo.pydemo.py calls http://127.0.0.1:8000 and uses the /charge, /charge/{id}/confirm and /charge/{id}/rollback endpoints. The service also exposes /charge/{id}/refund.
app/
main.py FastAPI app
api/routes.py charge, confirm, rollback, refund routes
payment/service.py bug and fix location
payment/store.py in-memory state
payment/models.py data models
demo.py reproduces the failure
CLAUDE.md ByteRover workflow rules for the agent
.brv/context-tree/ generated context: structure, api_design, business_logic, bug_fixes, testing
The workflow, step by step:
- Initialize:
brv initcreates ByteRover rules and enables context capture. - Curate:
brv curatehas Claude analyze the repository and write structured documentation based only on code behavior. - Sync:
brv pushpublishes the context so future engineers and agents can query it. - Fix: the prompt used was: "Using the existing ByteRover context and current codebase, design and implement a correct, idempotent fix for the double-credit bug, explain why previous behavior failed, update the code accordingly, and document the approved fix and rollout considerations as markdown."
- Commit: the fix is committed so code and context evolve together.
- Prevent: before writing code, a future engineer asks:
brv query "What patterns should I follow when modifying user balances in payment operations?"The exact layout of the generated documentation is decided by ByteRover and may change.
This is aimed at backend engineers on critical systems, platform teams supporting AI coding agents, and anyone evaluating ByteRover for institutional memory.
- ByteRover: the context and memory product used here.
- ByteRover docs: CLI commands such as
brv init,brv curate,brv pushandbrv query.
Built by Studio1, the technical content and DevRel partner for devtool teams. Made with ByteRover.
Browse more open-source examples at github.com/Studio1HQ.
studio1hq.com · Technical content, docs, video and DevRel for devtools