Last week I built flagtrail for Toggle Wars, the Flagsmith hackathon run by WeMakeDevs. It's an audit trail for self-hosted Flagsmith that the database can't quietly edit. While testing it I hit something I didn't expect: the change that fixes an incident is the one Flagsmith's audit log doesn't record.
Here's the 3-minute demo, then what happened, why, and how I caught it.
The problem I started with
If you self-host Flagsmith, your flags and your audit log are both ordinary rows in Postgres. That's fine until someone with database access changes a flag directly. It could be a DBA, a bad migration script, or a leaked credential.
A direct UPDATE like that goes around Flagsmith completely:
- customers start getting the new value right away
- no audit record is written
- no webhook fires
And since the audit log is just a table too, the same access can edit the history of what happened.
For most apps that's an edge case. For a bank or a payments company, it's the exact question an auditor asks: show me every change, who made it, and prove nobody altered the record.
So I built flagtrail to watch Flagsmith from the outside.
How flagtrail watches
It compares three sources that are hard to fake all at once:
- What Flagsmith reports: its signed webhooks.
- What Flagsmith actually serves: every environment's environment document, read every few seconds through the Admin API.
- What Flagsmith's audit table admits: read through a read-only Postgres role.
Everything goes into an append-only Merkle log with signed checkpoints (RFC 9162, the same design Certificate Transparency uses for HTTPS certificates). If anyone edits or deletes an old entry, every later proof breaks.
When the sources disagree (the served value changed but there's no webhook and no audit row), it raises a SILENT_CHANGE alert within seconds.
The demo incident
My test case was a made-up bank. In the demo, someone raises daily_transfer_limit from 50,000 to 500,000 straight in the database:
UPDATE features_featurestatevalue SET integer_value = 500000 WHERE feature_state_id = <id>; flagtrail caught that, as designed. Then I fixed it the normal way, through Flagsmith:
flagsmith flag update daily_transfer_limit -e <env key> --value 50000 --type integer --yes And flagtrail raised another alert, this time about the fix.
My first thought was that my code was wrong. It wasn't.
What's actually going on
I reproduced it on Flagsmith 2.294.0:
- An ordinary value change through Flagsmith, by a person in the dashboard or an API key, is audited and sends a webhook. Good.
- But after a direct database write, the change that restores the value writes no audit record and sends no webhook. That holds whether you fix it in the dashboard, through the Admin API or with the CLI.
The cause is in how Flagsmith decides something changed. It builds the audit record from the difference between the new history row (features_historicalfeaturestatevalue) and the previous one. The direct database write never created a history row. So Flagsmith sees:
previous history row: 50000 new history row: 50000 -> "no change", skip the audit record and the webhook It's comparing with what it last recorded, not with what was actually in the database a moment ago.
So in a real incident, the audit log misses both the bad change (expected, it bypassed Flagsmith) and the fix (not expected). The one moment you most need the record is the moment it's empty.
I reported it upstream with a full reproduction: Flagsmith#9185. The suggested fix is small: compare with the value actually stored before the save, not with the last history row.
flagtrail still records the fix, because it doesn't trust the audit log alone. It watches what's actually served.
Letting an agent handle the incident
The other half of the project is an MCP server (14 read-only tools) and an Agent Skill that takes an incident from alert to postmortem with the Flagsmith CLI.
I ran it in Claude Code against the demo incident. It found the database write and worked out who was affected (34 of 40 customers on the $500,000 limit). Then it proposed one exact CLI command to fix it and stopped until I said yes. After the fix, it checked the result in Flagsmith and in what customers were actually served.
It also hit the unrecorded fix, which is why the skill now tells the agent to expect that alert and sign it with an explanation.
Try it
It's MIT licensed and installs in one line, either fresh with demo data or beside your existing Flagsmith:
curl -fsSL https://raw.githubusercontent.com/Ayush-e4/flagtrail/main/install.sh | sh There's also a read-only replay of the console you can click around without installing anything: ayush-e4.github.io/flagtrail/console
- Code: github.com/Ayush-e4/flagtrail
- The upstream issue: Flagsmith#9185
If you self-host Flagsmith (or any flag service) and have dealt with audit requirements, I'd love to hear how you handle out-of-band changes today.
