Repository navigation
feat(bus,cli,config): keep business events on disk so the history survives a restart - #184
Merged
Merged
Conversation
…vives a restart (#168) Every event the daemon emits is also written to events.jsonl in the data directory, capped by eventLog.rotateBytes with one rotated generation. events.replay with sinceTs reads the file in both dispatchers; the CLI reads it directly for events --since when no daemon answers, and events --follow subscribes before replaying so the join loses and repeats nothing. daemon.log no longer copies component.installed and device.slimmed (ADR 0006).
…narrow the --since doc
V3RON
added a commit
that referenced
this pull request
Oct 1, 2026
…lure; daemon logs --follow (#187) Closes #169 `daemon.log` now records what the daemon was asked to do and what went wrong (ADR 0006). - Every dispatched call leaves one `operation` line, built only in `runDispatch`, for socket, MCP, HTTP and gateway dispatch. Its level comes from the new contract `effect`: write at info, read at debug, failure at info, `INTERNAL` at error. - Core modules log the background failures they handle, with device, step, error, and lease or requester where known. - At `debug`, `LoggingProcessRunner` logs each device command with its exit code. It never logs env, input or output. - A failing event subscriber is one JSON line through the logger. - `simlock daemon logs --follow` polls through `Filesystem`/`Clock`, detects rotation from `daemon.log.1` changing identity, and waits for a missing file. Deviations from the spec: - `doctor --purge-orphans` counts as a write, because it destroys devices. - A call refused before input validation logs its code but no message, because that message quotes raw wire input. ## Completion conditions - [x] Lease and release over the socket each leave one line with requester and duration. `e2e/daemon-log.test.ts` - [x] Unknown model: the line carries `UNKNOWN_MODEL`. e2e - [x] `status` adds no line at the default level and one at `debug`. e2e - [x] Boot failure: a line with the device, `step: boot` and the driver's error text. e2e and unit - [x] At `debug`, each device command leaves a line with its exit code. e2e (`device.exec`) and unit - [x] A throwing subscriber gives one JSON line and nothing on `console.error`. `main.test.ts` through `startDaemon` - [x] `--follow` prints a later lease's line, and keeps printing after rotation with a small `log.rotateBytes`. e2e and unit - [x] CLI.md describes the log and `--follow`. - [x] ADR 0006 and the ADR index say _Accepted_: #168 landed first (#184), so this PR closes the second. - [x] `pnpm check` green. Each new test was seen failing with its code removed. ## Review Spec review: 16 findings over two rounds, 6 fixed. Code review: 10 findings over two rounds, 9 fixed. Rejected: - `doctor.run` with `purgeOrphans` is a write — it destroys devices, and the Outcome says every state change leaves a line. Spec needs: `purgeOrphans` in the effect list. - Failure message missing before input validation — safety rule 10: the message quotes raw wire input. Spec needs: `message` only after validation. - `log.rotateBytes` row added to CONFIGURATION.md — neither `log.*` key was documented, and the log paragraph names this one. - `checkAccess`/`authorizeContext` split out of `runDispatch` — required by the pre-commit complexity gate. Behaviour unchanged. - Two `fallow-ignore` comment edits — the pre-commit audit flags them in files this diff touches. - Tests beyond the spec's list — they cover paths the code review found untested (testing rule 3). - Worker dispatcher gets `classifyError` in `server.ts`, not `main.ts` — `server.ts` builds that dispatcher and already imports it. Same effect. - A `cleanup.run` that joins a failing scheduled run gets both lines — the background run failed and the request is a separate record. *Written by an agent.*
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #168
Every business event is now also written to
events.jsonlin the data directory, so the history survives a restart or crash.events.replaywithsinceTsreads the file in both dispatchers through oneEventHistory.simlock events --sincereads the file directly when no daemon answers.--followsubscribes before it replays, so where history meets the live stream nothing is lost or printed twice. The file rotates on the neweventLog.rotateBytes(5 MiB, one generation kept) and is separate fromdaemon.log, which no longer copiescomponent.installedordevice.slimmed. If the file can't be opened or written, the daemon logs one line and replays from memory.ADR 0006 stays Accepted — not yet implemented until #169 lands.
Completion conditions
lease.grantedwith its timestamp is still in the file — e2eevent-history, "prints a lease granted before a daemon restart…"seq,timestamp,event,payload,module— e2e "writes every event file line as JSON…".1≤ 2× limit, newest present — e2e "keeps events.jsonl plus events.jsonl.1 under twice…"daemon.logrotation removes nothing from the event file — e2e "keeps every emitted event … after daemon.log rotates"events --since 1hprints the earlier grant — same first e2e; HTTP: e2ehttp-api, "GET /v1/events?since=1h returns an event from before a daemon restart"--since 1hprints history, no daemon started — e2e "prints the history with the daemon stopped…"--since 1h --follow: history once, then live — unitcli"events --since --follow prints the history once and then the live events"pnpm checkgreen. Every new test was checked to fail when the code it covers is broken.Review
Spec review: 9 findings, 2 fixed. Code review: 10 findings, 5 fixed.
Rejected:
readEventFileskips JSON lines that are not envelopes, beyond "not JSON" — a line with no numericseq/timestampcannot be filtered or deduplicated.runDaemonmoved ontodaemonRefusal, beyond the module list — the spec says--sinceuses the same testdaemon statususes; one helper is how (architecture rule 10).writeModulehoisted to file scope inmain.test.ts— test plumbing, so the new event-file tests can reuse it.NodeFileLogSinkdoc comment changed, though the spec says the sink is unchanged — its claims about volume and "built once" became false (architecture rule 13). No code changed.eventKeyexported beyond the three names the spec lists — the code review asked for one definition of event identity shared by the bus and the CLI (architecture rule 10).bus/index.tshas a memory-only comment the diff should fix — none exists; the only ring comment is about the ring's count bound, which still holds.runDaemonrefactor are outside the spec's lists — without that test the rethrow can be deleted with a green suite (testing rule 3).writeSync; the only cheap fix is a separator line, which breaks "every line parses as JSON".--sinceprints the file on atransport-kind failure — that is the spec's chosen test, the onedaemon statususes for "stopped".sinceTspredicate exists for both the ring and the file — two stores each filter their own entries; the choice of store is made once, inEventHistory.replay.--followjoin lives in the CLI (architecture rule 8) — the spec puts the join inrunEvents; the daemon contract is unchanged.capacity-cleanup-nuke) under load — passes alone on this commit and onmain.Written by an agent.