ExplanationEdit on GitHub

The dev loop#

What eezo dev does on every save, what the browser does in response, and why a failed compile is not an outage.

The loop#

eezo dev is one sbt command of the plugin, eezoDev, the dev console. It watches the source tree itself, and on every change does three things, in this order:

  1. Compile. The task asks for the project's full classpath, and asking for it compiles the project first. If the compile fails, the task fails here, and nothing after it runs.
  2. Kill the previous application, politely, then forcibly after ten seconds if it ignores the signal. The kill completes before the next step starts, so the new process never races the old one for the port.
  3. Fork a fresh JVM on the new classpath, running Main dev, with its output in the same console as the compile.

Step one is why a typo isn't an outage. The previous process is still serving when the compile fails, and it keeps serving until a compile succeeds. The dev loop never kills a working server for an error in the editor.

The route generator runs inside step one, as a source generator, so a new file under app/ is a new row in the table on the same save. It caches on the hash of the sources it reads, and writes the generated file only when its content changed, so a save that doesn't touch a route doesn't invalidate the compile that follows.

The stylesheet is built in the same step when the project has a tailwind.css at its root: the plugin runs the Tailwind CLI as a resource generator, cached the same way on the sources it reads, so the class you just typed is styled when the page reloads, with no second process. A Tailwind error fails the task the way a compile error does, and the previous application keeps serving. Style with Tailwind is the setup.

The watch is the console's own rather than sbt's ~, over the source and resource directories and the stylesheet, with a hundred milliseconds of quiet between the last file event and the build, so an editor that writes several files on one save, a rename across a package for one, compiles once. A save that lands while a compile is running is remembered and compiles once that one is done.

The console#

eezo dev takes the whole terminal. The top row names the project and, at its right end, the address the application serves on, or that it is starting, stopped, or exited. The bottom right is the build: a spinner while a compile runs, labelled with the file that triggered it, then ✓ built in 0.4s, or ✗ 2 errors. Between them, five panes, one key each:

  • 1 errors: the compiler's diagnostics as values, one block each: the file, line and column, then the compiler's own rendering with the excerpt and the caret. Warnings after errors. The pane opens by itself when a build fails; the tab shows the count.
  • 2 routes: the route table the running application mounted, as an aligned table, each route with where it came from: handwritten, derived, or eezo for the ones the framework mounts under /eezo, the live socket and its script. Under it, the warnings boot would print: a derived route a handwritten one replaced, a route that shadows another, a form page whose submit target is not mounted.
  • 3 schema: the drift the dev server found at boot, each change in the colour of its class, and the schema commands as keys: s applies the drift to the dev database (it asks first when a change loses data or can fail, and adds --force only then), f writes it as a named migration and applies that, m lists the pending migrations and applies them on Enter, S diffs the model against the database again. Each runs the same command eezo db runs, as a child on the build's classpath, and the console restarts the application when one succeeds. The pane keeps one line per command: a spinner while it runs, then its answer in the colour of its exit code; everything the command printed is in the log. An application with no database layer has no schema pane: one with the layer reports its drift before it serves, so serving without a report is how the console tells them apart.
  • 4 config: the variables application.conf names, one row each, with the path it feeds, whether it is required, defaulted or optional, whether it is redacted, and whether it is set. A row never shows a value. The pane comes with an application whose build names a Config class with eezoConfigClass, and it opens by itself when boot refuses: the rows boot refused are red, and a refusal that only the file can fix, a variable under EEZO_, a Redacted stated as a literal, a file that is missing or does not parse, a value no variable feeds, shows in red with boot's own line for it. The tab shows the number of offenders, or a green tick when there are none. e asks for each value a variable can fix, one path at a time: it names the path, the variable to set, the other one when the file names two, and how many more follow, and it masks what you type for a Redacted. A malformed value is asked of the variables that fed it, which boot's report names: of two fed in turn, port = ${?SHOP_PORT} and then port = ${?PORT}, only the later one set, since it wins; of a concatenation, ${?PREFIX}${?PORT}, every set part in turn, since any of them can hold the bad text. Enter takes the value and asks the next one; Enter on the last restarts the application with them; Esc stops asking and keeps what Enter took. A value typed here reaches every application the console starts after it, its row reads set (session) in cyan, and it lasts for this session of the console only: nothing writes it to a file, the shell, or a schema command. The values a variable cannot fix stay the file's, and e does not ask for them, nor for a variable left unset that has a default.
  • 5 log: everything the application prints or logs, a stack trace included, and the output of every schema command, following its tail until you scroll up. Arrows, j and k, PgUp and PgDn, g and G scroll; so does the mouse wheel, in terminals that turn it into arrows on the alternate screen, which VS Code, iTerm2, GNOME Terminal and Windows Terminal do.

The bottom row is the keys that apply right now, and where a question is asked: a migration's name, whether to force, or a value the config pane asks for. r rebuilds and restarts without a save, c clears the log, ? lists every key, q or Ctrl-C stops the loop and the application with it.

The layout follows the terminal. Under sixty columns the tabs shorten and the footer keeps only the keys that matter most; under twelve rows the header and the tabs share one row and the footer goes; under six rows there is only the status row. Colour is sixteen colours and off under NO_COLOR; the box drawing and the glyphs fall back to ASCII when the terminal is not UTF-8.

What is kept out: sbt's own narration, its loading, its progress bars, its timings, and the java.util.logging records Jetty and HikariCP write at INFO on every boot, which say the same thing every time. Their warnings still come through.

The screen is for a person at a keyboard. An agent writing the application, a log file or a pipe cannot read cursor movements or press s, so eezo dev --no-tui runs the same loop as lines: compiling (Index.scala changed), the diagnostics as the compiler printed them, built in 0.4s, started Main, the application's output, a line per schema command's result. The watch, the debounce, the restart and the quiet Jetty and HikariCP records are the same; only the drawing is gone. eezo dev --json is the same again as one JSON object per line, with the diagnostics as values and a build number that ties a compiling to its built or failed, so a tool waits for an answer rather than matching text; the plugin reference lists the events. The scaffold writes an AGENTS.md that says so to a coding agent before it starts. Ctrl-C, or killing sbt, stops the loop and the application with it.

Without a terminal and without that flag, in a pipe or in CI, the console has nobody to stop it, so it runs only as sbt "eezoDev --once": the plain lines, cut short once the application serves or exits, and the command fails when it did not serve, which is what a build check wants. A watch nobody asked for as lines is refused rather than left running after its reader is gone.

The console learns what the application mounted, what drifted and what its Config read from four lines the application prints at boot: serving on <url>, and, when the plugin asks for them with EEZO_DEV_MARKERS, eezo dev: routes <json> and eezo dev: drift <json>, the same values eezo routes --json and eezo db status --json print, and eezo dev: config <json>, the variables eezo config lists with whether each is set and every offender of the read, on one line each. The config line comes from dev alone, also when boot refuses, and never from run, so a deployment prints no variable name. sbt eezoDev from the sbt shell is the same console; sbt "run dev" by hand is the application alone, without them.

What the browser does#

Every page the dev server serves gets a small script appended to its <body>. The script keeps a WebSocket open to /eezo/reload. The restart that follows a save closes that socket; the script notices, polls until the new server answers, and reloads the page. Whole page, no state kept.

The script and the endpoint exist only when dev is on. In production the endpoint is an ordinary 404 and no page carries the script. The injection is structural, into the first <body> element of a Body.Html, so a response that isn't a page, or one you built from raw bytes, is left alone.

A live page is reloaded the same way. Its state was in the process that died, so the client reloads into a fresh page with a fresh init.

The drift check#

Before the dev server serves, it diffs the database against the model. Additive drift is a banner and the application serves. Destructive or risky drift is a page in place of the application, with the two actions on it, re-checked on every GET so resolving it from the page or from another terminal shows up on the next refresh. The console shows the same drift in its schema pane, switches to it when the drift blocks, and offers the same actions as keys; resolved from there, the application is restarted at once. A database that can't be reached is a warning, in the schema pane too, and everything that doesn't need it serves. Schema and migrations has the detail.

One secret per sbt session#

The session cookie is signed with the application secret, and every restart is a new JVM. A child left to generate its own secret would sign you out on every edit. So the plugin generates one secret when the loop first starts, keeps it for the life of the sbt session, and hands it to every child as EEZO_SECRET, unless sbt's environment already has one, which the child inherits. A reload of the build makes a fresh secret and signs you out once.

What eezo dev doesn't do#

  • Hot swap. No class reloading, no agent. Every change is a full restart of the application JVM, which is what makes the result trustworthy: the running code is always the code on disk.
  • State preservation. In-memory stores, live page state and anything else the process held are gone on restart. A model with a Table keeps its rows, because they're in Postgres.
  • A database-only application. dev is the http layer's command. On DbApp alone it's unknown, and a rerun-on-save loop for a job is sbt's own ~run.

Daniel: the save-to-reload timings you measured when choosing sbt's resident watch over sbt-revolver, if you want numbers on this page.

Where to go next#

What the forked JVM starts, and how it comes down, is the server.