Skip to content

stability: move events log from $SNAP_COMMON to $SNAP_DATA#733

Merged
cyberb merged 6 commits into
masterfrom
stability-events-data-dir
May 22, 2026
Merged

stability: move events log from $SNAP_COMMON to $SNAP_DATA#733
cyberb merged 6 commits into
masterfrom
stability-events-data-dir

Conversation

@cyberb
Copy link
Copy Markdown
Member

@cyberb cyberb commented May 21, 2026

Summary

Per CLAUDE.md convention: app state belongs in $SNAP_DATA, never $SNAP_COMMON.

  • $SNAP_DATA is snapshotted by snapd on each refresh — copied forward on success, rolled back on failed install.
  • $SNAP_COMMON is shared across revisions and is not part of that snapshotting, so on rollback an older binary can be left looking at newer-format data it doesn't understand.

The stability events log is forward-tolerant today (additive JSONL fields), but the convention is one schema change away from breaking rollbacks. Putting it in $SNAP_DATA is the safe place.

Changes

  • backend/cmd/stability/main.go — point at $SNAP_DATA/stability-events.jsonl.
  • backend/ioc/common.go — backend REST reader points at the same new path.
  • backend/stability/MigrateEventLog — one-shot move at daemon startup: if the file exists at the old $SNAP_COMMON path and not at the new $SNAP_DATA path, rename it across. Devices already on rev 2837 keep their existing history through the upgrade.

Test plan

  • go test ./stability/ — 3 new migration cases (move when only old exists, skip when new exists, no-op when neither exists).
  • CI green.
  • Refresh borisarm64 from this build, verify event file appears at /var/snap/platform/current/stability-events.jsonl and the previous swapoff_file event is preserved.

cyberb added 6 commits May 21, 2026 22:34
CLAUDE.md is clear: app state belongs in $SNAP_DATA, never $SNAP_COMMON.
$SNAP_DATA is snapshotted on refresh (rolls back transactionally on a
failed install), $SNAP_COMMON is shared across revisions and does not
roll back — leaving an older binary with newer-format data on
rollback. Today our events.jsonl is forward-tolerant, but the
convention is there for a reason and one schema change away from
breaking rollbacks.

Move events to $SNAP_DATA/stability-events.jsonl, plus a one-shot
MigrateEventLog at daemon startup that renames any existing file from
the old common path (so devices already on rev 2837 don't lose
history on refresh).
Hardcoded fallbacks ('/var/snap/platform/current' and '...common')
hid a real configuration error: if the daemon were ever started outside
the snap, it would silently write to /var/snap/platform/* on the host
rather than its sandboxed dirs. Fail loudly instead — these env vars
are guaranteed by snapd for every snap service.

Same treatment in ioc/common.go where the backend reads the events
file.
Replace env-var lookup with the conventions already used in the
codebase:
- ioc/common.go: EventLog singleton now depends on *config.SystemConfig
  and uses systemConfig.DataDir(), matching auth/authelia/totp wiring
  (ioc/common.go:337, 358, 365). SystemConfig.Load() log.Fatalln's on
  missing platform.cfg, so misconfiguration still fails loudly.
- cmd/stability/main.go: use hook.DataDir / hook.CommonDir constants
  (same pattern as hook/install.go and cmd/install).
The watcher has no shutdown cleanup — no open file handles to flush,
no in-flight state. Process termination via SIGTERM from systemd is
fine. Drop the signal.NotifyContext setup in main and the
context.Context parameter from Watcher.Run. The for/select collapses
to 'for range t.C'.
@cyberb cyberb merged commit 7fdee02 into master May 22, 2026
1 check passed
@cyberb cyberb deleted the stability-events-data-dir branch May 22, 2026 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant