Beautiful, AI-native markdown IDE and LLM wiki
TypeScript 2nd-brainagent-skillsclaudecodexcompany-braindocsknowledge-knowledge-baseknowledge-managementllmllm-wikillm-wiki-karpathymarkdownmarkdown-editormdmdxnotespkmsecond-brainskills
fix(ok): re-offer a staged install no quit ever committed (PRD-8263) (#3825)
Andrew Mikofalvy21abd2976e35
diff --git a/.changeset/windows-shutdown-voids-staged-install.md b/.changeset/windows-shutdown-voids-staged-install.mdnew file mode 100644index 000000000..ea26b5ab9--- /dev/null+++ b/.changeset/windows-shutdown-voids-staged-install.md@@ -0,0 +1,11 @@+---+"@inkeep/open-knowledge": patch+---++An update you downloaded is no longer thrown away when Windows ends your session, and the app no longer tells you an install failed when it never started one.++On Windows there were only two moments an update could actually install: you clicked "Relaunch now", or you quit the app and it installed on the way out. Shutting the machine down is neither. Windows terminates the app without giving it the chance to run its quit steps, so the update was silently discarded — and because the app had already recorded that an install was underway, the next launch reported a failure for something that had never been attempted.++For anyone who leaves the app open and shuts the laptop down rather than quitting, that repeated every time, so they never got an update at all. After three launches the failure notice gave up and went quiet too, leaving no sign that an update was sitting there ready to install.++The app now tells the two situations apart. An install that was genuinely handed over and did not take is still reported as a failure, unchanged. An update that no quit ever committed is recognized as still waiting, and is offered again the ordinary way — the same "ready to install" prompt you would have seen after the download — for as long as it is waiting. Nothing installs without you choosing it.diff --git a/knip.config.ts b/knip.config.tsindex b61debe5e..8ad68f996 100644--- a/knip.config.ts+++ b/knip.config.ts@@ -124,7 +124,9 @@ export default {'packages/server': {entry: ['src/**/*.test.ts', 'src/parse-worker.ts'],project: 'src/**',- ignoreDependencies: ['@types/shell-quote'],+ ignoreDependencies: [+ '@types/shell-quote',+ ],},'packages/cli': {entry: ['src/**/*.test.ts', 'scripts/*.ts', 'tests/**/*.ts', 'src/parse-worker.ts'],diff --git a/packages/core/src/bridge/bind-frontmatter-doc.ts b/packages/core/src/bridge/bind-frontmatter-doc.tsindex d7a845280..dfd95ef49 100644--- a/packages/core/src/bridge/bind-frontmatter-doc.ts+++ b/packages/core/src/bridge/bind-frontmatter-doc.ts@@ -1,3 +1,4 @@+import type * as Y from 'yjs';import type { Err, Ok, Result } from '../config/result.ts';import { type FrontmatterValidationError, toFrontmatterIssue } from '../frontmatter/errors.ts';diff --git a/packages/core/src/bridge/bridge-invariant.ts b/packages/core/src/bridge/bridge-invariant.tsindex 005627195..8bfdb40cd 100644--- a/packages/core/src/bridge/bridge-invariant.ts+++ b/packages/core/src/bridge/bridge-invariant.ts@@ -1,3 +1,4 @@+import { fnv1aDigest } from './hash-util.ts';export type BridgeInvariantSite = 'observer-b' | 'persistence' | 'test-harness';diff --git a/packages/core/src/bridge/compose.ts b/packages/core/src/bridge/compose.tsindex f4cc8a286..2a597ec3d 100644--- a/packages/core/src/bridge/compose.ts+++ b/packages/core/src/bridge/compose.ts@@ -1,3 +1,4 @@+import { prependFrontmatter, stripFrontmatter } from '../extensions/frontmatter.ts';export type ComposeAdjustment = 'none' | 'body' | 'frontmatter' | 'unresolved';diff --git a/packages/core/src/bridge/divergence-locate.ts b/packages/core/src/bridge/divergence-locate.tsindex 6b505314d..d979f4b39 100644--- a/packages/core/src/bridge/divergence-locate.ts+++ b/packages/core/src/bridge/divergence-locate.ts@@ -1,3 +1,4 @@+import { findFirstDivergenceIndex } from './tolerance-telemetry.ts';export const BRIDGE_LINE_KINDS = [diff --git a/packages/core/src/bridge/doc-boundary-space.ts b/packages/core/src/bridge/doc-boundary-space.tsindex 8fb428b90..01ef76a9f 100644--- a/packages/core/src/bridge/doc-boundary-space.ts+++ b/packages/core/src/bridge/doc-boundary-space.ts@@ -1,3 +1,4 @@+import { FRONTMATTER_RE, stripFrontmatter } from '../extensions/frontmatter.ts';import { carriedEdgeEmpties, type DocEdgeEmpties } from '../markdown/doc-edge-blank-runs.ts';diff --git a/packages/core/src/bridge/growth-detect.ts b/packages/core/src/bridge/growth-detect.tsindex 9d9c244b0..463e89595 100644--- a/packages/core/src/bridge/growth-detect.ts+++ b/packages/core/src/bridge/growth-detect.ts@@ -1,3 +1,4 @@+const DEFAULT_MIN_SUBSTANTIVE_LINE_LENGTH = 16;export const DUPLICATION_GATE_MIN_LINE_LENGTH = 8;diff --git a/packages/core/src/bridge/intraline-predicate.ts b/packages/core/src/bridge/intraline-predicate.tsindex c43fdd7e7..0939885bb 100644--- a/packages/core/src/bridge/intraline-predicate.ts+++ b/packages/core/src/bridge/intraline-predicate.ts@@ -1,3 +1,4 @@+export function rawLineCounts(doc: string): Map<string, number> {const counts = new Map<string, number>();for (const line of doc.split('\n')) {diff --git a/packages/core/src/bridge/merge-three-way.ts b/packages/core/src/bridge/merge-three-way.tsindex 251560a35..c0dc65705 100644--- a/packages/core/src/bridge/merge-three-way.ts+++ b/packages/core/src/bridge/merge-three-way.ts@@ -65,6 +65,7 @@ export function tryLineLevelCombine(return { clean: true, merged };}+export type BridgeMergeContentLossSide = 'user' | 'agent';export type BridgeMergeContentLossWhich = 'substring' | 'order' | 'growth';diff --git a/packages/core/src/bridge/normalize.ts b/packages/core/src/bridge/normalize.tsindex 01ac80099..dcc5b0690 100644--- a/packages/core/src/bridge/normalize.ts+++ b/packages/core/src/bridge/normalize.ts@@ -1,3 +1,4 @@+import { stripFrontmatter } from '../extensions/frontmatter.ts';import { bodyEdgeEmpties } from './doc-boundary-space.ts';diff --git a/packages/core/src/bridge/pm-structural-equivalence.ts b/packages/core/src/bridge/pm-structural-equivalence.tsindex 754dc5cc2..0be5203e4 100644--- a/packages/core/src/bridge/pm-structural-equivalence.ts+++ b/packages/core/src/bridge/pm-structural-equivalence.ts@@ -32,6 +32,7 @@ const BR_SENTINEL: PmStructuralNode = { type: '__br__' };const BR_LITERAL_RE = /^<br\s*\/?>$/i;+interface DegradeEntry {readonly label: string;readonly severity: ToleranceClassSeverity;@@ -127,6 +128,7 @@ export interface ComparePmStructuralOptions {ignoreAttrs?: (attrKey: string) => boolean;}+/** Rebuild a node with `fn` applied to each child; identity when childless.* Shared by the degrade canonicalizers so none re-implements the walk. */function mapChildren(@@ -248,6 +250,7 @@ function applyDegrades(tree: PmStructuralNode): {return { normalized: current, fired };}+export function comparePmStructural(expected: PmStructuralNode,actual: PmStructuralNode,diff --git a/packages/core/src/bridge/subsequence.ts b/packages/core/src/bridge/subsequence.tsindex af20de1e2..dca644141 100644--- a/packages/core/src/bridge/subsequence.ts+++ b/packages/core/src/bridge/subsequence.ts@@ -1,3 +1,4 @@+/** True when `needle` is a subsequence of `haystack` (two-pointer, O(n+m)):* insertions in `haystack` are free; any dropped or substituted `needle` byte* fails. */diff --git a/packages/core/src/markdown/callout-transformer.ts b/packages/core/src/markdown/callout-transformer.tsindex 83d47404a..a363dfd54 100644--- a/packages/core/src/markdown/callout-transformer.ts+++ b/packages/core/src/markdown/callout-transformer.ts@@ -1,3 +1,4 @@+import type { Blockquote, Paragraph, Root } from 'mdast';import type { MdxJsxAttribute, MdxJsxFlowElement } from 'mdast-util-mdx';import { visit } from 'unist-util-visit';diff --git a/packages/core/src/markdown/code-fence.ts b/packages/core/src/markdown/code-fence.tsindex 9807a7e82..4499dbc92 100644--- a/packages/core/src/markdown/code-fence.ts+++ b/packages/core/src/markdown/code-fence.ts@@ -1,3 +1,4 @@+export function selectFenceChar(info: string): '`' | '~' {return info.includes('`') ? '~' : '`';}diff --git a/packages/core/src/markdown/comment-promoter.ts b/packages/core/src/markdown/comment-promoter.tsindex 7415c474a..34704165b 100644--- a/packages/core/src/markdown/comment-promoter.ts+++ b/packages/core/src/markdown/comment-promoter.ts@@ -1,3 +1,4 @@+import type { Nodes, Paragraph, PhrasingContent, Root, RootContent, Text } from 'mdast';import { SKIP, visit } from 'unist-util-visit';import type { VFile } from 'vfile';diff --git a/packages/core/src/markdown/dedent-block-jsx-close.ts b/packages/core/src/markdown/dedent-block-jsx-close.tsindex ece5c02a1..b6299a948 100644--- a/packages/core/src/markdown/dedent-block-jsx-close.ts+++ b/packages/core/src/markdown/dedent-block-jsx-close.ts@@ -1,3 +1,4 @@+import { findFencedRegions, isInsideFence } from './fence-regions.ts';const INDENTED_BLOCK_JSX_CLOSE_RE = /^([ ]{1,3})(<\/[A-Z][A-Za-z0-9_]*\s*>)([ \t]*)$/gm;diff --git a/packages/core/src/markdown/details-accordion-promoter.ts b/packages/core/src/markdown/details-accordion-promoter.tsindex 54774764a..acd398aa6 100644--- a/packages/core/src/markdown/details-accordion-promoter.ts+++ b/packages/core/src/markdown/details-accordion-promoter.ts@@ -1,3 +1,4 @@+import type { Nodes, Paragraph, Parent, Root, Text } from 'mdast';import type { MdxJsxAttribute, MdxJsxFlowElement } from 'mdast-util-mdx';import { visit } from 'unist-util-visit';diff --git a/packages/core/src/markdown/div-align-promoter.ts b/packages/core/src/markdown/div-align-promoter.tsindex 43ecdc709..ba9b56384 100644--- a/packages/core/src/markdown/div-align-promoter.ts+++ b/packages/core/src/markdown/div-align-promoter.ts@@ -1,3 +1,4 @@+import type { Nodes, Paragraph, Parent, Root, Text } from 'mdast';import type { MdxJsxFlowElement } from 'mdast-util-mdx';import { visit } from 'unist-util-visit';diff --git a/packages/core/src/markdown/fence-regions.ts b/packages/core/src/markdown/fence-regions.tsindex 6d3f3643e..4513da9bb 100644--- a/packages/core/src/markdown/fence-regions.ts+++ b/packages/core/src/markdown/fence-regions.ts@@ -1,3 +1,4 @@+const FENCE_RE = /^(`{3,}|~{3,})/gm;export function findFencedRegions(src: string): Array<[number, number]> {diff --git a/packages/core/src/markdown/fixtures/index.ts b/packages/core/src/markdown/fixtures/index.tsindex 00f5771ee..6931623c7 100644--- a/packages/core/src/markdown/fixtures/index.ts+++ b/packages/core/src/markdown/fixtures/index.ts@@ -1,3 +1,4 @@+import { readFileSync } from 'node:fs';import { dirname, resolve } from 'node:path';import { fileURLToPath } from 'node:url';@@ -8,6 +9,7 @@ function fixturePath(...segments: string[]): string {return resolve(FIXTURES_DIR, ...segments);}+interface GfmExample {section: string;markdown: string;@@ -17,6 +19,7 @@ export function loadGfmExamples(): GfmExample[] {return JSON.parse(readFileSync(fixturePath('gfm', 'examples.json'), 'utf8')) as GfmExample[];}+interface MdxCrashEntry {id: string;input: string;@@ -68,6 +71,7 @@ export function loadLargeEmbedFixtures(): LargeEmbedFixture[] {) as LargeEmbedFixture[];}+export function loadPrd6955Before(): string {return readFileSync(fixturePath('regression', 'prd-6955-before.md'), 'utf8');}@@ -76,6 +80,7 @@ export function loadPrd6955CorruptedTriplicated(): string {return readFileSync(fixturePath('regression', 'prd-6955-corrupted-triplicated.md'), 'utf8');}+export interface NgPinnedCase {id: string;name: string;@@ -92,6 +97,7 @@ export function loadNgPinnedCases(): NgPinnedCase[] {) as NgPinnedCase[];}+export function loadLargeRealistic(): string {return readFileSync(fixturePath('perf', 'large-realistic.md'), 'utf8');}diff --git a/packages/core/src/markdown/fixtures/perf/generate.ts b/packages/core/src/markdown/fixtures/perf/generate.tsindex 8b1eb8519..daa3ef82b 100644--- a/packages/core/src/markdown/fixtures/perf/generate.ts+++ b/packages/core/src/markdown/fixtures/perf/generate.ts@@ -1,3 +1,4 @@+import { writeFileSync } from 'node:fs';import { dirname, resolve } from 'node:path';import { fileURLToPath } from 'node:url';@@ -10,6 +11,7 @@ const BASELINE_ONLY_COUNTS = [500, 2500] as const;const SEED = 0xf1de1117;+function mulberry32(seed: number): () => number {let a = seed >>> 0;return () => {@@ -36,6 +38,7 @@ function pickWeighted<T>(rand: () => number, items: readonly [T, number][]): T {return items[items.length - 1][0];}+const WORDS = ['lorem','ipsum',@@ -153,6 +156,7 @@ function mdxBlock(rand: () => number): string {return `<${name}>\n\n${sentence(rand)}\n\n</${name}>`;}+type BlockKind = 'paragraph' | 'heading' | 'list' | 'code' | 'table' | 'mdx';const MIX: readonly [BlockKind, number][] = [@@ -191,6 +195,7 @@ function generateDocument(blockCount: number, seed: number): string {return `${blocks.join('\n\n')}\n`;}+function main(): void {for (const count of [...BLOCK_COUNTS, ...BASELINE_ONLY_COUNTS]) {const doc = generateDocument(count, SEED);diff --git a/packages/core/src/markdown/guard-flanking-matrix.ts b/packages/core/src/markdown/guard-flanking-matrix.tsindex 420dc0fe5..32c055c5b 100644--- a/packages/core/src/markdown/guard-flanking-matrix.ts+++ b/packages/core/src/markdown/guard-flanking-matrix.ts@@ -7,6 +7,7 @@ import {import { BACKSLASH_GUARD_SUBSTITUTIONS, encodeBackslashEscapes } from './backslash-escape-guard.ts';import { ENTITY_REF_GUARD_SUBSTITUTIONS, encodeEntityRefs } from './entity-ref-guard.ts';+export const ATTENTION_DELIMITERS = ['*', '_', '**', '~~', '=='] as const;export type FlankClass = 'whitespace' | 'punctuation' | 'other';diff --git a/packages/core/src/markdown/handler-shadow-audit.ts b/packages/core/src/markdown/handler-shadow-audit.tsindex 2653473da..283913255 100644--- a/packages/core/src/markdown/handler-shadow-audit.ts+++ b/packages/core/src/markdown/handler-shadow-audit.ts@@ -1,3 +1,4 @@+export interface HandlerShadowWitness {input: string;expect: 'byte' | 'byte-and-reparse-type';diff --git a/packages/core/src/markdown/highlight-promoter.ts b/packages/core/src/markdown/highlight-promoter.tsindex da0a81d23..5d1000cc4 100644--- a/packages/core/src/markdown/highlight-promoter.ts+++ b/packages/core/src/markdown/highlight-promoter.ts@@ -1,3 +1,4 @@+import type { Nodes, Parent, PhrasingContent, Root, Text } from 'mdast';import type { MdxJsxTextElement } from 'mdast-util-mdx';import { SKIP, visit } from 'unist-util-visit';diff --git a/packages/core/src/markdown/html-to-mdast.ts b/packages/core/src/markdown/html-to-mdast.tsindex 787315157..9681c0056 100644--- a/packages/core/src/markdown/html-to-mdast.ts+++ b/packages/core/src/markdown/html-to-mdast.ts@@ -1,3 +1,4 @@+import type { Element as HastElement, Root as HastRoot } from 'hast';import type { List, Nodes as MdastNodes, Root as MdastRoot } from 'mdast';import rehypeParse from 'rehype-parse';@@ -128,7 +129,8 @@ export function htmlToMdast(html: string, options?: HtmlToMdastOptions): MdastRothrow new HtmlPayloadTooLargeError(html.length, maxBytes);}- const processor = unified().use(rehypeParse, { fragment: true });+ const processor = unified()+ .use(rehypeParse, { fragment: true });for (const plugin of cleanupPlugins) {processor.use(plugin);diff --git a/packages/core/src/markdown/image-promoter.ts b/packages/core/src/markdown/image-promoter.tsindex 706fa9afb..994eb6917 100644--- a/packages/core/src/markdown/image-promoter.ts+++ b/packages/core/src/markdown/image-promoter.ts@@ -1,3 +1,4 @@+import type { Image, Paragraph, Root } from 'mdast';import type { MdxJsxAttribute, MdxJsxFlowElement } from 'mdast-util-mdx';import { visit } from 'unist-util-visit';diff --git a/packages/core/src/markdown/index.ts b/packages/core/src/markdown/index.tsindex 779e27500..ec1ac1b7e 100644--- a/packages/core/src/markdown/index.ts+++ b/packages/core/src/markdown/index.ts@@ -1,3 +1,4 @@+import {type FromProseMirrorOptions,fromPmMark,@@ -206,6 +207,7 @@ export class MarkdownManager {}}+const registry = createRegistry();function destructureAttrs(@@ -254,6 +256,7 @@ function destructureAttrs(return result;}+function hasDirtyDescendant(node: PmNode): boolean {let found = false;node.descendants((child) => {@@ -276,6 +279,7 @@ function effectiveDirty(node: PmNode, freshnessChecker?: StructuralFreshnessChecreturn freshnessChecker ? freshnessChecker.isDiverged(node.toJSON()) : false;}+function isEmptyMdastParagraph(node: MdastNodes): boolean {if (node.type !== 'paragraph') return false;const children = node.children ?? [];@@ -344,6 +348,7 @@ function extractTextFromMdastNodes(nodes: MdastNodes[]): string {return out;}+import {AUDIO_EXTENSIONS,FILE_ATTACHMENT_EXTENSIONS,@@ -596,6 +601,7 @@ function buildMdastToPmHandlers(}));}+if (m.emphasis) {handlers.emphasis = toPmMark(m.emphasis, (node: Emphasis) => ({sourceDelimiter: node.data?.sourceDelimiter ?? '*',@@ -676,6 +682,7 @@ function buildMdastToPmHandlers(}));}+if (m.link) {const sourceLiteralMark = m.sourceLiteral;handlers.link = (node: Link, _parent: MdastParent, state: MdastToPmState) => {@@ -973,6 +980,7 @@ function buildMdastToPmHandlers(};}+const blockUnknownHandler = (node: {type: string;position?: { start: { offset: number }; end: { offset: number } };@@ -1098,6 +1106,7 @@ function buildMdastToPmHandlers(return handlers as RemarkProseMirrorOptions['handlers'];}+function buildPmToMdastHandlers(schema: Schema,freshness: FreshnessCheckerHolder,diff --git a/packages/core/src/markdown/lint/applies-to.ts b/packages/core/src/markdown/lint/applies-to.tsindex fa0be9e86..b79e9aef7 100644--- a/packages/core/src/markdown/lint/applies-to.ts+++ b/packages/core/src/markdown/lint/applies-to.ts@@ -1,3 +1,4 @@+import picomatch from 'picomatch';import { SUPPORTED_DOC_EXTENSIONS } from '../../constants/doc-extensions.ts';diff --git a/packages/core/src/markdown/lint/config-files.ts b/packages/core/src/markdown/lint/config-files.tsindex 312c9c74b..94b34dee1 100644--- a/packages/core/src/markdown/lint/config-files.ts+++ b/packages/core/src/markdown/lint/config-files.ts@@ -1,3 +1,4 @@+const MARKDOWNLINT_JSON_CONFIG_FILES: ReadonlySet<string> = new Set(['.markdownlint.json','.markdownlint.jsonc',diff --git a/packages/core/src/markdown/lint/config-schemas.ts b/packages/core/src/markdown/lint/config-schemas.tsindex 1a81aa524..fbbd309df 100644--- a/packages/core/src/markdown/lint/config-schemas.ts+++ b/packages/core/src/markdown/lint/config-schemas.ts@@ -52,6 +52,7 @@ const fullPluginShape = Object.fromEntries(LINT_PLUGINS.map((plugin) => [plugin.id, plugin.sliceSchema]),) as z.ZodRawShape;+export const LinterConfigSchema = z.object({enabled: z.boolean(),plugins: z.object(fullPluginShape),diff --git a/packages/core/src/markdown/lint/default-config.ts b/packages/core/src/markdown/lint/default-config.tsindex d48eea5e4..a51f2ffb0 100644--- a/packages/core/src/markdown/lint/default-config.ts+++ b/packages/core/src/markdown/lint/default-config.ts@@ -6,6 +6,7 @@ export const DEFAULT_MARKDOWNLINT_CONFIG: Record<string, MarkdownlintRuleSettingMD013: false,};+export function resolveMarkdownlintConfig(rules: Record<string, MarkdownlintRuleSetting> | undefined,): Configuration {diff --git a/packages/core/src/markdown/lint/frontmatter-schema-edit.ts b/packages/core/src/markdown/lint/frontmatter-schema-edit.tsindex ef478e268..9c9542661 100644--- a/packages/core/src/markdown/lint/frontmatter-schema-edit.ts+++ b/packages/core/src/markdown/lint/frontmatter-schema-edit.ts@@ -1,3 +1,4 @@+import { CANONICAL_SCHEMA_DIALECT_URIS, DEFAULT_SCHEMA_DIALECT } from './frontmatter-validate.ts';export interface FrontmatterFieldConstraint {diff --git a/packages/core/src/markdown/lint/frontmatter-validate.ts b/packages/core/src/markdown/lint/frontmatter-validate.tsindex 5f953d667..b0e7833fd 100644--- a/packages/core/src/markdown/lint/frontmatter-validate.ts+++ b/packages/core/src/markdown/lint/frontmatter-validate.ts@@ -1,3 +1,4 @@+import Ajv, { type ValidateFunction } from 'ajv';import Ajv2019 from 'ajv/dist/2019.js';import Ajv2020 from 'ajv/dist/2020.js';diff --git a/packages/core/src/markdown/lint/index.ts b/packages/core/src/markdown/lint/index.tsindex 11b5abdfd..ffd277a90 100644--- a/packages/core/src/markdown/lint/index.ts+++ b/packages/core/src/markdown/lint/index.ts@@ -1,3 +1,4 @@+import { LINT_PLUGINS, type LinterConfig } from './plugins.ts';import type { LintDiagnostic } from './types.ts';diff --git a/packages/core/src/markdown/lint/okf-frontmatter/materialize.ts b/packages/core/src/markdown/lint/okf-frontmatter/materialize.tsindex 7a5af097e..f438f1b16 100644--- a/packages/core/src/markdown/lint/okf-frontmatter/materialize.ts+++ b/packages/core/src/markdown/lint/okf-frontmatter/materialize.ts@@ -1,3 +1,4 @@+import type { OkfRuleId } from '../okf-rule-meta.ts';import { fileNameFor, OKF_SCHEMA_DIR, okfSchemaPathFor } from './paths.ts';import { OKF_FRONTMATTER_REGISTRY } from './registry.ts';diff --git a/packages/core/src/markdown/lint/okf-frontmatter/paths.ts b/packages/core/src/markdown/lint/okf-frontmatter/paths.tsindex 1ee913527..c290b6878 100644--- a/packages/core/src/markdown/lint/okf-frontmatter/paths.ts+++ b/packages/core/src/markdown/lint/okf-frontmatter/paths.ts@@ -1,3 +1,4 @@+import type { OkfRuleId } from '../okf-rule-meta.ts';export const OKF_SCHEMA_DIR = '.ok/okf';diff --git a/packages/core/src/markdown/lint/okf-frontmatter/registry.ts b/packages/core/src/markdown/lint/okf-frontmatter/registry.tsindex f325fbbb4..53ecb619d 100644--- a/packages/core/src/markdown/lint/okf-frontmatter/registry.ts+++ b/packages/core/src/markdown/lint/okf-frontmatter/registry.ts@@ -1,3 +1,4 @@+import { compileAppliesTo } from '../applies-to.ts';import { validateFrontmatterSource } from '../frontmatter-validate.ts';import {diff --git a/packages/core/src/markdown/lint/okf-frontmatter/schemas.ts b/packages/core/src/markdown/lint/okf-frontmatter/schemas.tsindex f1c37671b..89845d3d5 100644--- a/packages/core/src/markdown/lint/okf-frontmatter/schemas.ts+++ b/packages/core/src/markdown/lint/okf-frontmatter/schemas.ts@@ -1,3 +1,4 @@+// file-level form is deliberate: the sibling `biome-ignore` must sit on the line// oxlint-disable unicorn/no-thenablediff --git a/packages/core/src/markdown/lint/okf-project/rules.ts b/packages/core/src/markdown/lint/okf-project/rules.tsindex 6d691ae2b..8b476332e 100644--- a/packages/core/src/markdown/lint/okf-project/rules.ts+++ b/packages/core/src/markdown/lint/okf-project/rules.ts@@ -1,3 +1,4 @@+import { SUPPORTED_DOC_EXTENSIONS } from '../../../constants/doc-extensions.ts';import { isOkfRuleEnabled, type OkfRuleId, type OkfRuleToggles } from '../okf-rule-meta.ts';diff --git a/packages/core/src/markdown/lint/okf-rule-meta.ts b/packages/core/src/markdown/lint/okf-rule-meta.tsindex 4de50d79f..44913a9dc 100644--- a/packages/core/src/markdown/lint/okf-rule-meta.ts+++ b/packages/core/src/markdown/lint/okf-rule-meta.ts@@ -1,3 +1,4 @@+export const OKF_RULE_IDS = ['no-wiki-links','log-shape',diff --git a/packages/core/src/markdown/lint/okf-rules.ts b/packages/core/src/markdown/lint/okf-rules.tsindex 1d5538421..d0999b62e 100644--- a/packages/core/src/markdown/lint/okf-rules.ts+++ b/packages/core/src/markdown/lint/okf-rules.ts@@ -1,3 +1,4 @@+import { isOkfRuleEnabled, type OkfRuleId, type OkfRuleToggles } from './okf-rule-meta.ts';import type { OkfRule } from './okf-runner.ts';import { indexShape } from './rules/index-shape.ts';diff --git a/packages/core/src/markdown/lint/okf-runner.ts b/packages/core/src/markdown/lint/okf-runner.tsindex de130e3f4..fabb08d6e 100644--- a/packages/core/src/markdown/lint/okf-runner.ts+++ b/packages/core/src/markdown/lint/okf-runner.ts@@ -1,3 +1,4 @@+import type { Root } from 'mdast';import remarkFrontmatter from 'remark-frontmatter';import remarkGfm from 'remark-gfm';diff --git a/packages/core/src/markdown/lint/plugins.ts b/packages/core/src/markdown/lint/plugins.tsindex 09c8450ee..0a089990e 100644--- a/packages/core/src/markdown/lint/plugins.ts+++ b/packages/core/src/markdown/lint/plugins.ts@@ -1,3 +1,4 @@+import { z } from 'zod';import { DEFAULT_MARKDOWNLINT_CONFIG, resolveMarkdownlintConfig } from './default-config.ts';import {@@ -23,6 +24,7 @@ import {type OkfSlice,} from './types.ts';+const MarkdownlintRuleSettingSchema = z.union([z.boolean(),z.enum(MARKDOWNLINT_RULE_SEVERITIES),diff --git a/packages/core/src/markdown/lint/rules/index-shape.ts b/packages/core/src/markdown/lint/rules/index-shape.tsindex 59fe9b87d..fcbb1b56c 100644--- a/packages/core/src/markdown/lint/rules/index-shape.ts+++ b/packages/core/src/markdown/lint/rules/index-shape.ts@@ -1,3 +1,4 @@+import type { List, ListItem } from 'mdast';import { EXIT, visit } from 'unist-util-visit';import { defineScopedOkfRule } from '../okf-runner.ts';diff --git a/packages/core/src/markdown/lint/rules/log-shape.ts b/packages/core/src/markdown/lint/rules/log-shape.tsindex e0159519f..431e4e9c8 100644--- a/packages/core/src/markdown/lint/rules/log-shape.ts+++ b/packages/core/src/markdown/lint/rules/log-shape.ts@@ -1,3 +1,4 @@+import type { Heading } from 'mdast';import { toString as headingText } from 'mdast-util-to-string';import { visit } from 'unist-util-visit';diff --git a/packages/core/src/markdown/lint/rules/no-wiki-links.ts b/packages/core/src/markdown/lint/rules/no-wiki-links.tsindex 2123e977f..f75a04d15 100644--- a/packages/core/src/markdown/lint/rules/no-wiki-links.ts+++ b/packages/core/src/markdown/lint/rules/no-wiki-links.ts@@ -1,3 +1,4 @@+import type { Point } from 'unist';import { visit } from 'unist-util-visit';import { defineOkfRule } from '../okf-runner.ts';diff --git a/packages/core/src/markdown/lint/rules/reserved-casing.ts b/packages/core/src/markdown/lint/rules/reserved-casing.tsindex 89ef3e4a9..c8b4d8f28 100644--- a/packages/core/src/markdown/lint/rules/reserved-casing.ts+++ b/packages/core/src/markdown/lint/rules/reserved-casing.ts@@ -1,3 +1,4 @@+import { SUPPORTED_DOC_EXTENSIONS } from '../../../constants/doc-extensions.ts';import { defineOkfRule } from '../okf-runner.ts';diff --git a/packages/core/src/markdown/lint/types.ts b/packages/core/src/markdown/lint/types.tsindex 6836b962d..c04fa4de0 100644--- a/packages/core/src/markdown/lint/types.ts+++ b/packages/core/src/markdown/lint/types.ts@@ -1,3 +1,4 @@+import type { BrokenLinkReason } from '../../schemas/api/agent-write.ts';import type { OkfRuleId } from './okf-rule-meta.ts';@@ -112,6 +113,7 @@ export interface OkfSlice {generate?: { index?: boolean };}+interface RuleOptionSpecBase {key: string;description: string;diff --git a/packages/core/src/markdown/lint/validation-counts.ts b/packages/core/src/markdown/lint/validation-counts.tsindex 98238656e..437cc539a 100644--- a/packages/core/src/markdown/lint/validation-counts.ts+++ b/packages/core/src/markdown/lint/validation-counts.ts@@ -1,3 +1,4 @@+export interface ValidationSourceCounts {errorCount: number;warningCount: number;diff --git a/packages/core/src/markdown/math-promoter.ts b/packages/core/src/markdown/math-promoter.tsindex a5b511f25..bd79424c7 100644--- a/packages/core/src/markdown/math-promoter.ts+++ b/packages/core/src/markdown/math-promoter.ts@@ -1,3 +1,4 @@+import type { Code, Root } from 'mdast';import type { Math as MdastMath } from 'mdast-util-math';import type { MdxJsxAttribute, MdxJsxFlowElement } from 'mdast-util-mdx';diff --git a/packages/core/src/markdown/mdast-to-hast-handlers.ts b/packages/core/src/markdown/mdast-to-hast-handlers.tsindex ed89371d0..00fbc0035 100644--- a/packages/core/src/markdown/mdast-to-hast-handlers.ts+++ b/packages/core/src/markdown/mdast-to-hast-handlers.ts@@ -1,3 +1,4 @@+import type { Comment, Element, ElementContent, Properties } from 'hast';import type { FootnoteDefinition, FootnoteReference } from 'mdast';import type { MdxJsxFlowElement, MdxJsxTextElement } from 'mdast-util-mdx';diff --git a/packages/core/src/markdown/mdast-to-html.ts b/packages/core/src/markdown/mdast-to-html.tsindex 8ce2b2492..df788a80d 100644--- a/packages/core/src/markdown/mdast-to-html.ts+++ b/packages/core/src/markdown/mdast-to-html.ts@@ -1,3 +1,4 @@+import type { Element, Root as HastRoot, Text as HastText } from 'hast';import type { Root as MdastRoot, Text as MdastText } from 'mdast';import type { Handler } from 'mdast-util-to-hast';diff --git a/packages/core/src/markdown/merged-walker.ts b/packages/core/src/markdown/merged-walker.tsindex bfd7e3109..fa3cfcd86 100644--- a/packages/core/src/markdown/merged-walker.ts+++ b/packages/core/src/markdown/merged-walker.ts@@ -1,3 +1,4 @@+import type { Nodes, Parent, Root } from 'mdast';import { SKIP, visit } from 'unist-util-visit';import type { VFile } from 'vfile';diff --git a/packages/core/src/markdown/mermaid-promoter.ts b/packages/core/src/markdown/mermaid-promoter.tsindex 1a897fca8..17ed2b829 100644--- a/packages/core/src/markdown/mermaid-promoter.ts+++ b/packages/core/src/markdown/mermaid-promoter.ts@@ -1,3 +1,4 @@+import type { Code, Root } from 'mdast';import type { MdxJsxAttribute, MdxJsxFlowElement } from 'mdast-util-mdx';import { visit } from 'unist-util-visit';diff --git a/packages/core/src/markdown/parse-with-fallback.ts b/packages/core/src/markdown/parse-with-fallback.tsindex d988f4b8b..4aa0490c4 100644--- a/packages/core/src/markdown/parse-with-fallback.ts+++ b/packages/core/src/markdown/parse-with-fallback.ts@@ -168,6 +168,7 @@ export function parseRecursive(}}+interface VFilePlace {offset?: number;start?: { offset?: number };@@ -186,6 +187,7 @@ function extractErrorOffset(err: unknown): number | undefined {return undefined;}+interface Region {start: number;end: number;@@ -209,6 +211,7 @@ function nearestBlankLineAfter(src: string, offset: number): number | null {return null;}+export interface TagEvent {kind: 'open' | 'close' | 'self-close';name: string;@@ -355,6 +358,7 @@ function findFallbackRegion(src: string, errorOffset: number): Region {return { start: blockStart, end: blockEnd };}+interface SourceBlock {src: string;start: number;@@ -452,6 +456,7 @@ function tryPerBlockFallback(};}+function wholeDocRawText(source: string): JSONContent {return {type: 'doc',diff --git a/packages/core/src/markdown/parser-drop-closure.ts b/packages/core/src/markdown/parser-drop-closure.tsindex e6ab4fd57..43d420187 100644--- a/packages/core/src/markdown/parser-drop-closure.ts+++ b/packages/core/src/markdown/parser-drop-closure.ts@@ -1,3 +1,4 @@+export type DroppedTokenAdjudication =| {kind: 'format-dof-axis';diff --git a/packages/core/src/markdown/pipeline.ts b/packages/core/src/markdown/pipeline.tsindex 0e3224206..55736041c 100644--- a/packages/core/src/markdown/pipeline.ts+++ b/packages/core/src/markdown/pipeline.ts@@ -1,3 +1,4 @@+import {type FromProseMirrorOptions,fromProseMirror,diff --git a/packages/core/src/markdown/position-aware-join.ts b/packages/core/src/markdown/position-aware-join.tsindex 91cdf658f..ccf06e94d 100644--- a/packages/core/src/markdown/position-aware-join.ts+++ b/packages/core/src/markdown/position-aware-join.ts@@ -1,3 +1,4 @@+import type { Join } from 'mdast-util-to-markdown';import type { Position } from 'unist';import { isBlankLineParagraph } from './zero-emission-blocks.ts';diff --git a/packages/core/src/markdown/position-slice.ts b/packages/core/src/markdown/position-slice.tsindex 0f399d34c..e5b4c9eba 100644--- a/packages/core/src/markdown/position-slice.ts+++ b/packages/core/src/markdown/position-slice.ts@@ -1,3 +1,4 @@+import type { Nodes, Root } from 'mdast';import { visit } from 'unist-util-visit';import type { VFile } from 'vfile';@@ -476,7 +477,8 @@ export function applyPositionSliceToNode(const first = source[startOff];if (first !== '[' && first !== '<' && !node.title) {node.data.sourceStyle = 'gfm-autolink';- } else if (first === '[') {+ }+ else if (first === '[') {const slice = source.slice(startOff, endOff);const closeBracketIdx = slice.lastIndexOf('](');if (closeBracketIdx !== -1) {diff --git a/packages/core/src/markdown/rehype-plugins/skip-notion-whitespace.ts b/packages/core/src/markdown/rehype-plugins/skip-notion-whitespace.tsindex db10fa54b..ca225ce9b 100644--- a/packages/core/src/markdown/rehype-plugins/skip-notion-whitespace.ts+++ b/packages/core/src/markdown/rehype-plugins/skip-notion-whitespace.ts@@ -1,3 +1,4 @@+import type { Comment, Element, Root, Text } from 'hast';import type { Plugin } from 'unified';diff --git a/packages/core/src/markdown/rehype-plugins/strip-cocoa-meta.ts b/packages/core/src/markdown/rehype-plugins/strip-cocoa-meta.tsindex 34068d103..3a2524a9a 100644--- a/packages/core/src/markdown/rehype-plugins/strip-cocoa-meta.ts+++ b/packages/core/src/markdown/rehype-plugins/strip-cocoa-meta.ts@@ -1,3 +1,4 @@+import type { Element, ElementContent, Root } from 'hast';import type { Plugin } from 'unified';diff --git a/packages/core/src/markdown/rehype-plugins/strip-gdocs-wrapper.ts b/packages/core/src/markdown/rehype-plugins/strip-gdocs-wrapper.tsindex 93151d43b..2279a0189 100644--- a/packages/core/src/markdown/rehype-plugins/strip-gdocs-wrapper.ts+++ b/packages/core/src/markdown/rehype-plugins/strip-gdocs-wrapper.ts@@ -1,3 +1,4 @@+import type { Element, Root } from 'hast';import type { Plugin } from 'unified';diff --git a/packages/core/src/markdown/rehype-plugins/strip-github-hovercard.ts b/packages/core/src/markdown/rehype-plugins/strip-github-hovercard.tsindex 188f02d83..a0f467c42 100644--- a/packages/core/src/markdown/rehype-plugins/strip-github-hovercard.ts+++ b/packages/core/src/markdown/rehype-plugins/strip-github-hovercard.ts@@ -1,3 +1,4 @@+import type { Element, Root } from 'hast';import type { Plugin } from 'unified';diff --git a/packages/core/src/markdown/rehype-plugins/strip-gmail-classes.ts b/packages/core/src/markdown/rehype-plugins/strip-gmail-classes.tsindex 4ba2c3418..4e8542a21 100644--- a/packages/core/src/markdown/rehype-plugins/strip-gmail-classes.ts+++ b/packages/core/src/markdown/rehype-plugins/strip-gmail-classes.ts@@ -1,3 +1,4 @@+import type { Element, Root } from 'hast';import type { Plugin } from 'unified';diff --git a/packages/core/src/markdown/rehype-plugins/strip-gsheets-wrapper.ts b/packages/core/src/markdown/rehype-plugins/strip-gsheets-wrapper.tsindex 1a74b1272..a3c96b24a 100644--- a/packages/core/src/markdown/rehype-plugins/strip-gsheets-wrapper.ts+++ b/packages/core/src/markdown/rehype-plugins/strip-gsheets-wrapper.ts@@ -1,3 +1,4 @@+import type { Element, ElementContent, Root } from 'hast';import type { Plugin } from 'unified';diff --git a/packages/core/src/markdown/rehype-plugins/strip-mso-styles.ts b/packages/core/src/markdown/rehype-plugins/strip-mso-styles.tsindex de35e7b79..e95cf43d6 100644--- a/packages/core/src/markdown/rehype-plugins/strip-mso-styles.ts+++ b/packages/core/src/markdown/rehype-plugins/strip-mso-styles.ts@@ -1,3 +1,4 @@+import type { Comment, Element, ElementContent, Root } from 'hast';import type { Plugin } from 'unified';diff --git a/packages/core/src/markdown/rehype-plugins/strip-slack-classes.ts b/packages/core/src/markdown/rehype-plugins/strip-slack-classes.tsindex b4be1b2ea..ffdb4d5b5 100644--- a/packages/core/src/markdown/rehype-plugins/strip-slack-classes.ts+++ b/packages/core/src/markdown/rehype-plugins/strip-slack-classes.ts@@ -1,3 +1,4 @@+import type { Element, ElementContent, Root } from 'hast';import type { Plugin } from 'unified';diff --git a/packages/core/src/markdown/rehype-plugins/strip-vscode-spans.ts b/packages/core/src/markdown/rehype-plugins/strip-vscode-spans.tsindex 3c8d88b7c..e2a96d1a7 100644--- a/packages/core/src/markdown/rehype-plugins/strip-vscode-spans.ts+++ b/packages/core/src/markdown/rehype-plugins/strip-vscode-spans.ts@@ -1,3 +1,4 @@+import type { Element, Root } from 'hast';import type { Plugin } from 'unified';diff --git a/packages/core/src/markdown/resolve-image-url.ts b/packages/core/src/markdown/resolve-image-url.tsindex cf2c9da8e..0389575ac 100644--- a/packages/core/src/markdown/resolve-image-url.ts+++ b/packages/core/src/markdown/resolve-image-url.ts@@ -1,3 +1,4 @@+import { isRelativeUrl } from './safe-url.ts';function isDevDiagnosticContext(): boolean {diff --git a/packages/core/src/markdown/safe-url.ts b/packages/core/src/markdown/safe-url.tsindex 4d3250d3a..8be632ba4 100644--- a/packages/core/src/markdown/safe-url.ts+++ b/packages/core/src/markdown/safe-url.ts@@ -1,3 +1,4 @@+export const SAFE_URL_SCHEMES = ['https', 'http', 'mailto', 'tel', 'ftp', 'sms'] as const;const SCHEME_ALT = SAFE_URL_SCHEMES.map((s) => `${s}:`).join('|');diff --git a/packages/core/src/markdown/serialize-fidelity.test-helper.ts b/packages/core/src/markdown/serialize-fidelity.test-helper.tsindex 0dd54070e..96304e7a5 100644--- a/packages/core/src/markdown/serialize-fidelity.test-helper.ts+++ b/packages/core/src/markdown/serialize-fidelity.test-helper.ts@@ -1,3 +1,4 @@+import type { JSONContent } from '@tiptap/core';import type { Nodes } from 'mdast';import { expect } from 'vitest';diff --git a/packages/core/src/markdown/serialize-helpers.ts b/packages/core/src/markdown/serialize-helpers.tsindex 7cac5b042..93798cf83 100644--- a/packages/core/src/markdown/serialize-helpers.ts+++ b/packages/core/src/markdown/serialize-helpers.ts@@ -1,3 +1,4 @@+import type { Node as PmNode } from '@tiptap/pm/model';import type {MdxJsxAttribute,diff --git a/packages/core/src/markdown/single-dollar-math-promoter.ts b/packages/core/src/markdown/single-dollar-math-promoter.tsindex b012a5aff..8c08b7a04 100644--- a/packages/core/src/markdown/single-dollar-math-promoter.ts+++ b/packages/core/src/markdown/single-dollar-math-promoter.ts@@ -1,3 +1,4 @@+import type { PhrasingContent, Root, Text } from 'mdast';import type { InlineMath } from 'mdast-util-math';import { SKIP, visit } from 'unist-util-visit';diff --git a/packages/core/src/markdown/to-markdown-handlers.ts b/packages/core/src/markdown/to-markdown-handlers.tsindex b50bea5ec..83d4af672 100644--- a/packages/core/src/markdown/to-markdown-handlers.ts+++ b/packages/core/src/markdown/to-markdown-handlers.ts@@ -1,3 +1,4 @@+import type { Nodes, Parents } from 'mdast';import type { MdxJsxAttribute, MdxJsxExpressionAttribute, MdxJsxFlowElement } from 'mdast-util-mdx';import type { Handle, Info, State } from 'mdast-util-to-markdown';diff --git a/packages/core/src/markdown/underline-promoter.ts b/packages/core/src/markdown/underline-promoter.tsindex 0f1b0f27d..6e6d73400 100644--- a/packages/core/src/markdown/underline-promoter.ts+++ b/packages/core/src/markdown/underline-promoter.ts@@ -1,3 +1,4 @@+import type { Nodes, Parent, Root } from 'mdast';import type { MdxJsxTextElement } from 'mdast-util-mdx';import { visit } from 'unist-util-visit';diff --git a/packages/core/src/markdown/unknown-mdast-guard.ts b/packages/core/src/markdown/unknown-mdast-guard.tsindex 1a082bda7..932d7d2a8 100644--- a/packages/core/src/markdown/unknown-mdast-guard.ts+++ b/packages/core/src/markdown/unknown-mdast-guard.ts@@ -1,3 +1,4 @@+import type { Root as MdastRoot } from 'mdast';import type { VFile } from 'vfile';diff --git a/packages/core/src/markdown/whitespace-char-ref.ts b/packages/core/src/markdown/whitespace-char-ref.tsindex d578476a7..ac9f5239b 100644--- a/packages/core/src/markdown/whitespace-char-ref.ts+++ b/packages/core/src/markdown/whitespace-char-ref.ts@@ -1,3 +1,4 @@+const INLINE_WHITESPACE_BY_CODE: ReadonlyMap<number, string> = new Map([[0x20, ' '],[0x09, '\t'],diff --git a/packages/core/src/markdown/wiki-link-micromark.ts b/packages/core/src/markdown/wiki-link-micromark.tsindex 6dad26200..afd9936fe 100644--- a/packages/core/src/markdown/wiki-link-micromark.ts+++ b/packages/core/src/markdown/wiki-link-micromark.ts@@ -17,6 +17,7 @@ declare module 'micromark-util-types' {}}+const CODE_BANG = 33; // !const CODE_LBRACKET = 91; // [const CODE_RBRACKET = 93; // ]@@ -260,6 +261,7 @@ export function wikiLinkSyntax(): Extension {};}+function enterWikiLink(this: CompileContext, token: Token) {this.enter({@@ -385,6 +387,7 @@ export const wikiLinkToMarkdown: {unsafe: [{ character: '[', inConstruct: ['phrasing'] }],};+const MICROMARK_EXT = wikiLinkSyntax();export function remarkWikiLink(this: Processor) {diff --git a/packages/desktop/src/main/auto-updater.ts b/packages/desktop/src/main/auto-updater.tsindex 142e2d665..219983dc0 100644--- a/packages/desktop/src/main/auto-updater.ts+++ b/packages/desktop/src/main/auto-updater.ts@@ -145,6 +145,7 @@ export type DispatchKind =| 'stale-pending-cleared'| 'attempted-install-reconciled'| 'install-in-flight-deferred'+ | 'install-never-committed-reoffered'| 'install-failed-on-boot'| 'install-failed-giveup'| 'attempted-install-cross-channel'@@ -384,9 +385,9 @@ export interface StartAutoUpdaterHandle {* failed". Wired to `app.on('before-quit')`: with install-on-quit armed an* ordinary quit IS the commit point, and it is the last moment a live process* can observe it — the swap runs after the exit, in a process no later boot- * can see. Without this the boot would have only the staging moment to reason- * from, so a background download followed by an afternoon of work would leave- * the whole tolerance already spent by the time the user actually quit.+ * can see. The stamp is also what separates "this install began" from "no+ * install ever began": without it the boot cannot time the attempt at all and+ * re-offers the staged update instead of judging it.** Stamps once per armed attempt. A quit that re-hands off an attempt an* earlier quit already handed off buys no fresh tolerance: otherwise a user@@ -496,11 +497,12 @@ export const INSTALL_FAILURE_MAX_SURFACES = 3;* evidence needed to move it.** The window is measured from the handoff both install paths record — the- * "Relaunch now" click, or the quit install-on-quit commits on. It shrinks only- * when no live process got to observe the commit (a force-quit, a power loss),- * where the staging moment is the sole lower bound left and the effective- * tolerance is this minus however long the artifact sat staged. `recordedHandoff`- * on the boot logs says which of the two a given verdict used.+ * "Relaunch now" click, or the quit install-on-quit commits on. The boot+ * reconciliation reaches this window only with a stamp on record: an attempt+ * with none never began, so it is re-offered rather than timed. The staging+ * fallback in `installMayStillBeRunning` therefore matters only to that+ * function's other caller, crash detection, which asks before the+ * reconciliation has run.*/const INSTALL_IN_FLIGHT_GRACE_MS = 30 * 60 * 1000;@@ -2234,9 +2236,11 @@ export function startAutoUpdater(opts: StartAutoUpdaterOpts): StartAutoUpdaterHa// can clear it. That reconciliation compares major.minor.patch only, so a// same-MMP beta bump — the dominant OK update shape — reads as "caught up"// and drops the stamp, while the prerelease-aware failed-install verdict- // right after still sees an install that never landed. Only the fallback- // needs it: a recorded handoff lives in the `attemptedInstall` group, which- // this reconciliation does not touch.+ // right after still sees an install that never landed. Only the re-offer log+ // line needs it now — it reports how long the artifact has sat staged — so+ // this is log fidelity rather than verdict soundness: a recorded handoff+ // lives in the `attemptedInstall` group, which this reconciliation does not+ // touch.const attemptStagedAt = state.versionPendingInstallStagedAt;// Boot-time stale-pending reconciliation. `versionPendingInstall` is cleared@@ -2359,19 +2363,23 @@ export function startAutoUpdater(opts: StartAutoUpdaterOpts): StartAutoUpdaterHa// Running did NOT reach the attempted version — which is equally the// expected state while the install for it is still underway, so the two// have to be separated before either failure verdict below is reachable.- // The recorded handoff, or — when no live process saw the commit (a- // force-quit, a power loss, a state file predating the stamp) — the- // staging moment. The install cannot have begun before the artifact- // existed, so staging is a sound lower bound on the handoff, just not a- // tight one, and it degrades further once the reconciliation clears it.+ //+ // The chain asks two questions in this order, and the order is+ // load-bearing. FIRST, could an install still be running? While it could,+ // decide nothing. Only once it provably cannot: was one ever handed off+ // at all? A no there is not a failure, so it is re-offered rather than+ // condemned.const reconciledAtMs = now().getTime();+ // Two reads, because those two questions want different things. The+ // RESOLVED moment (stamp, else the staging snapshot) bounds "may still be+ // running", and comes from the same helper `installMayStillBeRunning`+ // uses so the two cannot disagree about it. The RAW stamp answers "was+ // one ever handed off", which the fallback would erase — an unobserved+ // quit has no stamp yet still gets a bound, which is the whole point of+ // the fallback and the whole reason the raw read has to survive it.+ const handoffStampedAt = state.attemptedInstallHandoffAt;const handoffAt = resolveInstallHandoffMoment(state, attemptStagedAt);const handoffAgeMs = installHandoffAgeMs(handoffAt, reconciledAtMs);- // The predicate itself lives in `installMayStillBeRunning` so crash- // detection can ask the same question with the same bound; the locals- // above stay for the log lines, which report the inputs the verdict was- // reached from rather than the verdict alone. Both resolve the moment- // through the same helper, so they cannot come to disagree about it.if (installMayStillBeRunning(state, reconciledAtMs, attemptStagedAt) !== null) {// Inside the install window, and the hold has boots left: decide// nothing about the attempt. `attemptedInstall` stays armed so a later@@ -2414,8 +2422,11 @@ export function startAutoUpdater(opts: StartAutoUpdaterOpts): StartAutoUpdaterHa// artifact had sat staged when it was committed. A deferred boot is// silent to the user, so this line is the only record of a held// verdict — carrying the inputs is what lets an operator reading a- // "my update never installed" report tell a verdict held correctly- // from one held off a fallback moment rather than a real handoff.+ // "my update never installed" report see which handoff moment the+ // hold was measured from. This arm runs BEFORE the never-committed+ // check, so it is the one place the staging fallback is still live and+ // `recordedHandoff` still varies — a hold leaning on the staging+ // moment reads `false` here.handoffAt,recordedHandoff: state.attemptedInstallHandoffAt !== null,stagingAgeMs: state.attemptedInstallStagingAgeMs,@@ -2426,6 +2437,101 @@ export function startAutoUpdater(opts: StartAutoUpdaterOpts): StartAutoUpdaterHadeferredBoots: state.attemptedInstallDeferredBoots,});onDispatch?.('install-in-flight-deferred');+ } else if (handoffStampedAt === null) {+ // No commit point ever ran for this attempt, so no install was ever+ // STARTED — a different fact from "an install began and we lost track+ // of when it did". Both commit points persist the handoff stamp BEFORE+ // handing the artifact to an installer: `relaunch-now` writes it and+ // returns early if that write fails, and `recordInstallHandoffOnQuit`+ // runs from `before-quit`, ahead of the swap. A null stamp is therefore+ // evidence that nothing was handed off, not a gap in the record.+ //+ // The shape that produces it in the field is win32: Windows ends the+ // session with `WM_ENDSESSION` and terminates the process without+ // running `will-quit`, so install-on-quit never fires. A user who shuts+ // the machine down rather than quitting the app hits it every time —+ // and, being the delivery vehicle for its own fixes, the app can never+ // repair that from a later release.+ //+ // Reasoning about install duration here would condemn (or excuse) an+ // install that does not exist, and charging it against+ // INSTALL_FAILURE_MAX_SURFACES is worse than a wrong message: three OS+ // shutdowns spend the budget, the give-up branch drops the record, and+ // the user is left with no offer at all while the artifact is still+ // staged on disk. So decline to judge, and put the update that IS still+ // staged back on offer through the ordinary consented path.+ //+ // Three shapes reach here with a stamp that is null for a reason other+ // than "the session never committed": a `state.json` written by a build+ // predating the stamp; a quit whose stamp write failed, which+ // `recordInstallHandoffOnQuit` logs before letting the quit proceed,+ // since it cannot decline a quit the way `relaunch-now` declines a+ // click; and electron-updater re-arming `update-downloaded` from its+ // on-disk cache, which clears the stamp under a live install.+ //+ // That third one is why this arm sits AFTER the in-flight deferral+ // rather than ahead of it: re-offering into an install that is still+ // running would hand the user a relaunch that aborts the swap already+ // underway. Past the grace none of them can still be installing, so the+ // cost collapses — if the install landed, the next boot reconciles it as+ // success; if it did not, the user is offered the relaunch instead of+ // being told the install failed, which is the same remedy behind a+ // truer message.+ const next = {+ ...state,+ // `attemptedInstall` stays ARMED. On non-Linux `relaunch-now` does not+ // arm it — only the `platform === 'linux'` spread does — so it is the+ // download-time arming that the post-click failure path depends on.+ // Withdrawing it here would disarm failed-install detection for the+ // very click this branch exists to offer: an install that then did not+ // land would find both gates null on the next boot, surfacing no+ // notice and no manual-download URL, and the staged-cache reclaim+ // would delete the artifact underneath it. Leaving it armed also costs+ // nothing, because the null-stamp test above runs every boot: the+ // re-offer simply repeats, and the budget stays unspent.+ //+ // The artifact is still staged, so re-arm the banner gate the ordinary+ // download path would have left armed. `stagedInstallerPath` is+ // deliberately untouched — it is what makes the offer actionable.+ versionPendingInstall: attempted,+ };+ if (persistSafely(next, 'install-never-committed-reoffered')) {+ state = next;+ logger.info('no commit point ran for the staged install — re-offering it', {+ attempted,+ running: currentVersion,+ // How long the artifact has been sitting staged and un-installed.+ // A large value across boots is the stranding signature: sessions+ // keep ending in a way that never commits, and the sole trace of it+ // is this line.+ stagedAgeMs: installHandoffAgeMs(attemptStagedAt, reconciledAtMs),+ });+ // Deferred for the same reason as Toast A/B/C: `startAutoUpdater` runs+ // from `app.whenReady()`, before the first renderer has attached its+ // update listeners, so a synchronous broadcast would be dropped.+ const fireReoffer = (): void => {+ broadcastToAllWindows('ok:update:downloaded', { version: attempted });+ };+ if (whenRendererReady) whenRendererReady(fireReoffer);+ else fireReoffer();+ onDispatch?.('install-never-committed-reoffered');+ } else {+ // Write failed — leave `attemptedInstall` armed so the next boot+ // re-decides rather than silently losing the record. Version-identified+ // so a record persisting across boots is traceable, matching the+ // sibling branches.+ logger.warn('failed to persist install-never-committed-reoffered', {+ attempted,+ running: currentVersion,+ });+ }+ // Past here a handoff IS on record, so an install really was handed to+ // an installer and the only open question is its age.+ //+ // The predicate itself lives in `installMayStillBeRunning` so crash+ // detection can ask the same question with the same bound; the locals+ // above stay for the log lines, which report the inputs the verdict was+ // reached from rather than the verdict alone.} else if (state.attemptedInstallSurfacedCount >= INSTALL_FAILURE_MAX_SURFACES) {// Budget spent — drop `attemptedInstall` so a persistently-failing// ShipIt or an unreachable attempted version (a yanked release, a@@ -2481,16 +2587,17 @@ export function startAutoUpdater(opts: StartAutoUpdaterOpts): StartAutoUpdaterHaattempted,running: currentVersion,surfaced: next.attemptedInstallSurfacedCount,- // Null when no live process saw the install committed — a quit that- // never ran its handlers — and a zero would read as an instant+ // Null when the commit that stamped the handoff left no staging age+ // behind — the clock moved backwards between staging and the+ // commit, or a boot's stale-pending reconciliation had already+ // dropped the staging stamp. A zero would read as an instant// install, so unknown is reported as unknown.stagingAgeMs: state.attemptedInstallStagingAgeMs,- // Pairs with the age below so the two `handoffAgeMs === null`- // causes are distinguishable from the line alone: absent here means- // no handoff moment survived at all, present with a null age means- // the clock moved backwards between the handoff and this boot.+ // Always present: the reconciliation reaches this line only with a+ // stamp on record. A null `handoffAgeMs` beside it therefore means+ // exactly one thing — the clock moved backwards between the handoff+ // and this boot.handoffAt,- recordedHandoff: state.attemptedInstallHandoffAt !== null,// How long ago the install was handed off, which the staging age// cannot say: it measures staged-to-request, not request-to-now.// Null means the timing on record could not be reasoned from, and@@ -2772,11 +2879,12 @@ export function startAutoUpdater(opts: StartAutoUpdaterOpts): StartAutoUpdaterHastagingAgeMs,});} else {- // The next boot will read `recordedHandoff: false` and fall back to the- // staging moment, which can age out faster than the real handoff — so- // the lost write is worth a version-identified trace of its own beyond- // persistSafely's generic error.- logger.warn('failed to persist install handoff moment — next boot uses staging fallback', {+ // This quit installs anyway — the write failing is no reason to decline+ // it — so the next boot sees an install that really was handed off+ // carrying no stamp, and re-offers the update rather than judging the+ // attempt. That is the benign direction, but it is a false negative for+ // failed-install detection and the only trace of it is this line.+ logger.warn('failed to persist install handoff moment — next boot will re-offer', {attempted: current.attemptedInstall,handoffAt,stagingAgeMs,diff --git a/packages/desktop/src/main/state-store.ts b/packages/desktop/src/main/state-store.tsindex d552da1e2..4e8baac27 100644Binary files a/packages/desktop/src/main/state-store.ts and b/packages/desktop/src/main/state-store.ts differdiff --git a/packages/desktop/tests/integration/auto-updater.test.ts b/packages/desktop/tests/integration/auto-updater.test.tsindex e4da2f9e3..829dd278d 100644--- a/packages/desktop/tests/integration/auto-updater.test.ts+++ b/packages/desktop/tests/integration/auto-updater.test.ts@@ -346,6 +346,19 @@ function makeRig(// Constants used across tests// ————————————————————————————————————————————————————————+/**+ * A handoff stamped far outside the in-flight grace, for fixtures that mean "an+ * install was really committed and really failed".+ *+ * `attemptedInstall` alone no longer says that. It is armed at DOWNLOAD time on+ * non-Linux, so on its own it means only "an artifact is staged" — and a boot+ * that finds it armed with NO handoff stamp now reads that as "no commit point+ * ever ran", re-offers the update, and never reaches a failure verdict. Fixtures+ * predating the handoff stamp were written when the two facts were one, so they+ * need this to keep exercising the branch their assertions describe.+ */+const COMMITTED_LONG_AGO = new Date('2020-01-01T00:00:00.000Z').getTime();+const CLASSIFIED_CODES: readonly string[] = ['ERR_UPDATER_CHANNEL_FILE_NOT_FOUND','ERR_UPDATER_LATEST_VERSION_NOT_FOUND',@@ -759,6 +772,7 @@ describe('staging age — how long the update sat before the install was requesttest('the boot-time failure notice reports the age persisted before the quit', () => {const { rig } = makeRig({attemptedInstall: '0.16.0-beta.3',+ attemptedInstallHandoffAt: COMMITTED_LONG_AGO,appVersion: '0.16.0-beta.1',attemptedInstallStagingAgeMs: 2060,});@@ -774,6 +788,7 @@ describe('staging age — how long the update sat before the install was requesttest('reports null rather than zero when no relaunch click preceded the failure', () => {const { rig } = makeRig({attemptedInstall: '0.16.0-beta.3',+ attemptedInstallHandoffAt: COMMITTED_LONG_AGO,appVersion: '0.16.0-beta.1',});expect(rig.logger.warn).toHaveBeenCalledWith(@@ -787,7 +802,7 @@ describe('staging age — how long the update sat before the install was request// click must not travel with it — a stale non-null number reads as real// signal to a triager and is worse than the age simply being absent.test('a newly armed version does not inherit an earlier version staging age', async () => {- const { rig: session } = makeRig({ platform: 'darwin' });+ const { rig: session, handle } = makeRig({ platform: 'darwin' });session.now = new Date('2026-04-21T12:00:00.000Z');session.updater.emit('update-downloaded', { version: '0.3.2' });session.now = new Date('2026-04-21T12:00:02.060Z');@@ -795,9 +810,12 @@ describe('staging age — how long the update sat before the install was requestexpect(session.state.attemptedInstallStagingAgeMs).toBe(2060);// A newer build lands and is committed by a plain quit — no click, so the- // install of 0.3.3 has no request moment of its own.+ // install of 0.3.3 has no request moment of its own. The quit itself is+ // what commits it, and stamping the handoff is what makes the next boot+ // judge the attempt rather than read it as one that never started.session.now = new Date('2026-04-21T13:00:00.000Z');session.updater.emit('update-downloaded', { version: '0.3.3' });+ handle.recordInstallHandoffOnQuit();expect(session.state.attemptedInstall).toBe('0.3.3');// 0.3.3 never took: the next boot is still on the old version.@@ -815,6 +833,7 @@ describe('staging age — how long the update sat before the install was requestconst { rig } = makeRig({appVersion: '0.3.1',attemptedInstall: '0.3.1',+ attemptedInstallHandoffAt: COMMITTED_LONG_AGO,attemptedInstallStagingAgeMs: 2060,});expect(rig.state.attemptedInstall).toBeNull();@@ -1413,16 +1432,17 @@ describe('boot-time stale versionPendingInstall reconciliation', () => {// ————————————————————————————————————————————————————————describe('boot-time failed-install detection', () => {- // Fail-closed case: this fixture carries no staging/handoff timestamps, so- // the boot has no basis for judging whether the install could still be- // running (legacy or corrupt `state.json` — every path that arms- // `attemptedInstall` also stamps `versionPendingInstallStagedAt`). With no- // timing to defer to, the detector still speaks. The complementary case —- // an attempt whose handoff IS on record and is recent enough that the- // install may still be in flight — lives in its own describe block below.- test('attempted not reached, no handoff timing on record (same-MMP beta) → relaunch-failed w/ downloadUrl, re-arm, stays armed', () => {+ // A handoff on record, far enough past the grace that nothing can still be+ // installing, so the detector speaks. The two complementary cases live in+ // their own describe block below: an attempt whose handoff is recent enough+ // that the install may still be in flight, and an attempt with NO handoff on+ // record at all — which no longer reaches this detector, because a stamp that+ // was never written means no install was ever started, and the boot re-offers+ // the staged update instead of judging it.+ test('handoff on record, long past the grace (same-MMP beta) → relaunch-failed w/ downloadUrl, re-arm, stays armed', () => {const { rig } = makeRig({attemptedInstall: '0.16.0-beta.3',+ attemptedInstallHandoffAt: COMMITTED_LONG_AGO,appVersion: '0.16.0-beta.1',});const failed = rig.captured.filter((c) => c.channel === 'ok:update:relaunch-failed');@@ -1449,6 +1469,7 @@ describe('boot-time failed-install detection', () => {...emptyState(),lastSeenVersion: '0.16.0-beta.1',attemptedInstall: '0.16.0-beta.3',+ attemptedInstallHandoffAt: COMMITTED_LONG_AGO,};const boot = () => {const captured: CapturedSend[] = [];@@ -1487,6 +1508,7 @@ describe('boot-time failed-install detection', () => {test('attempted reached (running == attempted) → silently cleared, no failure notice', () => {const { rig } = makeRig({attemptedInstall: '0.16.0-beta.3',+ attemptedInstallHandoffAt: COMMITTED_LONG_AGO,appVersion: '0.16.0-beta.3',attemptedInstallSurfacedCount: 2,});@@ -1502,6 +1524,7 @@ describe('boot-time failed-install detection', () => {test('attempted reached (running past attempted, stable over beta) → silently cleared', () => {const { rig } = makeRig({attemptedInstall: '0.16.0-beta.3',+ attemptedInstallHandoffAt: COMMITTED_LONG_AGO,appVersion: '0.16.0',attemptedInstallSurfacedCount: 2,});@@ -1536,6 +1559,7 @@ describe('boot-time failed-install detection', () => {// branch's own clear of the stale pending marker.const { rig } = makeRig({attemptedInstall: '0.24.0',+ attemptedInstallHandoffAt: COMMITTED_LONG_AGO,versionPendingInstall: '0.24.0',// Seeded so the clearing assertion below has teeth — a branch that// stops nulling it would leave a stale path for the Linux fallback.@@ -1559,6 +1583,7 @@ describe('boot-time failed-install detection', () => {// same-channel failure notice.const { rig } = makeRig({attemptedInstall: '0.23.0-beta.5',+ attemptedInstallHandoffAt: COMMITTED_LONG_AGO,appVersion: '0.22.0',});expect(rig.captured.filter((c) => c.channel === 'ok:update:relaunch-failed')).toHaveLength(0);@@ -1570,6 +1595,7 @@ describe('boot-time failed-install detection', () => {test('same-channel failure below budget → surfaces AND increments the counter', () => {const { rig } = makeRig({attemptedInstall: '0.16.0-beta.3',+ attemptedInstallHandoffAt: COMMITTED_LONG_AGO,appVersion: '0.16.0-beta.1',attemptedInstallSurfacedCount: 1,});@@ -1584,6 +1610,7 @@ describe('boot-time failed-install detection', () => {// so the giveup branch must clear it itself.const { rig } = makeRig({attemptedInstall: '0.17.0-beta.1',+ attemptedInstallHandoffAt: COMMITTED_LONG_AGO,versionPendingInstall: '0.17.0-beta.1',// Seeded so the clearing assertion below has teeth.stagedInstallerPath: '/tmp/staged-giveup.deb',@@ -1607,6 +1634,7 @@ describe('boot-time failed-install detection', () => {...emptyState(),lastSeenVersion: '0.16.0-beta.1',attemptedInstall: '0.16.0-beta.3',+ attemptedInstallHandoffAt: COMMITTED_LONG_AGO,};const boot = () => {const captured: CapturedSend[] = [];@@ -1655,6 +1683,7 @@ describe('boot-time failed-install detection', () => {test('update-downloaded of a NEW version resets the surface counter', () => {const { rig } = makeRig({attemptedInstall: '0.16.0-beta.3',+ attemptedInstallHandoffAt: COMMITTED_LONG_AGO,appVersion: '0.16.0-beta.1',attemptedInstallSurfacedCount: 1,});@@ -1675,6 +1704,7 @@ describe('boot-time failed-install detection', () => {const { rig } = makeRig({isPackaged: false,attemptedInstall: '0.16.0-beta.3',+ attemptedInstallHandoffAt: COMMITTED_LONG_AGO,appVersion: '0.16.0-beta.1',attemptedInstallSurfacedCount: 2,});@@ -1692,6 +1722,7 @@ describe('boot-time failed-install detection', () => {...emptyState(),lastSeenVersion: '0.23.0-beta.1',attemptedInstall: '0.24.0',+ attemptedInstallHandoffAt: COMMITTED_LONG_AGO,};const dispatches: DispatchKind[] = [];startAutoUpdater({@@ -1718,12 +1749,63 @@ describe('boot-time failed-install detection', () => {expect(state.attemptedInstall).toBe('0.24.0');});+ test('persist failure on the never-committed re-offer → no dispatch, no toast, record stays armed', () => {+ // Same guard the sibling branches carry: if a refactor ever moved+ // `state = next` outside the `persistSafely` gate, a failed disk write would+ // leave memory claiming the re-offer while `state.json` still holds the old+ // record — and the next boot would read back the very+ // record-claims-an-install-that-never-happened inconsistency this branch+ // exists to resolve.+ const captured: CapturedSend[] = [];+ const state: AppState = {+ ...emptyState(),+ lastSeenVersion: '0.16.0-beta.1',+ attemptedInstall: '0.16.0-beta.3',+ // The shape of the branch under test: armed, with no handoff ever stamped.+ attemptedInstallHandoffAt: null,+ };+ const warn = vi.fn(() => {});+ const dispatches: DispatchKind[] = [];+ startAutoUpdater({+ updater: new FakeUpdater(),+ ipcMain: makeFakeIpc(),+ readState: () => state,+ writeState: () => {+ throw new Error('EACCES');+ },+ getPrimaryWindow: () => makeFakeWindow(captured),+ getAppVersion: () => '0.16.0-beta.1',+ isPackaged: true,+ clock: makeFakeClock(),+ now: () => new Date(),+ onDispatch: (k) => dispatches.push(k),+ logger: {+ info: vi.fn(() => {}),+ warn,+ error: vi.fn(() => {}),+ debug: vi.fn(() => {}),+ },+ });++ expect(dispatches).not.toContain('install-never-committed-reoffered' as DispatchKind);+ // No toast either: a user offered a relaunch the state cannot back would+ // click into a gate that was never armed.+ expect(captured.filter((c) => c.channel === 'ok:update:downloaded')).toHaveLength(0);+ // The record survives, so the next boot re-decides rather than losing it.+ expect(state.attemptedInstall).toBe('0.16.0-beta.3');+ expect(warn).toHaveBeenCalledWith(+ 'failed to persist install-never-committed-reoffered',+ expect.objectContaining({ attempted: '0.16.0-beta.3', running: '0.16.0-beta.1' }),+ );+ });+test('persist failure on the giveup branch → record stays armed, no dispatch', () => {const captured: CapturedSend[] = [];const state: AppState = {...emptyState(),lastSeenVersion: '0.16.0-beta.1',attemptedInstall: '0.16.0-beta.3',+ attemptedInstallHandoffAt: COMMITTED_LONG_AGO,attemptedInstallSurfacedCount: INSTALL_FAILURE_MAX_SURFACES,};const dispatches: DispatchKind[] = [];@@ -1762,6 +1844,7 @@ describe('boot-time failed-install detection', () => {...emptyState(),lastSeenVersion: '0.16.0-beta.1',attemptedInstall: '0.16.0-beta.3',+ attemptedInstallHandoffAt: COMMITTED_LONG_AGO,};const dispatches: DispatchKind[] = [];startAutoUpdater({@@ -1798,6 +1881,7 @@ describe('boot-time failed-install detection', () => {...emptyState(),lastSeenVersion: '0.16.0-beta.3',attemptedInstall: '0.16.0-beta.3',+ attemptedInstallHandoffAt: COMMITTED_LONG_AGO,};const dispatches: DispatchKind[] = [];startAutoUpdater({@@ -1910,8 +1994,11 @@ describe('boot-time failed-install detection — install still in flight', () =>* The pre-update session: stage the update, then end the session the way that* commits the install — the "Relaunch now" click, or a plain quit that* install-on-quit commits on. `'unobserved-quit'` ends the session without- * either, modelling the commits no live process gets to record: a force-quit,- * a power loss, or a `state.json` written by a build predating the quit stamp.+ * either, which is the session that commits NOTHING: a Windows shutdown (the+ * dominant shape — it terminates the process without `will-quit`, so+ * install-on-quit never fires), a force-quit, or a power loss. It also stands+ * in for the two benign ways a real commit arrives unstamped: a `state.json`+ * from a build predating the quit stamp, and a quit whose stamp write failed.* Returns the `state.json` that boot reads.** `overrides` moves the version pair and the commit moment off the defaults —@@ -1942,6 +2029,10 @@ describe('boot-time failed-install detection — install still in flight', () =>const failureCards = (rig: TestRig): CapturedSend[] =>rig.captured.filter((c) => c.channel === 'ok:update:relaunch-failed');+ /** The ordinary ready-to-install offer — Toast A's channel. */+ const reofferCards = (rig: TestRig): CapturedSend[] =>+ rig.captured.filter((c) => c.channel === 'ok:update:downloaded');+/*** A reopen the user does not stay in: boot, let the launch check re-fire* electron-updater's cached `update-downloaded`, then quit — which commits@@ -2069,37 +2160,179 @@ describe('boot-time failed-install detection — install still in flight', () =>expect(rig.dispatches).toContain('install-failed-on-boot' as DispatchKind);});- test('a commit no live process observed falls back to the staging moment', async () => {- // Nothing recorded the handoff, so the only bound left is that the install- // cannot have begun before the artifact existed. Sound, just not tight: the- // tolerance now runs from the download, so it is whatever remains of the- // window after however long the artifact sat staged.+ test('a session that recorded no handoff is re-offered once nothing can still be installing', async () => {+ // Both commit points persist the handoff stamp BEFORE handing anything to+ // an installer: `relaunch-now` writes it and returns early if that write+ // fails, and `recordInstallHandoffOnQuit` runs from `before-quit`, ahead of+ // the swap. So a null stamp is not "we lost track of when the install+ // began" — it is "no install ever began", which deserves a different answer+ // than a failure verdict.+ //+ // But it is asked SECOND, after the in-flight grace, and the ordering is+ // load-bearing: electron-updater re-arming `update-downloaded` from its+ // on-disk cache clears the stamp, so a null one can coexist with an install+ // genuinely in flight. Re-offering into that would hand the user a relaunch+ // that aborts the swap already running. Once the grace is spent nothing can+ // still be installing, and what the state describes is simply an update+ // sitting staged — so the honest response is the ordinary offer, not a+ // failure notice. The sibling test below pins the deferral that guards this.const rig = reopenAt(await stageAndCommit('unobserved-quit'),- new Date(STAGED_AT.getTime() + 45 * SECOND),+ new Date(STAGED_AT.getTime() + 2 * HOUR),);- expect(rig.state.attemptedInstallHandoffAt).toBeNull();+ expect(rig.dispatches).toContain('install-never-committed-reoffered' as DispatchKind);+ expect(rig.dispatches).not.toContain('install-in-flight-deferred' as DispatchKind);expect(failureCards(rig)).toHaveLength(0);- expect(rig.dispatches).toContain('install-in-flight-deferred' as DispatchKind);+ // The user-visible half: the staged artifact goes back on offer through the+ // ordinary consented path, which means the same toast the download would+ // have raised.+ expect(reofferCards(rig)).toHaveLength(1);+ expect(reofferCards(rig)[0]?.payload).toEqual({ version: ATTEMPTED });+ expect(rig.state.versionPendingInstall).toBe(ATTEMPTED);+ // `attemptedInstall` stays ARMED. On non-Linux the click does not arm it —+ // only the Linux spread does — so this is the record the post-click failure+ // path reads. Withdrawing it would disarm failed-install detection for the+ // very click this branch exists to offer.+ expect(rig.state.attemptedInstall).toBe(ATTEMPTED);expect(rig.state.attemptedInstallSurfacedCount).toBe(0);- // The log says which moment the verdict leaned on, so a field report can be- // read without guessing whether the tolerance was the full window or- // whatever was left of it after the artifact sat staged.- expect(rig.logger.info).toHaveBeenCalledWith(- expect.stringContaining('defer'),- expect.objectContaining({ recordedHandoff: false, handoffAt: STAGED_AT.getTime() }),+ });++ test('a never-committed attempt inside the grace defers rather than re-offering', async () => {+ // The ordering guard. `update-downloaded` re-arming from electron-updater's+ // on-disk cache clears the handoff stamp, so a null stamp can coexist with+ // an install that is genuinely mid-flight. Asking "was one ever handed off"+ // BEFORE "could one still be running" would re-offer into that install, and+ // the relaunch the user then clicked would abort the swap already underway.+ //+ // Nothing else in the suite fails if the two arms are swapped back: the+ // deferral tests still see their dispatch, because the re-offer arm would+ // simply never be reached in their fixtures.+ const rig = reopenAt(+ await stageAndCommit('unobserved-quit'),+ new Date(STAGED_AT.getTime() + 45 * SECOND),);++ expect(rig.dispatches).toContain('install-in-flight-deferred' as DispatchKind);+ expect(rig.dispatches).not.toContain('install-never-committed-reoffered' as DispatchKind);+ // The decisive one: no relaunch is offered while a swap may be running.+ expect(reofferCards(rig)).toHaveLength(0);+ expect(failureCards(rig)).toHaveLength(0);});- test('an unobserved commit long after the staging still fires the notice', async () => {+ test('a session that recorded no handoff never becomes a failure verdict, however long ago', async () => {+ // The win32 shape this exists for: Windows ends the session with+ // `WM_ENDSESSION` and terminates without running `will-quit`, so+ // install-on-quit never fires and nothing is handed off. A user who shuts+ // the machine down rather than quitting the app hits this every time, and+ // age is not what distinguishes it — a day-old never-started install is+ // exactly as un-started as a minute-old one.const rig = reopenAt(await stageAndCommit('unobserved-quit'),new Date(STAGED_AT.getTime() + 24 * HOUR),);- expect(failureCards(rig)).toHaveLength(1);- expect(rig.dispatches).toContain('install-failed-on-boot' as DispatchKind);+ expect(failureCards(rig)).toHaveLength(0);+ expect(rig.dispatches).not.toContain('install-failed-on-boot' as DispatchKind);+ expect(rig.dispatches).toContain('install-never-committed-reoffered' as DispatchKind);+ expect(rig.state.versionPendingInstall).toBe(ATTEMPTED);+ expect(rig.state.attemptedInstallSurfacedCount).toBe(0);+ });++ test('repeated never-committed boots keep re-offering instead of spending the give-up budget', async () => {+ // The stranding mechanism, pinned. Charging a never-started install against+ // `INSTALL_FAILURE_MAX_SURFACES` means that after three OS shutdowns the+ // record is dropped and the user is told nothing at all — while the update+ // is still sitting on disk. Whatever the offer is, it has to survive more+ // boots than the failure budget allows.+ let state = await stageAndCommit('unobserved-quit');+ for (let boot = 1; boot <= 4; boot += 1) {+ const rig = reopenAt(state, new Date(STAGED_AT.getTime() + boot * 24 * HOUR));+ expect(failureCards(rig)).toHaveLength(0);+ expect(rig.dispatches).not.toContain('install-failed-giveup' as DispatchKind);+ expect(reofferCards(rig)).toHaveLength(1);+ expect(rig.state.versionPendingInstall).toBe(ATTEMPTED);+ // No re-arming between boots: each one ends the same way the last did, so+ // the state this boot leaves behind IS the next boot's starting state.+ // That the loop needs no help is the point — the offer repeats on its own.+ state = rig.state;+ }+ });++ test('a re-offer taken and then failing still produces a failure verdict on the next boot', async () => {+ // The hazard in keeping the two records separate: the click is the only+ // thing that turns a re-offer into a real attempt, and on non-Linux it does+ // not arm `attemptedInstall` itself. If the boot that re-offers had+ // withdrawn that record, this sequence would end in silence — no notice, no+ // manual-download URL — and the staged-cache reclaim would delete the+ // artifact the user is still waiting on.+ const reoffered = reopenAt(+ await stageAndCommit('unobserved-quit'),+ new Date(STAGED_AT.getTime() + 24 * HOUR),+ );+ expect(reoffered.dispatches).toContain('install-never-committed-reoffered' as DispatchKind);++ // The user takes the offer. This is the moment the attempt becomes real: the+ // click stamps the handoff, so the next boot judges it rather than+ // re-offering.+ reoffered.now = new Date(STAGED_AT.getTime() + 24 * HOUR + MINUTE);+ await reoffered.ipc.invoke('ok:update:relaunch-now');+ expect(reoffered.state.attemptedInstallHandoffAt).not.toBeNull();++ // ...and the install does not land. A day on, nothing is installing.+ const reclaim = vi.fn();+ const { rig: afterFailedClick } = makeRig({+ ...reoffered.state,+ appVersion: RUNNING,+ platform: 'darwin',+ nowAt: new Date(STAGED_AT.getTime() + 48 * HOUR),+ reclaimStagedUpdateCache: reclaim,+ });++ expect(afterFailedClick.dispatches).toContain('install-failed-on-boot' as DispatchKind);+ expect(failureCards(afterFailedClick)).toHaveLength(1);+ expect(failureCards(afterFailedClick)[0]?.payload).toEqual({+ version: ATTEMPTED,+ downloadUrl: STUCK_HINT_DOWNLOAD_URL,+ });+ // The artifact survives: an install commitment is still armed, so the+ // reclaim must not delete what the Retry needs.+ expect(reclaim).not.toHaveBeenCalled();+ });++ test('the re-arm is what restores an offer the stale-pending reconciliation cleared', async () => {+ // Same-MMP beta: the boot's stale-pending reconciliation nulls+ // `versionPendingInstall` before the attempt is judged, so here the re-arm+ // is doing real work rather than restating what `...state` already carried.+ const rig = reopenAt(+ await stageAndCommit('unobserved-quit', {+ running: '0.16.0-beta.1',+ attempted: '0.16.0-beta.3',+ }),+ new Date(STAGED_AT.getTime() + 24 * HOUR),+ '0.16.0-beta.1',+ );++ expect(rig.dispatches).toContain('stale-pending-cleared' as DispatchKind);+ expect(rig.dispatches).toContain('install-never-committed-reoffered' as DispatchKind);+ expect(rig.state.versionPendingInstall).toBe('0.16.0-beta.3');+ expect(reofferCards(rig)).toHaveLength(1);+ });++ test('a recorded handoff is still judged on its age — the in-flight grace is untouched', async () => {+ // Guard against the fix over-reaching. The discriminator is whether a+ // handoff was recorded, NOT how old it is: a real commit inside the grace+ // still defers, and the same commit a day later still fails.+ const committed = await stageAndCommit('plain-quit');++ const early = reopenAt(committed, new Date(HANDED_OFF_AT.getTime() + 45 * SECOND));+ expect(early.dispatches).toContain('install-in-flight-deferred' as DispatchKind);+ expect(early.dispatches).not.toContain('install-never-committed-reoffered' as DispatchKind);++ const late = reopenAt(committed, new Date(HANDED_OFF_AT.getTime() + 24 * HOUR));+ expect(late.dispatches).toContain('install-failed-on-boot' as DispatchKind);+ expect(late.dispatches).not.toContain('install-never-committed-reoffered' as DispatchKind);+ expect(failureCards(late)).toHaveLength(1);});test('the uninstall quit claims no handoff', async () => {@@ -2445,14 +2678,16 @@ describe('boot-time failed-install detection — install still in flight', () =>expect(rig.state.attemptedInstall).toBe(ATTEMPTED);});- test('a deferred boot records how long ago the install was handed off, and from what', async () => {+ test('a deferred boot records how long ago the install was handed off', async () => {// A deferred boot is silent to the user by design, so this line is the only// place an operator reading a "my update never installed" report can see// that the boot considered the attempt and how long ago the handoff was —// the number that separates a verdict held too eagerly from one held- // correctly. The derived age alone cannot be audited: the two moments it- // came from have to travel with it, or a verdict held off a handoff that was- // never observed is indistinguishable from one held off a real handoff.+ // correctly. The derived age alone cannot be audited: the moment it was+ // measured from has to travel with it.+ //+ // The line no longer says WHICH moment, because there is only one it can be:+ // a boot with no handoff on record never reaches the deferral at all.const rig = reopenAt(await stageAndCommit('relaunch-click'),new Date(HANDED_OFF_AT.getTime() + 62 * SECOND),@@ -2464,7 +2699,6 @@ describe('boot-time failed-install detection — install still in flight', () =>attempted: ATTEMPTED,handoffAgeMs: 62 * SECOND,handoffAt: HANDED_OFF_AT.getTime(),- recordedHandoff: true,stagingAgeMs: HANDED_OFF_AT.getTime() - STAGED_AT.getTime(),}),);@@ -3617,6 +3851,7 @@ describe('dev-mode guard (isPackaged=false)', () => {const { rig } = makeRig({isPackaged: false,attemptedInstall: '0.5.0',+ attemptedInstallHandoffAt: COMMITTED_LONG_AGO,appVersion: '0.4.0',});expect(rig.captured.filter((c) => c.channel === 'ok:update:relaunch-failed')).toHaveLength(0);@@ -3641,6 +3876,7 @@ describe('dev-mode guard (isPackaged=false)', () => {isPackaged: false,forceDevBypass: true,attemptedInstall: '0.5.0',+ attemptedInstallHandoffAt: COMMITTED_LONG_AGO,appVersion: '0.4.0',});const failed = rig.captured.filter((c) => c.channel === 'ok:update:relaunch-failed');@@ -4223,6 +4459,7 @@ describe('staged-cache reclaim — fires only once every install commitment is sappVersion: '0.3.2',versionPendingInstall: '0.3.2',attemptedInstall: '0.3.2',+ attemptedInstallHandoffAt: COMMITTED_LONG_AGO,reclaimStagedUpdateCache: reclaim,});expect(rig.state.versionPendingInstall).toBeNull();@@ -4249,6 +4486,7 @@ describe('staged-cache reclaim — fires only once every install commitment is sconst reclaim = vi.fn(() => Promise.resolve());const { rig } = makeRig({attemptedInstall: '0.9.9',+ attemptedInstallHandoffAt: COMMITTED_LONG_AGO,reclaimStagedUpdateCache: reclaim,});expect(rig.dispatches).toContain('install-failed-on-boot' as DispatchKind);@@ -4259,6 +4497,7 @@ describe('staged-cache reclaim — fires only once every install commitment is sconst reclaim = vi.fn(() => Promise.resolve());const { rig } = makeRig({attemptedInstall: '0.9.9',+ attemptedInstallHandoffAt: COMMITTED_LONG_AGO,attemptedInstallSurfacedCount: INSTALL_FAILURE_MAX_SURFACES,reclaimStagedUpdateCache: reclaim,});