Debugging the Engine
Most v2 bugs come to you as “when my game does X, Y happens”. This page is about getting from that sentence to the line of code: reproducing it in the smallest game you can, watching the engine while it happens, and finding when it started.
Reproduce it in the smallest game
Copy the starter game and give it only the statements the report needs:
cp -r dist /tmp/game-bugEdit /tmp/game-bug/js/script.js (keep its declarations, replace the Start label), serve the folder (cd /tmp/game-bug && python3 -m http.server 8080) and open it. The copy has its own engine/core/monogatari.js: after you change src/ and rebuild, copy dist/engine/core/ into it again.
When you can see the bug, turn it into a scratch spec, so you can see your fix work and keep the test: Testing the Engine has the pattern, and stage 3 of the learning path does it with a real bug.
Ask the reporter for the browser, whether the game was served or opened from the file (v2 behaves differently opened from a file: see What works opened from a file), and their js/options.js settings. Many reports turn on a setting: Storage, Screenshots, ExperimentalFeatures, MultiLanguage.
The browser console
window.monogatari is the engine itself, so the console of a running game (F12, then Console) can read and call everything:
| Type | To see |
|---|---|
monogatari.state() |
the label, the step and what is on screen (characters, images, scene, music…) |
monogatari.history() |
what each action recorded for rollback |
monogatari.storage() |
the game’s variables |
monogatari.label() |
the current label’s statements; monogatari.label()[monogatari.state('step')] is the current one |
monogatari.global('_engine_block') |
true while a statement chain runs; also global('block'), global('distraction_free'), global('playing'), global('finished_typing') |
monogatari.actions().map((action) => action.id) |
the actions in matching order |
monogatari.prepareAction('show scen beach', { cycle: 'Application' }).constructor.id |
which action takes a statement ("Dialog" here) |
monogatari.settings(), monogatari.preferences() |
the game’s settings and the player’s preferences |
monogatari.version |
the engine’s version, "2.9.0" |
Every part of the engine calls its methods on this same object (engine.run(), engine.next()…), so you can wrap one from the console to watch it:
const original = monogatari.run;
monogatari.run = function(statement, ...rest) {
console.log('run:', statement);
return original.call(this, statement, ...rest);
};From then on, every statement the engine runs is logged, including the ones next() runs after a click. Reload the page to undo it.
The starter game prints a few warnings at every boot that aren’t bugs: “Persistent Storage permission has been denied” when the browser doesn’t grant it, and, on a first run, “There was no settings saved…” with a KeyNotFoundError for Settings.
Debug levels
monogatari.debug is Artemis’s Debug class, a console wrapper with levels. js/main.js in the starter game sets monogatari.debug.level(5).
| Level | Name | What the engine prints |
|---|---|---|
| 0 | NONE |
nothing, and no error dialogs |
| 1 | ERROR |
debug.error() |
| 2 | WARNING |
and debug.warn(), such as “Screenshot capture failed” |
| 3 | INFO |
and debug.info() |
| 4 | DEBUG |
and debug.debug(), debug.log() and the collapsed groups: “Run Cycle [Dialog]”, “shouldProceed Check” with OK or FAIL and the reason for each action and component, “Proceed Prevented” |
| 5 | ALL |
the same as 4 |
Errors and warnings print with or without the debug module. Everything from INFO up (the trace, groups, tables, timers) prints only while the debug module is loaded: the DEBUG proxy in src/monogatari.ts turns those methods into no-ops without it, so a released game’s console stays quiet at any level. With the module loaded and no level set by the game, the level starts at 1.
At level 4 and above, a click that doesn’t move the game tells you why in the console: the shouldProceed Check group lists each action and component with OK or FAIL, and a FAIL Dialog line followed by Reason: Error: TypeWriter effect has not finished. names the one that refused.
Error dialogs and their ids
The engine reports mistakes in a game with FancyError.show(id, context) (src/lib/FancyError.ts). The dialog’s text lives in the debug module, debug/index.js, which registers a template for each id (FancyError.register('action:jump:label_not_found', { title, message, props })). A dialog appears only when the debug module is loaded (it sets window.MonogatariDebug) and the debug level is above 0, so released games, which drop engine/debug/debug.js, never show them.
The dialog’s data-error attribute holds a random id, not the template’s. To find the code behind a dialog, search for its title in debug/index.js, then for the id in src/:
grep -n 'does not exist' debug/index.js # finds register('action:jump:label_not_found', …
grep -rn "action:jump:label_not_found" src # finds src/actions/Jump.tsThe debug module also listens for the browser’s error events. An error in one of the game’s files while the page loads, such as a missing comma in js/script.js, opens “There is a mistake in js/script.js” with the file, the line and the browser’s message, once the page has loaded. An error thrown later, from a timer or a listener, opens “An Unknown Error Occurred” at once. A rejected promise fires unhandledrejection instead, which the module doesn’t hear: look in the console for those.

While one dialog is open, shouldProceed() refuses to move the game (a dialog is a .modal), and further errors wait in a queue: closing one shows the next. The dialog’s help section links the v2 Help page, Discord and GitHub’s issues (HELP_LINKS in src/lib/FancyError.ts).
Diagnosing Errors lists every dialog for game developers; Errors and the Debug Module explains how they work in code.
Stop at a breakpoint in the TypeScript
dist/engine/core/monogatari.js is minified, but its linked source map, monogatari.js.map, lists the 395 files it was built from (src/ and the libraries) with their contents. In the developer tools, Sources, Ctrl+P opens lifecycle.ts, monogatari.ts or any action by name, and breakpoints set there stop the game.
Good first breakpoints, at the first line inside each of these functions (line numbers on develop at 2.9.0; search for the function’s name when they’ve moved):
| File and line | Stops when |
|---|---|
src/engine/lifecycle.ts:617, the first line of run() |
any statement runs |
src/engine/lifecycle.ts:1100, the first line of proceed() |
the player clicks, presses the right arrow or space, or auto-play or skip moves the game |
src/engine/lifecycle.ts:1131, the first line of rollback() |
the player goes back |
src/engine/persistence.ts:975, the first line of loadFromSlot() |
a game is loaded |
Stage 2 of the learning path reads the call stack of a click from such a breakpoint.
Find the commit that broke it
Since December 2025 the person making a change commits the rebuilt bundles with it, so a commit’s dist/engine/core/ usually matches its src/ and you can run a spec at an old commit without building: check it out and run the spec. git bisect automates the search. This finds the commit that fixed the character move transition, between the 2.8.0 and 2.8.1 tags, by running the spec from 2.8.1 (saved outside the repository) at each step:
git show v2.8.1:cypress/e2e/actions/show_character.spec.js > /tmp/move.spec.js
cat > /tmp/bisect-move.sh <<'EOF'
#!/bin/sh
cp /tmp/move.spec.js cypress/e2e/actions/show_character.spec.js
bunx cypress run --browser chromium --spec cypress/e2e/actions/show_character.spec.js > /dev/null 2>&1
status=$?
git checkout -q -- cypress/e2e/actions/show_character.spec.js
if [ $status -eq 0 ]; then exit 1; else exit 0; fi
EOF
chmod +x /tmp/bisect-move.sh
git bisect start --term-old=broken --term-new=fixed
git bisect fixed v2.8.1
git bisect broken v2.8.0
git bisect run /tmp/bisect-move.sh
git bisect resetIt ends with fea01a2e… is the first 'fixed' commit. To find a commit that broke something, use the usual terms (git bisect start <bad> <good>) and a script that exits with 0 when the spec passes.
Two cautions. Before commit 5b16c02e (December 2025), a GitHub workflow committed the rebuilt bundles separately as “Update engine core”, so an older source commit may carry bundles from before it; rebuild at each step there (bun install && bun build.ts), as far back as bbc0c637, the commit that added build.ts. And the specs need the test asset server, which changed host in commit 4b5fff30.
Layout and other things you have to see
Some bugs are only visible: a sprite in the wrong place, a menu covering the text. Capture the page at the size the reporter uses, with the developer tools’ device toolbar or a headless browser, and measure elements with getBoundingClientRect() in the console. The 2.8.1 fix for character positions added a spec that does exactly that (“Anchors the sprite to each position” in cypress/e2e/actions/show_character.spec.js): measure the sprite and its container, and compare edges.
The desktop hosts
The starter game’s Electron host prints the page’s console to the terminal when started with --enable-logging, which bun run start in dist/ does. On a machine without a display, run it under Xvfb (xvfb-run -a bun run start). The Starter Game and Desktop Hosts has the setup and what’s known not to work.