Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

Keep native installation history across a reboot that renumbers the disk (#1370)

0xken15628c30ed76f7
diff --git a/cli/src/engines/kit/nativeInstall.spec.ts b/cli/src/engines/kit/nativeInstall.spec.ts
index dc3de8f07..0dbf292df 100644
--- a/cli/src/engines/kit/nativeInstall.spec.ts
+++ b/cli/src/engines/kit/nativeInstall.spec.ts
@@ -323,6 +323,17 @@ it.each(['missing', 'replaced', 'emptied', 'dispatch removed', 'witness removed'
expect(restarted.dispatch).not.toHaveBeenCalled()
})
+it('keeps its history when a reboot renumbers the disk', async () => {
+ await controller().ensure('opencode', recipe, environment, 'request', () => true)
+ complete()
+ const authority = `${directory}.authority`, saved = JSON.parse(readFileSync(authority, 'utf8'))
+ writeFileSync(authority, JSON.stringify({ ...saved, directory: saved.directory.replace(/^\d+:/, '1:') }))
+ const restarted = controller()
+ expect(await restarted.status('opencode', 'request', () => true)).toEqual({ complete: true })
+ expect(await restarted.ensure('opencode', recipe, environment, 'request', () => true)).toEqual({ complete: true })
+ expect(restarted.dispatch).not.toHaveBeenCalled()
+})
+
it('confirms a readable result durably before crediting it or dispatching its successor', async () => {
await controller().ensure('opencode', recipe, environment, 'request', () => true)
complete()
diff --git a/cli/src/engines/kit/nativeInstall.ts b/cli/src/engines/kit/nativeInstall.ts
index 3278d97e7..46d47530e 100644
--- a/cli/src/engines/kit/nativeInstall.ts
+++ b/cli/src/engines/kit/nativeInstall.ts
@@ -13,7 +13,7 @@ import { LAUNCH_LOCATION_VARIABLES } from './nativeLocations.js'
import { NativeEvidenceBudget } from './nativeEvidence.js'
import { NativeFiles } from './nativeFiles.js'
import { inspectHookFile, runHookPreparation } from './nativeHookFiles.js'
-import { NativePaths, verifyNativePathFacts, type NativePathFact } from './nativePaths.js'
+import { NativePaths, verifyNativePathFacts, withoutDevice, type NativePathFact } from './nativePaths.js'
const LIMIT = 262_144
// This is installation history, not launch history: ordinary launches never add
@@ -92,6 +92,7 @@ const [file,expected,testDeadline]=process.argv.slice(1),directory=path.dirname(
const hash=s=>crypto.createHash('sha256').update(s).digest('hex');
const id=s=>String(s.dev)+':'+String(s.ino)+':'+String(s.mode)+':'+String(s.uid);
const ver=s=>id(s)+':'+String(s.size)+':'+String(s.mtimeNs)+':'+String(s.ctimeNs);
+const nodev=s=>s&&s.slice(s.indexOf(':')+1);
function read(file){const fd=fs.openSync(file,C.O_RDONLY|C.O_NOFOLLOW|C.O_NONBLOCK);try{
const s=fs.fstatSync(fd,{bigint:true});if(!s.isFile()||s.size>262144n||s.uid!==BigInt(process.getuid())||(s.mode&0o022n))throw Error('Unsafe installation record');
const bytes=Buffer.alloc(Number(s.size));let offset=0;for(let calls=0;offset<bytes.length;calls++){
@@ -102,14 +103,14 @@ function read(file){const fd=fs.openSync(file,C.O_RDONLY|C.O_NOFOLLOW|C.O_NONBLO
const directoryFd=fs.openSync(directory,C.O_RDONLY|C.O_DIRECTORY|C.O_NOFOLLOW),directoryId=id(fs.fstatSync(directoryFd,{bigint:true}));
const text=read(file);if(hash(text)!==expected)throw Error('Changed installation claim');
const claim=JSON.parse(text),authorityText=read(claim.authority),authority=JSON.parse(authorityText),dispatchText=read(claim.witness),dispatch=JSON.parse(dispatchText);
-if(authority.directory!==directoryId||read(file+'.dispatch')!==dispatchText||dispatch.kind!=='run'||dispatch.token!==claim.token||dispatch.claim!==expected)throw Error('Unconfirmed installer dispatch');
+if(nodev(authority.directory)!==nodev(directoryId)||read(file+'.dispatch')!==dispatchText||dispatch.kind!=='run'||dispatch.token!==claim.token||dispatch.claim!==expected)throw Error('Unconfirmed installer dispatch');
try{fs.lstatSync(file+'.result');throw Error('Installer already settled')}catch(e){if(e.code!=='ENOENT')throw e}
function current(){
if(id(fs.lstatSync(directory,{bigint:true}))!==directoryId||read(file)!==text||read(claim.authority)!==authorityText||read(claim.witness)!==dispatchText||read(file+'.dispatch')!==dispatchText)throw Error('Changed installation authority');
for(const p of claim.previous)if(hash(read(p.file))!==p.digest)throw Error('Changed installation predecessor');
for(const r of claim.routes){let s;try{s=fs.lstatSync(r.path,{bigint:true})}catch(e){if(e.code!=='ENOENT')throw e;s=null}
- if((s?id(s):null)!==r.identity)throw Error('Changed installation target');
- if(r.alias&&(!s||ver(s)!==r.alias.version||fs.readlinkSync(r.path)!==r.alias.target))throw Error('Changed installation alias');}
+ if(nodev(s?id(s):null)!==nodev(r.identity))throw Error('Changed installation target');
+ if(r.alias&&(!s||nodev(ver(s))!==nodev(r.alias.version)||fs.readlinkSync(r.path)!==r.alias.target))throw Error('Changed installation alias');}
}
function publish(value){
current();const temporary=file+'.'+claim.token+'.result-tmp',result=file+'.result';
@@ -198,7 +199,7 @@ export function createNativeInstallations({ directory, node = managedNodePath, d
authority = readRecord(authorityFile)
}
const genesis = JSON.parse(authority.text) as Authority
- if (genesis.version !== 1 || genesis.directory !== directoryId) return hold('The engine installation history was replaced; its previous owner is still unconfirmed.')
+ if (genesis.version !== 1 || withoutDevice(genesis.directory) !== withoutDevice(directoryId)) return hold('The engine installation history was replaced; its previous owner is still unconfirmed.')
const stamp = directoryStamp(directory)
// NativeFiles retains iterator acquisition and ancestor evidence, including ABA route swaps.
const entries = new NativeFiles().entries(directory), names = entries.filter(name => /^\d{8}\.json$/.test(name)).sort()
diff --git a/cli/src/engines/kit/nativeInstallProcess.spec.ts b/cli/src/engines/kit/nativeInstallProcess.spec.ts
index 57a79ef21..ac2432e24 100644
--- a/cli/src/engines/kit/nativeInstallProcess.spec.ts
+++ b/cli/src/engines/kit/nativeInstallProcess.spec.ts
@@ -71,6 +71,27 @@ it('executes the real installation wrapper once without starting the engine or d
expect(await controller().ensure('opencode', chosen, environment, 'request', () => true)).toEqual({ complete: true })
}, 15_000)
+it('dispatches a claim saved before a reboot renumbered the disk', async () => {
+ const chosen = recipe(installCode())
+ await controller().ensure('opencode', chosen, environment, 'request', () => true)
+ // The core died after saving the claim and before its dispatch; the restart gave the volume another st_dev.
+ const file = join(directory, '00000000.json'), renumber = (saved: string | null) => saved && saved.replace(/^\d+:/, '1:')
+ rmSync(`${directory}.00000000.dispatch`); rmSync(`${file}.dispatch`)
+ const claim = JSON.parse(readFileSync(file, 'utf8'))
+ for (const route of claim.routes) {
+ route.identity = renumber(route.identity)
+ if (route.alias) route.alias.version = renumber(route.alias.version)
+ }
+ writeFileSync(file, JSON.stringify(claim))
+ const authority = JSON.parse(readFileSync(`${directory}.authority`, 'utf8'))
+ writeFileSync(`${directory}.authority`, JSON.stringify({ ...authority, directory: renumber(authority.directory) }))
+ const restarted = controller()
+ expect(await restarted.ensure('opencode', chosen, environment, 'request', () => true)).toMatchObject({ running: true })
+ const [, dispatched, hash] = restarted.dispatch.mock.calls[0]
+ expect(await run(dispatched, hash)).toMatchObject({ code: 0 })
+ expect(await controller().ensure('opencode', chosen, environment, 'request', () => true)).toEqual({ complete: true })
+}, 15_000)
+
it('waits for a private live Desktop download marker before using its installation', async () => {
mkdirSync(join(home, '.harness', 'run'), { recursive: true })
const downloader = spawn(process.execPath, ['-e', 'setInterval(()=>{},1000)', 'harness-download-private-fixture'], { stdio: 'ignore' })
diff --git a/cli/src/engines/kit/nativePaths.ts b/cli/src/engines/kit/nativePaths.ts
index 160aed03b..911411094 100644
--- a/cli/src/engines/kit/nativePaths.ts
+++ b/cli/src/engines/kit/nativePaths.ts
@@ -7,6 +7,10 @@ import { NativeEvidenceBudget, nativeUnavailable } from './nativeEvidence.js'
export const nativeFileKey = (info: Pick<BigIntStats, 'dev' | 'ino'>) => `${info.dev}:${info.ino}`
const identity = (info: BigIntStats | null) => info && `${nativeFileKey(info)}:${info.mode}:${info.uid}`
const version = (info: BigIntStats) => `${identity(info)}:${info.size}:${info.mtimeNs}:${info.ctimeNs}`
+/** Saved evidence outlives a reboot, and st_dev does not: macOS numbers /dev/diskN as disks appear at boot, so one
+ * restart moved a user's data volume from 1,4 to 1,7 and held every launch for good (2026-10-16). Saved identities
+ * and versions lead with st_dev; they are compared without it. */
+export const withoutDevice = <T extends string | null | undefined>(saved: T): T => (saved && saved.slice(saved.indexOf(':') + 1)) as T
type Part = { info: BigIntStats | null; target?: string }
type Location = { path: string; info: BigIntStats } | null
/** Immutable route facts can cross a service boundary; timestamps matter for aliases, not sibling churn. */
@@ -27,7 +31,8 @@ export function verifyNativePathFacts(facts: readonly NativePathFact[]): void {
if ((error as NodeJS.ErrnoException).code !== 'ENOENT') return nativeUnavailable('the retained route became unreadable')
info = null
}
- if (identity(info) !== fact.identity || (fact.alias && (!info || version(info) !== fact.alias.version || target !== fact.alias.target))) {
+ if (withoutDevice(identity(info)) !== withoutDevice(fact.identity)
+ || (fact.alias && (!info || withoutDevice(version(info)) !== withoutDevice(fact.alias.version) || target !== fact.alias.target))) {
return nativeUnavailable('the retained route changed during preparation')
}
}