Kiro 在第 13,497 次執行中推翻團隊定理:打造 PhantomFork 參加 Kiroween 2026
At Run 13,497, Kiro Disproved Our Own Theorem: Building PhantomFork for Kiroween 2026
Kiro 透過 fast-check 的 property-based testing,在第 13,497 次執行中推翻 PhantomFork 規格中的 C5 因果錐定理。團隊將定理改為雙向局部因果閉包,並保留觸發問題的反例作測試。PhantomFork 是確定性離散事件模擬骨架,支援回溯故障、注入反事實幹預並比對結果。
Written as part of the **Kiroween 2026 Hackathon* (Skeleton Crew category + Best Kiro Crew App).*
- Live Demo (zero login, zero API keys): https://phantomfork.vercel.app
- Main Skeleton Repo (MIT): https://github.com/lingfengQAQ/phantomfork
- Kiro Crew App Repo (MIT): https://github.com/lingfengQAQ/phantomfork-crew
- 2:09 HD Demo Video:
The Problem: Postmortems Argue About Counterfactuals Without Proof
Every incident postmortem ends with the same unprovable question:
"If we had capped retry budget at 2 before the Postgres pool drained, would those 2,341 failed checkouts have survived?"
Normally you answer with intuition because the production incident is already dead and buried. For Kiroween 2026, we built PhantomFork — a deterministic discrete-event simulation skeleton (@phantomfork/spine) and reusable React UI kit (@phantomfork/ui) where you rewind a failure, inject one counterfactual intervention at a single tick, and get a deterministic proof of which failures vanish.
Because we entered Skeleton Crew, the exact same zero-dependency kernel drives two completely separate apps in one repo:
-
Incident Autopsy (
/autopsy/) — An SRE war room opening in the middle of a03:14checkout cascade (2,341 dead checkouts). Scrub to tick37, fork$flag:retryBudget = 2, and watch dead requests roll to0, guided by The Coroner, a deadpan ghost. -
Manor Séance (
/seance/) — A Gothic midnight murder mystery at Ashgrove Manor powered by the exact same kernel. Keep the library candle lit at tick38: Clara spots Dr. Thorne spiking the brandy, Lady Ashgrove refuses the glass, and her verdict flips fromMURDEREDtoSURVIVED MIDNIGHTunder the disapproving gaze of Butler Wexley.
What Changed How We Build With Kiro
Before Kiro, writing an AI-assisted multi-package codebase usually turned into endless prompt reminders: "Don't use Math.random() inside domain rules, don't break the UI types, keep test suites isolated."
With Kiro (Kiro IDE + Kiro CLI running claude-opus-5.5), we inverted the workflow so the workspace itself enforced invariants while parallel agents worked in isolated worktrees:
-
EARS Specs + Frozen Contracts First (
.kiro/specs/): Five full specs (spine-kernel,ui-kit,incident-autopsy,manor-seance,mcp-and-power) lockedpackages/spine/src/types.tsandpackages/ui/src/types.tsbefore parallel workers built both apps, MCP server, and Kiro Power. -
Path-Scoped Steering (
.kiro/steering/): Instead of stuffing a giant rules doc into every prompt, three targeted steering files activate only when touching matching globs:-
**/domain/**loadsdeterminism-rules.md(rules may only read/write throughctx); -
**/*.test.tsloadspbt-testing.md(write the property before the fix, preserve shrunk counterexamples); -
**/copy.tsloadsghost-voice.md(140-char cap, every ghost line tells you the next tap).
-
-
PreToolUsePurity Hook (.kiro/hooks/phantomfork-hooks.json):purity-guardintercepts proposed edits before they touch disk (exit 2with a haunted error message ifMath.random,Date.now,performance.now, ornew Date()appears in domain code). While testing against real Kiro CLIfs_writepayloads, we even caught that our initial hook script didn't inspect Kiro CLI'sfile_text/new_strfields — fixed and verified! -
Letting Kiro Do the Search Over MCP (
.kiro/agents/outage-detective.json): Rather than writing a brute-force parameter optimizer inside our TypeScript engine, we exposed 5 compact stdio MCP tools (list_scenarios,simulate,fork,diff,explain, each response capped< 8 KB). Our customoutage-detectiveKiro agent searches counterfactuals autonomously and discoversset $flag:retryBudget = 2 @ t37(1,119 < 1,136events) on its own.
The Highlight: Run 13,497 Disproved Our Own Spec Theorem
Property-based testing (fast-check) was not just a checkbox — Kiro proved our own specification theorem wrong.
Our blueprint originally stated Property C5 (Causal Cone Soundness) as:
"If you cancel event
e, every divergent event in the forked timeline must lie insidee's forward causal cone (impact(e))."
With a simple random domain generator (~3.5 events), fast-check agreed for 2,000 runs. Once we enriched the generator (branching spawns, depth up to 4, up to 119 events), fast-check shattered C5 at Run 13,497 (seed 7) and shrank it in 88 steps to three stark rules:
a@1 writes k.
x@2 reads k; if k is unset, it spawns w@3, which writes j.
q@4 reads j and writes out.
Think about why that breaks the "theorem":
- In the parent timeline,
awritesk, soxnever spawnsw. Thereforeqis never ina's forward causal coneimpact(a). - When you cancel
a,kstays unset, soxcreatesw,wwritesj, andqdiverges!
Counterfactuals can create writers that never existed in the parent timeline.
We replaced C5 with sound bidirectional local causal closure (every divergent event after e.at has a divergent spawn parent or last writer in either timeline), preserved both the shrunk seed-7 counterexample and a hand-minimized "hidden-writer" test in packages/spine/test/k7-conformance.test.ts, and updated our UI contract so diff() is presented as ground truth and the causal cone as explanation.
Meanwhile, Per-Event Common Random Numbers (sfc32(domain.seed, event.id)) guarantee non-interference across unrelated subsystems: auth-svc heartbeat jitter in Incident Autopsy and Chef Moreau's kitchen timers in Manor Séance remain byte-identical across every fork.
Taking It Into Kiro Crew (phantomfork-crew)
We also packaged the engine into a standalone persistent Kiro Crew App (https://github.com/lingfengQAQ/phantomfork-crew) using Kiro Crew's @kirocrew/app-sdk, aiohttp RouteRegistry hooks, owner-gated persistent ledger storage, stdio MCP server, and persistent phantomfork-outage-detective and phantomfork-timeline-auditor Crew agents — so teams can dispatch autonomous postmortem investigations directly inside Kiro Crew.
Try PhantomFork Yourself (Zero Setup)
- Open https://phantomfork.vercel.app — land straight inside the
03:14checkout cascade, clickFork @ tick 37: retryBudget = 2to watch 2,341 dead requests drop to 0, then click Manor Séance in the top bar to save Lady Ashgrove using the exact same engine. - Or install the Kiro Power locally:
git clone https://github.com/lingfengQAQ/phantomfork
cd phantomfork && npm install && npm test # 129/129 green across 5 workspaces
kiro-cli powers install ./power/phantomfork
Happy haunting & deterministic forking! 👻🎃
來源:DEV Community · dev.to