Skip to content

fix(start-wrt): keep activity logging best-effort when the database cannot open - #4520

Merged
dr-bonez merged 4 commits into
masterfrom
wrt/factory-reset-reboot
Nov 6, 2026
Merged

dr-bonez merged 4 commits into
masterfrom
wrt/factory-reset-reboot

Conversation

@Dominion5254

Copy link
Copy Markdown
Member

Summary

activity::log is documented as best-effort, but the shared SQLite connection panicked when it could not be opened. A factory reset is the case that exposes it: firstboot erases /var/lib/startwrt, so when the reset is the daemon's first activity entry since it started, the handler panics after the wipe and never reboots. The router keeps running half-wiped, with SSH down for lack of host keys, until someone restarts it.

The connection is now opened on first use behind db(). An open failure is an ordinary Filesystem error that the next call retries: log drops it, as its contract says, and the activity RPCs return it. The reset proceeds to its reboot.

Changelog fragment: patch / fixed, for the 1.3.1 changelog.

Verification

  • make start-wrt-test: 800 + 18 pass, including the new a_failed_open_is_retried and open_db_creates_the_directory_and_schema.
  • rustfmt on the pinned nightly, prettier, and changelog.mjs check-version are clean.
  • K1 bench, daemon holding no activity DB descriptor: on the image's original binary, startwrt-cli system factory-reset panicked at activity.rs:32 (unable to open database file), the CLI got a transport error, and 30 s later the router was still up, half-wiped, with its SSH host keys deleted. On this branch's binary the same precondition produced reboot: Restarting system about 40 s after the call and a clean boot on defaults. The entry written after the wipe does not survive: firstboot leaves the overlay pending and mount_root re-wipes it at boot.
  • Retry: replacing /var/lib/startwrt with a regular file made activity.list return Filesystem Error: failed to open activity database; removing the file made the next activity.list succeed without a daemon restart.
  • activity.list with the directory absent recreates it and returns an empty list; activity.delete of an unknown id returns Not Found; a UI login is logged and listed by both the UI RPC and the CLI; the bench smoke checks pass after the reset and the config restore.

Not exercised: the flash wizard's log_to path (same open_db; flashing is out of bench reach) and activity.clear, which uses the same db() helper as delete.

…annot open

`activity::log` is documented as best-effort, but the shared connection
panicked on open. A factory reset is the case that exposes it: `firstboot`
erases the database's directory, so when the reset is the daemon's first log
entry since starting, the handler panics after the wipe and never reboots. The
router keeps running half-wiped, with SSH down for lack of host keys, until
someone restarts it.

An open failure is now an ordinary error that the next call retries: `log`
drops it, as its contract says, and the activity RPCs return it. The reset
proceeds to its reboot.

@helix-white helix-white left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved on code at b063925bbaf26cea26e94b4172b7c863cc8e2c1f; the merge-tree check against current master is clean. No correctness regressions found.

CI is not green. Changelog fragments & versions fails in the unchanged release-tooling test at scripts/tests/release-notes-test.mjs:1499: it expects the CLI capability check inside the installation step, but master commit 4a33d49eb moved installation to a composite action and put the capability check in the following step. This is unrelated to this diff, but needs resolution before merge. The riscv64 binary, automated tests, and generated-artifacts jobs remain pending. Prettier, formatting/lockfiles, dependency licenses, and conflict-marker checks passed; image build and deployment were skipped.

The fix removes the activity database's panicking lazy initializer. A failed directory creation, SQLite open, or schema initialization now leaves the cached connection unset: logging discards the error, activity RPCs return a filesystem error, and the next call retries. Consequently, logging after firstboot erases the directory cannot prevent the factory-reset handler from scheduling its reboot. Successful connections retain their existing process lifetime and serialization; entry retention, schema, and API payloads remain unchanged, with no migration.

The shared open helper also serves the setup wizard's alternate-path logger, removing duplicated directory/schema initialization. This is independent of the hardware-button reset in #4519.

Implementation diff: +49 / −25 lines in 1 file (excludes lockfiles, tests, docs, release notes, and changelog).

I reviewed the affected callers and recorded evidence without running builds or tests. The author reports 800 + 18 passing tests, including failed-open retry and directory/schema creation, plus a K1 bench reproduction on the original binary and successful reset/reboot on this branch's binary. Recorded checks also cover recovery without daemon restart and activity RPC/login behavior. The flash wizard path and activity clear were not exercised end to end.

One description correction: the fragment is patch-tier, but the pending release is already 1.4.0, not 1.3.1, under the existing manifest and minor fragment.

Helix-Harness: pi
Helix-Model: openai-codex/gpt-6.1-sol

@dr-bonez

dr-bonez commented Nov 3, 2026

Copy link
Copy Markdown
Member

@Dominion5254 address ci failures. might just need a rebase

@helix-white

Copy link
Copy Markdown
Member

Confirmed: both failed jobs hit the same stale assertion in scripts/tests/release-notes-test.mjs:1499. Master now fixes that assertion in 75a59d5 (#4530), so updating this branch onto current master should address that failure. That commit also changes changelog frontmatter from user-facing to release-notes; the new factory-reset fragment needs updating to that convention. The riscv64 build and generated-artifact checks have since passed. Leaving branch updates to @Dominion5254; I have not changed the PR branch.

@helix-white helix-white left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved at 6a49d096ee656956f810f038eb09a019e1a0604a. The fresh merge-tree check against current master is clean; no correctness findings.

Since my previous review, the branch merged master and changed its fragment to release-notes: true. The activity implementation and its tests are byte-for-byte unchanged, as are the factory-reset and setup callers. The merged release-tooling test now checks the dedicated CLI-capability step, addressing the cause of both earlier CI failures. Fresh CI results are still pending; this approval does not establish that they pass.

The change makes activity database initialization fallible rather than panicking after a factory reset wipes its directory. Logging drops initialization errors, allowing reboot scheduling to proceed; activity RPCs return a filesystem error. Failed initialization leaves the connection unset for the next call to retry. Successful connections keep their existing lifetime and mutex serialization. The alternate-path setup logger reuses the same directory/schema initialization helper. Storage format, API payloads, and entry retention remain unchanged; no migration is needed.

Implementation diff: +49 / −25 lines in 1 file (excludes lockfiles, tests, docs, release notes, and changelog).

Verification evidence remains the author's previously recorded 800 + 18 passing tests and K1 bench reproduction/fix, including recovery after an open failure without restarting the daemon. That evidence predates the master merge; the unchanged implementation supports its relevance, but fresh CI is awaited for the combined head. The flash-wizard path and activity clear remain untested end to end. I ran no builds or tests as reviewer.

The description still names 1.3.1; the manifest's pending release is 1.4.0.

Helix-Harness: pi
Helix-Model: openai-codex/gpt-6.1-sol

@Dominion5254
Dominion5254 force-pushed the wrt/factory-reset-reboot branch from 6a49d09 to 3c9e61c Compare November 6, 2026 20:57
@dr-bonez
dr-bonez merged commit 0902470 into master Nov 6, 2026
11 checks passed
@dr-bonez
dr-bonez deleted the wrt/factory-reset-reboot branch November 6, 2026 21:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants