Skip to content

fix(apps): recover app runtime and harden startup - #672

Merged
RentnerKev merged 3 commits into
mainfrom
rentner/fix/app-runtime-reliability
Dec 1, 2026
Merged

RentnerKev merged 3 commits into
mainfrom
rentner/fix/app-runtime-reliability

Conversation

@RentnerKev

@RentnerKev RentnerKev commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

Problem

The v1 upstream probe uses the controller's monitoring admission. The app manager can advertise a UI it failed to load, and the migration scanner can confuse a standalone BEGIN token with a SQL routine body. An app-manager crash leaves installed apps stopped, and a background catalog fetch can report a stale catalog when staging accepts the same signed metadata during the fetch.

Changes

  • Forward the authenticated installation ID for v1 upstream probes so the controller applies app admission.
  • Fail startup before generation registration when the declared UI cannot load. Publish a typed error for the Owner and clear a matching candidate only when it belongs to a never-started first-install reservation.
  • Recognize BEGIN ATOMIC as adjacent SQL tokens in routine definitions. Require balanced routine blocks and parentheses at EOF.
  • Restart the app manager with bounded backoff and check both transient and persisted maintenance fences. The manager reconciles installed apps through its existing writer fences.
  • Sample the catalog verification clock after reading the checkpoint under the installer lock. Persist that acceptance time with the reverified metadata.

Verification

  • Bun typecheck and lint, focused UI and controller tests, and the v1 controller transport regression against disposable PostgreSQL in Kiri.
  • 203 focused Rust tests and strict Clippy in Kiri, including the SQL scanner and overlapping catalog refresh.
  • The production supervisor fixture verifies restart, backoff, and maintenance fences. The signed native lifecycle covers recovery from an app-manager SIGKILL, a UI boot failure, and selection of a healthy release after a failed first install.

Closes #656
Closes #652
Closes #653
Closes #655

Summary by CodeRabbit

  • Bug Fixes
    • App versions that cannot load their interface now fail with a clear message instead of appearing to start successfully.
    • Installations that need recovery show the issue in the app catalog, with an option to retry activation.
    • Failed first-time installs no longer leave behind an incomplete installation.
    • The app manager can restart after unexpected exits while the rest of the appliance continues running.

@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration

Commits

Reviewing files that changed from the base of the PR and between fdb88c3 and 36e8e45.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

This PR updates catalog refresh checkpoint timing, reports UI package load failures through app lifecycle state, adjusts SQL migration parsing, restarts crashed app managers under guarded backoff, and passes installation identity with upstream probes.

Changes: Catalog refresh checkpoint

Layer / File(s) Summary
Deferred clock and checkpoint refresh
core/src/app_install/browse.rs, core/src/app_install/catalog.rs, core/tests/private/app_install.rs
Background refresh now reads the clock and checkpoint after acquiring the lock. The tests cover a checkpoint rewritten during staging.

UI package failure and recovery reporting

Layer / File(s) Summary
Recovery error state and lifecycle handling
core/src/app_manager/journal.rs, core/src/app_manager.rs, core/src/app_manager/lifecycle.rs, core/src/app_manager/removal.rs, core/src/app_manager/service.rs
The journal records a recovery error for UI package load failures. The manager sets or clears that error during activation and boot handling, and includes it in applicable installation status responses.
Catalog failure classification and install handling
core/src/app_manager/catalog.rs, core/tests/private/app_manager/catalog.rs
Catalog install and lifecycle results classify UI package failures. Initial-install cleanup is limited to slots matching the stated untouched-install conditions.
Lifecycle tests and recovery display
core/tests/private/app_install.rs, core/tests/private/app_ui_package.rs, core/tests/private/app_manager/lifecycle*, web/src/lib/AppCatalog/contract.ts, web/src/lib/Language/Locales/*.json, web/src/features/AppCatalog/Components/InstalledAppCard.tsx, web/src/tests/features/AppCatalog/catalog-install-ui.test.tsx, web/src/tests/server/AppRuntime/catalog.test.ts
Tests cover failed installs and failed recovery boots. The web contract and translations accept the error, and the installed-app card displays it when management is permitted.

SQL migration parsing

Layer / File(s) Summary
Atomic routine parsing and validation
core/src/app_manager/migration.rs, core/tests/private/app_manager/migration.rs
The scanner recognizes BEGIN ATOMIC routine bodies and rejects unmatched closing parentheses. Tests cover accepted and rejected SQL forms.

App-manager restart handling

Layer / File(s) Summary
Restart scheduling and safety checks
docker/production/entrypoint.sh, docker/production/fault-supervisor.sh
The supervisor reaps exited app managers and schedules restarts with backoff. Restarts are deferred when maintenance, backup recovery, marker, or journal-safety checks prevent them.
Restart behavior tests
docker/production/tests/fault-supervisor.sh, web/src/tests/tooling/docker/production/startup-guard.test.ts
Tests cover restart delays, deferral conditions, monitoring during backoff, and startup-guard behavior.

Upstream probe identity

Layer / File(s) Summary
Installation-scoped upstream probe
web/src/server/AppRuntime/hosts.server.ts, web/src/tests/server/AppRuntime/host-operations.db.test.ts
The v1 probe passes the caller’s installation ID to controller inspection. The integration test checks the diagnostics request fields.

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant Manager
  participant UiPackage
  participant InstallationStatus
  Manager->>UiPackage: load declared UI package
  UiPackage-->>Manager: return load error
  Manager->>Manager: record UiPackageUnavailable
  Manager->>InstallationStatus: expose recoveryError
Loading
sequenceDiagram
  participant Entrypoint
  participant FaultSupervisor
  participant AppManager
  participant BackupExporter
  Entrypoint->>FaultSupervisor: reap exited app manager
  FaultSupervisor->>FaultSupervisor: schedule restart with backoff
  FaultSupervisor->>BackupExporter: check journal safety
  BackupExporter-->>FaultSupervisor: return safety result
  FaultSupervisor->>AppManager: restart when eligible and due
Loading

Possibly related issues

Possibly related PRs

Merge Risk: Minimal · previous review fdb88

This change makes app startup, the app manager, catalog refresh and v1 upstream probes more reliable. The review found no concrete merge-blocking defect in the supplied code. Normal CI checks should still run before merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "fix(apps): recover app runtime and harden startup" names the main theme of the changeset. The diff covers app-manager recovery (RecoveryError::UiPackageUnavailable, recovery_error journalin…
Description check Passed The description follows the repository template. It has a Problem section and a Changes section, a Verification section, and Closes lines for issues #656, #652, #653, and #655. It omits the template h…
Linked Issues check Passed [#656] web/src/server/AppRuntime/hosts.server.ts now passes the installation ID to inspectControllerDomain on the v1 upstream probe path. host-operations.db.test.ts checks that one /internal/v1/diagno…
Out of Scope Changes check Passed Each changed area maps to a linked issue. The web locale files, InstalledAppCard.tsx, and contract.ts add the uiPackageUnavailable message and recoveryError field that #652 needs for lifecycle status …
Full details: Title check

Explanation

The title "fix(apps): recover app runtime and harden startup" names the main theme of the changeset. The diff covers app-manager recovery (RecoveryError::UiPackageUnavailable, recovery_error journaling, restart with backoff in the supervisor), startup hardening (failing startup when a declared UI cannot load), and related fixes. It does not mention the v1 upstream probe admission, the BEGIN ATOMIC scanner fix, or the catalog clock change. Those are secondary and the title does not need to cover every detail, so the title is related to the main change.

Full details: Description check

Explanation

The description follows the repository template. It has a Problem section and a Changes section, a Verification section, and Closes lines for issues #656, #652, #653, and #655. It omits the template headings for Type of change, Checklist, Breaking changes, and Screenshots. The Related issue content is present as Closes lines. The Summary heading is replaced by Problem and Changes. The Testing content is present under Verification. The author describes the change well, but several template sections are absent.

Resolution

Optionally add the missing template sections: Type of change (Bug fix is applicable), the Checklist, Breaking changes (or None), and Screenshots (or None). Rename or map the Problem and Changes content to the Summary heading if the template is enforced strictly.

Full details: Linked Issues check

Explanation

[#656] web/src/server/AppRuntime/hosts.server.ts now passes the installation ID to inspectControllerDomain on the v1 upstream probe path. host-operations.db.test.ts checks that one /internal/v1/diagnostics/domain request carries the installation ID and upstream-only fields. The controller-side Class::App admission is not re-read in this assessment, but the forwarded ID is what the issue requires.

[#652] core/src/app_manager.rs launch now maps a failed UI package load to RecoveryError::UiPackageUnavailable and aborts activation before generation registration. hasUi is derived from the loaded package. The failure is stored in the journal slot as recovery_error and exposed as recoveryError in lifecycle status and the web contract. Tests: lifecycle/ui_package.rs covers a broken release that fails with uiPackageUnavailable and a healthy release that installs. app_ui_package.rs covers the no-ui case returning None.

[#653] core/src/app_manager/migration.rs treats only adjacent BEGIN and ATOMIC tokens as a routine body opener. The scanner requires routine and parenthesis depth to be zero at EOF. migration.rs tests accept real BEGIN ATOMIC bodies and reject unclosed bodies and unmatched parentheses. The issue's exact example is not listed verbatim in the tests. Its COMMIT falls outside any routine body, and the existing rule that rejects top-level COMMIT (tested by 'COMMIT;' and 'SELECT 1; commit') covers it.

[#655] docker/production/entrypoint.sh and fault-supervisor.sh restart the app manager with bounded backoff (1 s doubling to 30 s), defer restarts during maintenance or transient markers, and log repeated crashes. The fault-supervisor test covers the delay sequence and reset after stable uptime. The lifecycle test kills the manager and checks that the active release and data return. core/src/app_install/catalog.rs and browse.rs read the clock after taking the installer lock. Background refresh persists the new acceptance time. app_install.rs tests cover a checkpoint rewritten during staging.

Full details: Out of Scope Changes check

Explanation

Each changed area maps to a linked issue. The web locale files, InstalledAppCard.tsx, and contract.ts add the uiPackageUnavailable message and recoveryError field that #652 needs for lifecycle status reporting. removal.rs and service.rs clear or expose recovery_error for the same state. The fault-supervisor and entrypoint changes implement the #655 restart and maintenance-fence behavior. The fault-supervisor journal-safety check is part of restart safety under #655. The migration.rs changes implement #653. The test-fixture changes support the acceptance tests for #652, #655, and #656. No change was found without a connection to a linked issue.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 6e629aa and fdb88c3.

Files selected for processing: 33

  • core/src/app_install/browse.rs
  • core/src/app_install/catalog.rs
  • core/src/app_manager.rs
  • core/src/app_manager/catalog.rs
  • core/src/app_manager/journal.rs
  • core/src/app_manager/lifecycle.rs
  • core/src/app_manager/migration.rs
  • core/src/app_manager/removal.rs
  • core/src/app_manager/service.rs
  • core/tests/private/app_install.rs
  • core/tests/private/app_manager/catalog.rs
  • core/tests/private/app_manager/lifecycle.rs
  • core/tests/private/app_manager/lifecycle/ui_package.rs
  • core/tests/private/app_manager/migration.rs
  • core/tests/private/app_ui_package.rs
  • docker/production/entrypoint.sh
  • docker/production/fault-supervisor.sh
  • docker/production/tests/fault-supervisor.sh
  • web/src/features/AppCatalog/Components/InstalledAppCard.tsx
  • web/src/lib/AppCatalog/contract.ts
  • web/src/lib/Language/Locales/de.json
  • web/src/lib/Language/Locales/en.json
  • web/src/lib/Language/Locales/es.json
  • web/src/lib/Language/Locales/fr.json
  • web/src/lib/Language/Locales/it.json
  • web/src/lib/Language/Locales/nl.json
  • web/src/lib/Language/Locales/pl.json
  • web/src/lib/Language/Locales/pt.json
  • web/src/server/AppRuntime/hosts.server.ts
  • web/src/tests/features/AppCatalog/catalog-install-ui.test.tsx
  • web/src/tests/server/AppRuntime/catalog.test.ts
  • web/src/tests/server/AppRuntime/host-operations.db.test.ts
  • web/src/tests/tooling/docker/production/startup-guard.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@RentnerKev

RentnerKev commented Dec 1, 2026 •

Copy link
Copy Markdown
Member Author

Self-review (CodeRabbit rate-limited): Reviewed the complete PR diff at 1d27c9d against current main. PR maintenance merged the lucide-react update from main. The PR patch is identical to fdb88c3, which CodeRabbit reviewed without actionable comments.

The v1 probe forwards the trusted installation ID and keeps app admission separate from monitoring. UI loading completes before a generation can fence a healthy predecessor or register with the authority. The matching candidate is discarded only for a never-started first-install reservation. The signed fixture confirms that a healthy alternate release starts under the same ID. The migration scanner only recognizes adjacent BEGIN ATOMIC tokens and rejects incomplete boundaries. Scanner regressions cover ordinary identifiers, SQL trivia and balanced bodies. The background refresh reads its timestamp under the installer lock and still applies the current signed rollback floor.

The independent review found two issues that are fixed in the reviewed patch. App-manager recovery uses both transient markers and the persisted maintenance journal, and a broken UI can no longer keep a pristine install reservation bound to an unusable release. The combined Kiri run passed 203 focused Rust tests, strict Clippy, the native supervisor fixtures and the signed lifecycle with SIGKILL and UI recovery cases. The AppRuntime database regression passed in disposable PostgreSQL. On the updated main dependency, Bun typecheck and lint passed and all 21 focused UI and controller tests passed.

No action items or unresolved review threads remain. Merge is gated on the current head's completed CI.

Follow-up for 36e8e45. PR maintenance merged the Cargo dependency updates from main and the complete PR diff is still identical. CodeRabbit reported that the merge commit had no files to review. With the new lockfile, the 203 focused Rust tests, strict Clippy, the complete native supervisor fixture and the signed lifecycle passed again in Kiri. The lifecycle also verified the failed first install, the healthy alternate release and recovery from SIGKILL. The source review and thread resolution still apply to this head.

@RentnerKev
RentnerKev merged commit 1967180 into main Dec 1, 2026
69 checks passed
@RentnerKev
RentnerKev deleted the rentner/fix/app-runtime-reliability branch December 1, 2026 04:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant