Repository navigation
Description
Request: none
Problem
daemon.log does not say what the daemon was asked to do or why background
work failed. A request over the socket (CLI, MCP) leaves no line; only HTTP
requests do. When a background step fails (a boot, a reclaim, a quarantine
retry, a cleanup run, a lease expiry) the error is dropped: the device is
retried or destroyed and the reason is recorded nowhere. Device commands
(simctl, adb, sdkmanager) are never logged. A failing event subscriber
is written to the log as raw text, not as a JSON line.
simlock daemon logs prints the log once and exits, so none of this can be
watched while it happens.
Who it is for
An operator or agent working out why a lease was slow, queued, or refused,
or why a device was destroyed, on a machine they can run simlock on.
Outcome
- Every operation that changes state leaves one line when it finishes: the
operation, who asked, how long it took, and the result or error code. This
holds for every frontend: socket, MCP, HTTP, and a gateway's dispatch. - Read-only operations leave that line only at
log.level: debug. A failed
one leaves it at the default level. - Every background failure that is handled by retrying, deferring, or
destroying a device leaves one line with the device, the lease if there is
one, the step that failed, and the error text. The exception is a failure
whose error text already travels on an event (device.purge-failed,
device.recovery-failed,device.quarantine-stranded): it leaves no
line. - At
log.level: debug, every device command leaves one line: the command,
its arguments, its exit code, and how long it took. Never its environment
or its input. - Every line in
daemon.logwritten by a running daemon is a JSON line. simlock daemon logs --followprints the current log, then each new line
as it is written, until interrupted. It keeps following across a rotation,
and it waits when no daemon is running.- A business fact is not repeated in
daemon.log. Facts are in the event
file; this log says what was asked and what went wrong.
Non-goals
- Reading another machine's daemon log, over HTTP or through a gateway.
- Filtering by level or module in
daemon logs. - Logging from the CLI or the MCP server process. They are clients.
- Recording what a
device.execcommand printed.
Completion conditions
- Lease and release a device over the socket:
daemon.logholds one line
for each, naming the requester and the duration. - Ask for a lease with an unknown model: the line carries the error code.
- At the default level,
simlock statusadds no line. Atdebugit does. - Make a device's boot fail:
daemon.logholds a line naming the device,
the step, and the tool's error text. - At
debug, a lease that boots a device leaves one line per device
command, each with an exit code. - Make an event subscriber throw: the log gains one JSON line and no raw
text. - Run
simlock daemon logs --follow, then lease a device: the request line
appears without rerunning the command. Withlog.rotateBytesset small,
lines written after a rotation still appear. - CLI.md describes what the log records and the
--followflag.
Open questions
None.
Decisions
- ADR 0006 — Events and the daemon log are two records: the log records what was asked and what went wrong, never a fact, and no log line becomes an event.
Technical spec
Modules touched
src/contract/operations.ts:OperationDefinitiongainseffect: "read" | "write" | ((input) => "read" | "write"), shaped likerole.read:catalog.get,status.get,lease.list,list.get,config.get,driver.passthrough,events.replay,events.subscribe,events.unsubscribe,token.list,worker.list.write:lease.request,lease.cancel,lease.renew,lease.release,lease.release-all,device.exec,nuke.run,daemon.stop,token.create,token.revoke,worker.drain,worker.undrain,worker.remove.- By input:
doctor.runiswritewhenfixis true;cleanup.runisreadwhendryRunis true.
src/daemon/dispatch.ts:DispatchPipelinegainsobserve?: { clock, logger, codeOf(error): string }.runDispatchwrites one line, messageoperation, when the call settles. This is the only place the line is built.- Fields:
operation,principal,role,durationMs. On failure alsocodeandmessage.leaseIdandrequesterIdwhen the validated input has a string under that key. Nothing else from the input and nothing from the output. - Level: success of a
writeisinfo; success of areadisdebug; a failure isinfo; a failure with codeINTERNALiserror. - A call refused before its handler (
UNKNOWN_REQUEST,BAD_REQUEST,FORBIDDEN) is a failure and gets the line. - The module stays free of
src/coreimports;codeOfis injected.
- Fields:
src/daemon/dispatcher.ts,src/gateway/dispatcher.ts: passobservewithlogger.child("dispatch").GatewayDispatchergainsclockanderrorCodeoptions.main.tshandsclassifyErrorto both.src/daemon/server.ts: delete theHandled request errordebug line; the operation line replaces it.Unhandled request error, here and insrc/http/app.ts, stays: it carries the stack.daemon.stopandhelloare answered by the server, not dispatched, and keep their existing lines.src/http/app.ts: therequestline stays. It is the transport's own record and covers requests that never reach a dispatcher.- Background failures:
LeaseEnginepassesoptions.loggeron toDeviceProvisioner,LeaseAcquisitionCoordinator,QuarantineCoordinator,WarmPoolCoordinatorandLeaseExpiryScheduler;main.tspasses it toCleanupReaper. Each takes it as optional, scopes it withchild("<module>"), and defaults toNoopLogger. One line per site, withdeviceId,step,error(the caught error's message), andleaseIdorrequesterIdwhere the site knows one:device-provisioner.ts: a new device failed to become ready (warn); destroying it afterwards failed (warn).lease-acquisition-coordinator.ts: shutting down an eviction target failed; deleting an eviction target failed; booting a shut-down device for a waiter failed; destroying it afterwards failed (allwarn).quarantine-coordinator.ts: a reclaim retry failed; a delete retry failed (warn, withattempts); the retry itself threw (error).warm-pool-coordinator.ts: shutting down a reclaimed device failed; making a reclaimed device ready failed (warn).reaper.ts: a scheduled cleanup run threw (error).lease-expiry-scheduler.ts: expiring a lease threw (error, withleaseId).- Not logged: a failure whose error text already travels on an event (
device.purge-failed,device.recovery-failed,device.quarantine-stranded), and the observer-isolation catches inwait-queue.ts.
src/ports/logging-process-runner.ts(new, exported fromsrc/ports/index.ts):LoggingProcessRunnerwraps aProcessRunner.run: onedebugline when it settles, withcommand,args,code,durationMs, orerrorwhen it threw. The error is rethrown unchanged.spawnandspawnStreaming: the same line, once, when the process exits.- Never
env,input, stdout or stderr.
src/daemon/main.ts:- Wrap the one
ProcessRunnerinLoggingProcessRunnerwithlogger.child("process")only whenconfig.log.levelisdebug. - Give
EventBusa logger that writesEvent handler failedthroughlogger.child("bus")withevent,seq,messageandstack. Theconsole.errorfallback in the fatal start handler stays; it runs only when the log cannot be written.
- Wrap the one
src/cli/index.ts,daemon logs --follow:- Prints the last 100 lines as today, then each new complete line until
SIGINTorSIGTERM, then exits 0 with its timer cancelled. - Follows by polling through the
FilesystemandClockports, every 250 ms. Nofs.watch. - A rotation is detected from the rotated file changing, not from the current file shrinking: a fresh file can outgrow the old offset within one poll. After a rotation it prints the unread rest of
daemon.log.1, then the new file from its start. - A missing log file means wait.
--followwith--jsonis a usage error, exit 2.- If the follow needs a read from a byte offset or a file identity, add it to the
Filesystemport and toMemoryFilesystem.
- Prints the last 100 lines as today, then each new complete line until
- Docs:
docs/CLI.md:simlock daemon logs [--follow], and the paragraph on whatdaemon.logrecords.docs/CONFIGURATION.md:log.levelsays whatdebugadds (read operations, device commands).docs/internal/ARCHITECTURE.md: the operational-logging section.CHANGELOG.md, Unreleased: one entry.docs/internal/adr/0006-events-and-log-are-two-records.mdand the ADR index: status becomes Accepted in whichever PR closes the second of Keep business events on disk so the history survives a restart #168 and Daemon log records every request and background failure, and can be followed live #169.
Contract and event changes
OperationDefinition.effectis new in the contract module. It never goes on the wire.- No operation, schema, error code, config key, or event changes. Both
EVENTS.mdfiles are untouched.
Rules in play
architecture.md9: logging through theLoggerport, the follow throughFilesystemandClock; noconsole, nofs.architecture.md10: the operation line is built inrunDispatchand nowhere else. No transport and no dispatcher writes a second one.architecture.md12: every exit from the follow leaves no timer and no signal handler behind.architecture.md13: theNodeFileLogSinkcomment insrc/ports/logger.tssays volume is low because nothing logs per request. That stops being true; fix it.architecture.md1 and 2: core log lines name a device id, a step and an error text. They interpret nothing platform-specific.src/gateway/boundary.test.ts:dispatch.tsmust not importsrc/core.safety.md, wire input is a claim:principalandrequesterIdare logged as claimed. No credential, token secret, environment or stdin is ever logged.events.md: no fact becomes a log line. A site whose error already rides on an event is left alone.documentation.md3: no log message names a path in this repo.testing.md: every title below is a claim; break the code and watch each fail.
Tests
Unit, src/contract/operations.test.ts:
- Every operation declares an effect.
doctor.runis a write only withfix, andcleanup.runis a read only withdryRun.
Unit, src/daemon/dispatch.test.ts (new):
- A write that succeeds logs one info line with the operation, principal, role and duration.
- A read that succeeds logs at debug and nothing at info.
- A read that fails logs at info with its error code.
- An error classified
INTERNALlogs at error. - A request refused for its role logs one line with
FORBIDDEN. - The line carries
leaseIdandrequesterIdfrom the validated input and no other input field. - The gateway dispatcher logs the same line for the same operation.
Unit, one per site, in the module's own test file:
- A new device that fails to become ready logs the driver's error with the device id.
- A failed destroy after a failed boot logs the device id and the error.
- A failed eviction shutdown logs the device id and the error, and the waiter is deferred as before.
- A failed eviction delete logs the device id and the error.
- A shut-down device that fails to boot for a waiter logs the driver's error.
- A failed quarantine reclaim retry logs the error and the attempt number.
- A failed quarantine delete retry logs the error and the attempt number.
- A reclaimed device that fails to shut down logs the error.
- A reclaimed device that fails to become ready logs the error.
- A cleanup run that throws logs at error.
- A lease expiry that throws logs at error with the lease id.
- A purge failure logs nothing, because
device.purge-failedcarries the error.
Unit, src/ports/logging-process-runner.test.ts:
runlogs the command, arguments, exit code and duration, and never the environment or the input.- A
runthat throws logs the error and rethrows it. spawnlogs once, when the process exits.spawnStreaminglogs once, when the process exits, and no chunk of its output.
Unit, src/daemon/main.test.ts:
- At
log.level: infono process line is written. - A throwing event subscriber writes one JSON line through the logger and nothing through
console.error.
Unit, src/cli/index.test.ts:
daemon logs --followprints the existing tail, then a line appended later.- It prints lines written after a rotation, when the new file is already larger than the old offset at the next poll.
- It waits while the log file is missing and prints lines once it appears.
daemon logs --follow --jsonfails withUSAGE, exit 2.- An interrupt ends the follow with exit 0 and leaves no timer armed.
E2e, fast lane, e2e/daemon-log.test.ts:
- A lease and its release over the socket each leave one
operationline naming the requester. - A lease request for an unknown model leaves an
operationline with its error code. - At the default level
simlock statusleaves nooperationline; atdebugit leaves one. - A scripted boot failure leaves a line naming the device and the driver's error text.
- At
debug, adevice.execcommand leaves oneprocessline with its exit code and no line holding its output. simlock daemon logs --followprints theoperationline of a lease made after it started.
Written by an agent.
Activity
V3RON commentedon Oct 1, 2026
Spec updated: Decisions and Technical spec added.
Written by an agent.
docs(adr): 0006 — events and the daemon log are two records; docs fol…
V3RON commentedon Oct 1, 2026
Spec updated: Outcome now excepts failures whose error already rides on an event.
Written by an agent.
feat(bus,cli,config): keep business events on disk so the history sur…