Repository navigation
feat(computer): add Go daemon localmodels kit updater with hot-swap, rollback, and CLI (WHI-1151) - #1198
feat(computer): add Go daemon localmodels kit updater with hot-swap, rollback, and CLI (WHI-1151)#1198oldwinter53 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Request changes (3 P1, 4 P2, 2 P3) · merge base 9ef0028 · 1 commit, 21 files
Findings
P1
-
apps/computer/local-daemon/cmd/linger-computer-daemon/main.go:616(and:970) —buildDaemonKitUpdaterreceivesbaseProviderEnvironment(built atmain.go:182viacomputerconfig.RuntimeEnvironmentatinternal/computerconfig/environment.go:34), which strips allLINGER_*variables, and then readsenvironment["LINGER_APP_VERSION"]from it. BecauseLINGER_APP_VERSIONis always empty in the resident Daemon,ValidateKitManifestCompatibility(internal/localmodels/kit_manifest.go:647) completely skipsminLingerVersionandmaxLingerVersionchecks: a Daemon on an older Linger release will treat an incompatible kit asavailableand activate it intoactive.json, only for startupresolveStartupLocalModelsTool(main.go:215, which gets rawenvironment) to retire it on next launch. PasslingerVersionresolved from the raw processenvironmentintobuildDaemonKitUpdaterseparately from the scrubbedbaseProviderEnvironmentused for child tool invocations. -
apps/computer/local-daemon/internal/localmodels/kit_updater.go:1190(andmain.go:210-214,localmodels_update_cli.go:230-234) — Overwritingcomputer.json'slocal_models.pythonandlocal_models.module_directoryviaUpdateLocalModelsTooldestroys the bundled baseline pointer because startup (main.go:210-214) and standalone CLI (localmodels_update_cli.go:151-164, 230-234) both loadBundledToolfromcomputer.json. On the first upgrade from bundledv1to activev2,active.jsonrecordsPrevious: nil(kit_updater.go:1164-1185) whilecomputer.jsonis overwritten tov2. After any Daemon restart—or in a follow-up standalonelocalmodels update --rollback --config computer.jsoncall—Rollbackseesactive.Record.Previous == nilandsamePathOrResolvedParent(bundledDir, active.KitDir) == true(kit_updater.go:1513) and fails withno_rollback_target(which is whylocalmodels_update_cli_test.go:347-353had to pass--python/--module-direxplicitly). It also breaks fail-closed startup fallback on headless Computers: ifactive.jsonis later retired as incompatible (kit_active.go:478-496) or corrupted,ResolveEffectiveKitfalls back tocomputer.jsonand keeps running the retiredv2, and a later upgrade dropsv1fromPruneUnusedKitDirskeepDirs(kit_updater.go:1306). Keepcomputer.jsonpinned to the bundled baseline and let<toolsRoot>/active.jsonremain the single source of truth for signed overrides (every Daemon and stateless CLI path already resolvesactive.jsonahead ofcomputer.json), removingUpdateLocalModelsToolandUpdateComputerConfig—or persist the bundled baseline separately so restart, rollback, and retirement never lose it. -
apps/computer/local-daemon/internal/localmodels/kit_updater.go:1244(and:1263-1270,:1345-1370) —verifyLiveSwapraces withLibrary.StopAlland caller cancellation. WhilecommitActivationLockedholdsu.library.lifecycleMu(e.g., during the up-to-30srunKitMigrate),StopAll(internal/localmodels/lifecycle_stop.go:279-281) incrementsl.stoppingCountbefore blocking onlifecycleMu. WhenverifyLiveSwapthen callsu.library.Refresh(verifyCtx),Library.Refresh(internal/localmodels/library.go:1036-1041) short-circuits and returnsl.currentSnapshotLocked()without executing the new kit: on a warm cache (l.current != nil),verifyLiveSwapsees the stale pre-swapAvailable: truesnapshot and commits an unverified kit; on a cold cache (l.current == nil, returningstoppingRefusalwithCodeToolFailedatlibrary.go:443, 3001) or when callerctxis canceled duringverifyLiveSwap,commitActivationLockedtreats the error as a broken kit and permanently blacklists a healthy version inrejected.json(kit_updater.go:1263-1270). Checku.library.isStoppingOrClosed()before/afterverifyLiveSwapand checkerrors.Is(ctx.Err(), context.Canceled): roll back cleanly without callingRecordRejectedKit, and never treat astoppingCount > 0short-circuit as a passing verification.
P2
-
apps/computer/local-daemon/internal/localmodels/kit_updater.go:2121(and:2085-2119) — The production HTTPS transport (newKitHTTPClient), DNS-rebindingDialContext,CheckRedirectpolicy, proxy env handling (buildKitProxyFunc/collectConfiguredProxyHosts), andvalidatePublicHTTPSHosthave zero unit tests because every test inkit_updater_test.goandlocalmodels_update_cli_test.goinjects a customHTTPClient(u.customHTTPClient = true), bypassing bothnewKitHTTPClientandvalidatePublicHTTPSHost(kit_updater.go:2085-2092). Add focused tests coveringvalidatePublicHTTPSHost(loopback/private/IMDS/non-canonical IPv4 literals),CheckRedirect(non-HTTPS, credentials, non-public target, hop cap), proxy selection, and connect-time IP rejection innewKitHTTPClient. -
apps/computer/local-daemon/internal/localmodels/kit_updater.go:2068(and:2096-2119) —validateFetchURLandvalidatePublicHTTPSHostduplicatevalidatePublicHTTPSURLfrominternal/localmodels/kit_manifest.go:503-545,allowQueryis passedfalseat all 4 call sites (kit_updater.go:1736, 1878, 2022, 2065), andvalidateFeedURL(:2064) is a single-use one-line wrapper. ExtractvalidatePublicHTTPSHostinkit_manifest.go, share it fromvalidatePublicHTTPSURL,validateFetchURL, andCheckRedirect, and drop the unusedallowQueryparameter andvalidateFeedURL. -
apps/computer/local-daemon/internal/localmodels/kit_updater.go:629(and:2423-2455) —Dismisschecksu.opBusy, mutatesu.statustoidle, releasesu.muat:629, and callsu.notify(snap)at:630. Betweenu.mu.Unlock()andu.notifyMu.Lock()(:2450), a concurrentCheck/Apply/Rollback(e.g., background poll tick) can acquireopBusy, transition tochecking/available, and acquirenotifyMufirst, causing observers to receive[checking, idle]and violateOnStatus's strict publication-order guarantee (:481-483). SerializeDismissthroughtryAcquireOp/releaseOpso transitions and notifications stay strictly ordered without deadlocking re-entrant observers. -
apps/computer/local-daemon/internal/localmodels/kit_updater.go:533(and:641, :960, :1403) —KitUpdater.Close()cancelsu.ctxand waits onu.wg, butCheck,Apply, andRollbackdo not bind their contexts tou.ctx(onlywaitForActiveJobsat:1638watchesu.ctx.Done()) and do not participate inu.wg. On Daemon shutdown (main.go:655-659, 621, 251), ifPOST /localmodels/kit-updateapplyoutlivescontrolServer.Close's 2s grace window,kitUpdater.Close()returns immediately while download, unpack, oractive.jsonwrites continue racing againstlocalModels.Close()and process exit. Derive each operation's context fromctxandu.ctx(viacontext.AfterFunc) and track active operations inu.wginsidetryAcquireOp/releaseOp.
P3
-
apps/computer/local-daemon/internal/localmodels/kit_updater_test.go:1409—TestKitUpdaterDevOverrideDisabledAndDismissusestime.Sleep(40 * time.Millisecond)to verify a disabled updater did not poll. BecauseStartreturns synchronously without spawning a goroutine whenu.disabled(kit_updater.go:514), remove the sleep and assert!devUpdater.startedandhits.Load() == 0afterdevUpdater.Close(). -
apps/computer/local-daemon/internal/localmodels/kit_unpack.go:88(andkit_unpack_unix.go:59,kit_updater.go:243,kit_unpack_test.go:172) — Code comments reference PR number#1155, violating the repository convention against issue/PR numbers in comments (AGENTS.md). State the permission invariant directly (owner-writable0700/0600POSIX permissions) without#1155.
Checked: archive layout and size cap (packages/local-installation/src/localmodels-tool.ts:329) · privatefs check on 0500/0700 dirs (apps/computer/local-daemon/internal/platform/privatefs/privatefs_unix.go:27) · control server write timeouts (apps/computer/local-daemon/internal/linger/control/listener_unix.go:64)
Unverified: go test -race on apps/computer/local-daemon (Go toolchain unavailable in review environment)
Process: needs rebase onto main (1 commit behind)
CI: all 9 checks passed (computer-go runs without -race; local @linger/computer checks not run)
Automated review of c0c5bc9 by Antigravity.
c0c5bc9 to
2f354ab
Compare
|
Rebased onto latest P1
P2
P3
|
There was a problem hiding this comment.
Approve with nits (1 P2) · follow-up on c0c5bc9 · merge base 13ebbbe · 2 commits, 24 files
Resolved: raw LINGER_APP_VERSION forwarding (main.go:617) · persisted bundled baseline (kit_active.go:494) · StopAll/cancel live-verify fencing (kit_updater.go:1396) · production HTTPS/redirect/proxy tests (kit_updater_test.go:1909) · shared validatePublicHTTPSHost (kit_manifest.go:524) · Dismiss observer serialization (kit_updater.go:606) · Close op cancellation and wait (kit_updater.go:2463) · sleep-free disabled test (kit_updater_test.go:1412) · PR number comments removed (kit_unpack.go:88)
Findings
P2
apps/computer/local-daemon/internal/localmodels/kit_active.go:571(and:383-443) —verifyBundledKitDirectoryduplicates the ~55-line directory containment, symlink-escape,privatefs,tool.jsonschema/target, and relative-entry verification body ofverifyActiveKitDirectoryright above it in the same file, differing only in skipping the manifest-boundSHA256/ManifestSHA256/SourceCommitchecks and defaultingtargettoCurrentKitTarget(). Future security or layout hardening applied to one path can silently drift from the other. Collapse both into a singleverifyKitDirectory(cleanRoot, rawKitDir, target string, expected *KitManifestTarget)helper that enforces the manifest-bound fields whenexpected != niland validateskitHex64Patternotherwise.
Checked: RuntimeEnvironment LINGER_* scrubbing (apps/computer/local-daemon/internal/computerconfig/environment.go:34) · installer kit permission parity (packages/local-installation/src/localmodels-tool.ts:363) · StopAll stopGen fencing (apps/computer/local-daemon/internal/localmodels/library.go:514)
Unverified: go test -race on apps/computer/local-daemon (Go toolchain unavailable in review environment) · local @linger/computer TS and process tests
Process: squash review-fixup commit 2f354ab into a8ef1d1 before rebase merge; rerun check (computer-go)
CI: 8/9 passed; computer-go failed on unrelated native test (touched packages passed; no -race)
Automated review of 2f354ab by Antigravity.
…rollback, and CLI
2f354ab to
4ee90be
Compare
|
Collapsed |
There was a problem hiding this comment.
Approve · follow-up on 2f354ab · merge base 13ebbbe · 1 commit, 24 files
Resolved: shared kit directory verification (kit_active.go:383)
Checked: active.json TS schema parity (packages/local-installation/src/localmodels-active.ts:1540) · proxy IMDS netguard policy (apps/computer/local-daemon/internal/platform/netguard/netguard.go:79) · probe exclusion in ActiveJobCount (apps/computer/local-daemon/internal/localmodels/concurrency_probe.go:833)
Unverified: local go test -race (no Go toolchain in review env) · local @linger/computer TS/process tests
CI: all 9 checks passed (computer-go runs without -race; local @linger/computer checks skipped)
Automated review of 4ee90be by Antigravity.
Refs WHI-1151
Summary
Implements Phase 1 / PR 3 of the Linger ×
localmodelsdecoupled upgrade architecture inside the Go Local Computer Daemon, building on merged PR #1183 (forward-compatibility hardening) and PR #1190 (signedactive.jsoncontract and lock-freeToolHandle):KitUpdater(internal/localmodels/kit_updater.go):idle,checking,up_to_date,available,incompatible,downloading,verifying,waiting_for_jobs,activating,rolled_back,failed,disabled) with snake_case JSONKitUpdateStatusand orderedOnStatusobserver hook for PR 4 Runner Gateway wiring.releases.heylinger.com/cli/localmodels/channels/{stable,next}/manifest.json+.sig) with adaptive baseline channel gating, monotonicsequenceanti-rollback,rollout.percent == 0kill-switch,rejected.jsonfiltering (with manualforce_retry), and region-ordered npm dist-tag fallback (registry.npmmirror.com/registry.npmjs.org→ immutable CDN manifest or@simplexai/localmodelsmeta-package tarball, always validated through the same Ed25519 + Schema v2 compatibility pipeline).netguardHTTPS transport honoringHTTP_PROXY/HTTPS_PROXY/NO_PROXY, strict body size caps (256 KiB manifest, 4 KiB signature, exactkit.bytestarball cap), DNS-rebinding protection, and public-HTTPS redirect validation.LINGER_LOCALMODELS_DEV_*); never auto-downloads or auto-applies without explicit trigger.#1155Parity (internal/localmodels/kit_unpack{,_unix,_windows}.go):region.json/SIMPLEX_REGION) with streaming SHA-256 verification and automatic mirror failover; reuses already-unpacked verified<toolsRoot>/<sha256>directories.tool.json(manifestSha256,schemaVersion == 1, platform/arch,sourceCommit, every asset SHA-256) and optionalbootstrap.sha256.#1155permissions (POSIX0700dirs/executables,0600regular files; Windows owner-only ACLs viaprivatefs) and restores PEP 552.pycsource mtimes.kit migrate& Auto-Rollback (internal/localmodels/kit_smoke.go,library.go,speech.go,tts.go,internal/computerconfig/config.go):capabilities --json(localmodels.capabilities/v1,cliContractmajor3) andlibrary status --base-dir <tmp> --jsonagainst temporary state/base dirs before touching live state.ActiveJobCount()toLibrary,SpeechLibrary, andTtsLibrary(counting only CLI download/load/unload/adopted jobs — never active LLM inference leases), defers inwaiting_for_jobsuntil CLI jobs drain, coordinates onLibrary.lifecycleMu, atomically persistsactive.json+computer.json(computerconfig.UpdateLocalModelsTool), swapsToolHandlein-process, invalidates Speech/TTS support & voice caches, runskit migrate --base-dir <dir> --json, and verifies liveLibrary.Refresh.ToolHandle,active.json, andcomputer.json, records<version>:<sha256>inrejected.json, and re-refreshes live state on post-swapTOOL_FAILEDor timeout; prunes unreferenced older kits only when live verification succeeds andkit migratereports zeroskipped_runningor errors.internal/linger/control/server.go,cmd/linger-computer-daemon/{main.go,localmodels_cli.go,localmodels_update_cli.go}):KitUpdaterintolinger-computer-daemonand addsGET /localmodels/kit-updateandPOST /localmodels/kit-update(check,apply,rollback,dismiss).linger-computer-daemon localmodels update [--status | --check | --apply | --rollback] [--channel stable|next] [--feed-url <https-url>] [--force-retry] [--json], delegating to a live Daemon when reachable and falling back to standalone mode when offline.apps/computer/local-daemon/andapps/computer/AGENTS.md; Runner Gateway, OpenAPI, TeamHub, and Web UI wiring follow in PR 4.Critical Path Impact
No network round trips or extra file walks are added to the user message ->
provider_readypath.KitUpdater.Startruns a deferred background metadata-only poller (90 s initial delay + jitter) completely off startup and inference paths.Verification
go test -race -count=1 ./internal/computerconfig/... ./internal/localmodels/... ./internal/linger/control/... ./internal/daemon/... ./cmd/linger-computer-daemon/...GOOS=windows GOARCH=amd64 go build ./...and Windowsgo test -coninternal/computerconfig,internal/localmodels,internal/linger/control,cmd/linger-computer-daemongolangci-lint run --new-from-rev=origin/main ./...and.golangci.doc-comments.yml(0 issues)make check-repository-gate BASE=origin/main