Every codebase I've worked on has had a ghost. It's a test that passes 29 times and fails on the 30th, usually on the run that matters. We all know the ritual: click re-run, see green, move on. Then the bigger teams add a quarantine list, and the ghost gets a room of its own.
For Kiroween 2026 I wanted to treat that ghost as what it really is: a deterministic bug hiding behind nondeterminism. A test only "flakes" because something outside it changes between runs. That might be the clock, the order tests run in, a timer firing a millisecond late, an unseeded random number, or a slow network call. If you control all of those, the ghost has nowhere to hide.
The four rites
Scan. POLTERGEIST installs a chaos layer under Vitest. Math.random is seeded, the clock can be shifted and the timezone changed, test order is shuffled from a seed, timers get jitter, and fetch gets latency. It runs your suite 30 times under random settings and draws a flicker strip per test. On my haunted demo project it found all six planted ghosts (order dependence, shared state, time of day, network timing, a timer race and unseeded randomness) and never accused the seven healthy controls.
Possess. This is where property-based testing comes in. fast-check usually searches over inputs. Here it searches over chaos vectors. The property is simply "this test passes under this chaos". When fast-check finds a counterexample, it shrinks it to the smallest perturbation that still breaks the test. A 1-in-30 flake becomes a 30-in-30 failure, and POLTERGEIST writes an autopsy: this perturbation, at this line, broke this assertion.
Exorcise. A custom Kiro agent, the Exorcist, runs headless through the Kiro CLI in its own git worktree. It reads the seed and the autopsy and proposes a fix.
Verify. I didn't want an AI that marks its own homework, so six rules in plain TypeScript decide whether a fix ships:
- The seed must reproduce the failure before the fix.
- It must pass 30 of 30 runs after the fix.
- 500 random chaos runs must pass.
- The test must not be weakened.
- The change must stay inside the files named in the autopsy.
- A pinned regression test must be added.
If the agent's fix breaks a rule, it gets the evidence and tries again. After four tries, POLTERGEIST prints GHOST TOO STRONG and refuses to ship.
In the real runs, Kiro's agent fixed the order-dependence, time-of-day and timer-race ghosts in one revision each. Each fix went to 0 failures in 500 chaos runs.
How Kiro built it
The rules for this hackathon are strict: the code has to be written by Kiro. So I treated Kiro like a team I'd hand a spec to.
- Specs: EARS requirements and a 10-task plan. Every task had numeric acceptance checks, such as "at least 29 of 30 reproduction, under 60 seconds".
- Autopilot: a script ran one headless Kiro call per task. It gated each one on build, types and the full test suite, and committed only when everything was green.
- Steering: the six exorcism rules live in steering and in
verify.ts. A design canon made Kiro screenshot its own pages and critique them against reference sites before a task counted as done. - Hooks: a
preToolUsefence blocks the agent from loosening a test in the first place. - The Power: the steering, agent and hooks are packaged as a Kiro Power, so anyone can bring the exorcist into their own repo.
The most satisfying moment came during the live exorcism runs. POLTERGEIST caught a real bug in itself: on Windows, the agent's edits carried a byte-order mark that confused the weakening check. Kiro found it and fixed it.
What I learned
Flakiness is a search problem, and property-based testing is a wonderful search engine once you aim it at time and order instead of inputs. And an AI agent is at its best inside a box with rules it cannot argue with.
Try it in 30 seconds with npx github:let-the-dreamers-rise/poltergeist demo. No account or credits needed.
- Code (MIT): https://github.com/let-the-dreamers-rise/poltergeist
- Live site: https://poltergeist-psi.vercel.app
- Demo video: https://youtu.be/Uhb12wxjcqQ
Built for the Kiroween 2026 hackathon. #KiroweenHackathon26