Skip to content

fix(installer,desktop): surface localmodels kit errors on resume and preserve upgrade retry (WHI-1299) - #1197

Open
oldwinter53 wants to merge 1 commit into
mainfrom
fix/whi-1299-resume-localmodels-kit-error
Open

oldwinter53 wants to merge 1 commit into
mainfrom
fix/whi-1299-resume-localmodels-kit-error

Conversation

@oldwinter53

Copy link
Copy Markdown

Fixes WHI-1299

What and why

On macOS (darwin-arm64), desktop bundles do not embed bundled-localmodels-kit.tgz because of Apple notarization rules, so upgrades rely on installer.js --resume --external-computer (instanceRuntime()) to download and verify the newly pinned localmodels kit when pre-download did not run or failed.

Previously, --resume swallowed instanceRuntime() rejections with .catch(() => undefined) (logging nothing to resume.log or stderr and omitting any error from stdout JSON), while LocalServerModule silently left config.json on the stale localmodels kit and moved desktop/local-server.json forward without warning or retry.

Changes

  • apps/linger-installer/src/main.ts (--resume path):
    • Removed the silent .catch(() => undefined) on instanceRuntime(...).
    • On rejection, redacts secrets and strips URL query/fragment tokens, writes Runtime lookup failed: <error> to both resume.log and process.stderr, and emits runtimeError in the stdout JSON outcome alongside runtimeLookupTimings and resumeTimings while still exiting 0 so resumed services stay usable.
  • apps/desktop/src/main/local-server.ts (LocalServerModule):
    • Parses runtimeError from --resume stdout JSON and compares the active kit in config.runtimeEnvironment against the expected kit resolved read-only via resolveEffectiveToolSource(..., { retireStale: false }) (respecting newer verified signed <home>/tools/localmodels/active.json kits so independently upgraded kits are never downgraded, and skipping kit checks under LINGER_LOCALMODELS_DEV_* overrides).
    • Logs local_server.resume_runtime_failed naming the redacted error and expected vs active kit hashes/version/origin whenever runtimeError is present or the expected kit was not adopted.
    • Persists optional runtimeRefreshPending: true in desktop/local-server.json (backward compatible; omitted on healthy records) so subsequent launches keep retrying via non-blocking fast-ready background reconciliation or cold resume until adoption succeeds, then clears it and logs local_server.runtime_refresh_recovered.
    • Schedules bounded in-session background retries (30s, 120s, 300s) that are aborted cleanly on stop(), #reset(), server.changed, begin(), blockForManualRecovery(), and paused/resumed across suspendRecovery().

How it was verified

  • Focused tests for the changed behavior:
    • apps/linger-installer/src/main.test.ts (27 passed, including redacted runtimeError logging/stdout and empty-message fallback)
    • apps/desktop/src/main/local-server-resume.test.ts (68 passed, including upgrade runtimeError + bounded retry recovery, retry exhaustion + cross-launch non-blocking fast-ready recovery, older installer silent kit mismatch detection, newer signed active.json preservation without downgrade, normal bundled kit adoption, LINGER_LOCALMODELS_DEV_* bypass, and suspendRecovery pause/resume)
  • Touched app fast checks (Node 26.5.0):
    • make check-repository BASE=origin/main (env inventory, Prettier formatting, English-only check)
    • make check-docs BASE=origin/main (131 Markdown files, changelog valid)
    • make check-installer BASE=origin/main (typecheck, eslint --max-warnings=0, 31 test files)
    • make check-desktop BASE=origin/main (typecheck, eslint --max-warnings=0, 79 test files / 1266 tests, 41 Python packaging tests, build-daemon.mjs --all)
    • commitlint --from origin/main --to HEAD
  • Contracts regenerated if contracts/openapi/ changed (N/A — no OpenAPI contract files changed)

Boundary

  • Updated apps/linger-installer/AGENTS.md and apps/desktop/AGENTS.md to document --resume's runtimeError contract, local_server.resume_runtime_failed, runtimeRefreshPending, and bounded background retries.
  • No changes to apps/computer/ (Go daemon).
  • Does not touch the user message to provider_ready path and adds no network round trip or file walk on the desktop fast-ready critical path (expected-kit checks and retries run only after --resume completes or asynchronously in the background).

@linger-review linger-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Approve with nits (4 P2, 1 P3) · merge base 9ef0028 · 1 commit, 6 files

Findings

P2

  • apps/desktop/src/main/local-server.ts:5446 — #cancelBackgroundReconcile() leaves #reconcileHasPendingRuntimeRefresh stuck true. #reconcileAfterFastReady sets #reconcileHasPendingRuntimeRefresh = true at line 5562 and only clears it inside if (this.#reconcileAbort === controller) in finally (lines 5630–5633). Because #cancelBackgroundReconcile() clears this.#reconcileAbort = undefined before the aborted task reaches finally, that guard always evaluates to false on cancellation. If an in-flight runtime-refresh reconcile is cancelled via suspendRecovery(), server.changed, #reset(), begin(), or #resumeInner() and the installation then becomes healthy without another uncancelled background reconcile (for example via unreachable #resumeInner() recovery or reset + fresh install, or after switching to a remote server where #phase remains "ready"), every subsequent suspendRecovery() / release() cycle sees #reconcileHasPendingRuntimeRefresh === true (line 3337) and schedules a spurious #scheduleRuntimeRefreshRetry(1) (line 3386). Fix: set this.#reconcileHasPendingRuntimeRefresh = false; inside #cancelBackgroundReconcile() (every suspendRecovery() call site already reads the flag before cancelling).

  • apps/desktop/src/main/local-server.ts:6912 — canonicalDirectory duplicates canonicalPath in the same file. Lines 6912–6918 implement realpath(directory) with a path.resolve(directory) fallback, which is identical to canonicalPath at line 7213. Fix: delete canonicalDirectory and call canonicalPath at lines 6213, 6215, and 6225.

  • apps/linger-installer/src/main.ts:359 — URL query/fragment stripping + redaction is duplicated across two apps. Lines 359–363 copy the exact two regexes and redact() call from apps/desktop/src/main/local-server.ts:6559–6565, while both apps already import redact from @linger/local-installation/redaction (packages/local-installation/src/redaction.ts:2). Fix: extract a shared helper in packages/local-installation/src/redaction.ts and call it from both apps/linger-installer/src/main.ts and LocalServerModule.#formatResumeError.

  • apps/desktop/src/main/local-server-resume.test.ts:3759 — Timer race and sleep assertion in the suspendRecovery pause/resume test. Line 3759 sets runtimeRefreshRetryDelaysMs: [60], then lines 3769–3776 poll for local_server.runtime_refresh_retry_scheduled via waitForInstaller (apps/desktop/src/main/test-support.ts:87, which uses Vitest's default 50 ms vi.waitFor polling interval) before calling suspendRecovery at line 3777 and sleeping 120 ms at line 3779. Under minor CI or Windows scheduling jitter (> 10 ms past a 50 ms poll tick), retry 1 fires before suspendRecovery runs and flakes the counterFile === 1 assertion. Fix: increase the retry delay (or trigger suspendRecovery directly on the scheduled log event / poll with a small interval) so suspendRecovery deterministically runs before the timer can fire.

P3

  • apps/desktop/src/main/local-server.ts:6183 — #expectedLocalmodelsKit ignores process.env.LINGER_APP_VERSION overrides. #daemonEnv() (line 2238) preserves an existing LINGER_APP_VERSION in env for the installer.js --resume subprocess, whereas #expectedLocalmodelsKit always passes await this.#resolveAppVersion(). If LINGER_APP_VERSION is overridden in the environment to a version that makes active.json compatible for the child while #resolveAppVersion() considers it incompatible, Desktop flags a false kit_mismatch on every retry. Fix: pass effectiveLingerAppVersion(env) from the env already constructed in #runResume (line 6273) into #expectedLocalmodelsKit.

Checked: read-only active.json resolution (packages/local-installation/src/localmodels-active.ts:1721) · finally timings on lookup throw (apps/linger-installer/src/server/instance-runtime.ts:116) · daemon idle restart on computer.runtime (apps/desktop/src/main/computer-daemon.ts:427)

Process: needs rebase onto main (1 commit behind)

CI: passed (7/7 required checks)


Automated review of 7142b9f by Antigravity.

@oldwinter53
oldwinter53 force-pushed the fix/whi-1299-resume-localmodels-kit-error branch from 7142b9f to 04c306c Compare December 5, 2026 15:53
@oldwinter53

Copy link
Copy Markdown
Author

Addressed all 5 findings from the automated review and rebased onto main (04c306c53):

  • P2 #cancelBackgroundReconcile(): Reset this.#reconcileHasPendingRuntimeRefresh = false inside #cancelBackgroundReconcile() (every suspendRecovery() caller checks the flag before cancelling) and added a regression test covering cancellation during an in-flight runtime-refresh reconcile.
  • P2 canonicalDirectory duplication: Removed canonicalDirectory and reused canonicalPath in #activeLocalmodelsKitSha256.
  • P2 URL-strip + redaction duplication: Extracted redactWithUrlStrip() in packages/local-installation/src/redaction.ts with unit tests (redaction.test.ts), used by both apps/linger-installer/src/main.ts and LocalServerModule.#formatResumeError.
  • P2 suspendRecovery retry test timing: Triggered suspendRecovery directly from the local_server.runtime_refresh_retry_scheduled log event with a 200 ms delay so there is no timer/polling race.
  • P3 LINGER_APP_VERSION env override: Passed effectiveLingerAppVersion(env) from the resume subprocess environment into #expectedLocalmodelsKit() and added a unit test verifying process.env.LINGER_APP_VERSION overrides.

@linger-review linger-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Approve with nits (1 P3) · follow-up on 7142b9f · merge base 13ebbbe · 2 commits, 8 files

Resolved: clear pending reconcile flag (local-server.ts:5452) · reuse canonicalPath (local-server.ts:6219) · shared redactWithUrlStrip (redaction.ts:20) · deterministic suspendRecovery retry test (local-server-resume.test.ts:3780) · honor LINGER_APP_VERSION override (local-server.ts:6511)

Findings

P3

  • apps/desktop/src/main/local-server-resume.test.ts:3890 — The new LINGER_APP_VERSION override test duplicates ~115 lines of signed active.json and tool.json fixture setup verbatim from lines 3440–3554 (differing only in keyId and minLingerVersion), so future ACTIVE_KIT_RECORD_SCHEMA or manifest schema updates must be edited in two places. Fix: extract a local writeSignedActiveKitFixture(home, { minLingerVersion }) helper shared by both tests.

Checked: installer distribution.json loading (apps/linger-installer/src/main.ts:901,924) · manifest safeRelative path depth (packages/local-installation/src/localmodels-tool.ts:120,246) · suspendRecovery retry handoff (apps/desktop/src/main/local-server.ts:3333,5473,5520)

Process: squash the review-fixup commit 04c306c into 70b58af before rebase-merging onto main

CI: passed (9/9 checks)


Automated review of 04c306c by Antigravity.

…preserve upgrade retry

Surface instanceRuntime() rejections during headless --resume as a redacted runtimeError field (via shared redactWithUrlStrip) with resume.log and stderr logging while keeping exit 0 so resumed services stay usable. In LocalServerModule, log local_server.resume_runtime_failed with expected vs active localmodels kit hashes (resolved read-only via resolveEffectiveToolSource with effectiveLingerAppVersion so newer signed active.json kits are never downgraded), persist runtimeRefreshPending in desktop/local-server.json until adoption succeeds, and run bounded background retries without blocking startup.

Fixes WHI-1299
@oldwinter53
oldwinter53 force-pushed the fix/whi-1299-resume-localmodels-kit-error branch from 04c306c to cf26cfe Compare December 5, 2026 16:13
@oldwinter53

Copy link
Copy Markdown
Author

Extracted the shared writeSignedActiveKitFixture() helper in apps/desktop/src/main/local-server-resume.test.ts to remove the duplicated signed active.json fixture setup, and squashed the branch into a single commit (cf26cfe02) on top of origin/main.

@linger-review linger-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Approve · follow-up on 04c306c · merge base 13ebbbe · 1 commit, 8 files

Resolved: duplicated signed kit fixture setup (local-server-resume.test.ts:3067,3580,3922)

Checked: read-only active.json resolution (packages/local-installation/src/localmodels-active.ts:1701,1721) · timings on instanceRuntime throw (apps/linger-installer/src/server/instance-runtime.ts:116) · suspendRecovery retry handoff (apps/desktop/src/main/local-server.ts:3333,5473,5520)

CI: passed (9/9 checks)


Automated review of cf26cfe by Antigravity.

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.

2 participants