README Source History Refs Reviews Compare Notes Search Review guide CI runs fix: refresh wake-facts worktree state so HEAD is never stale 5662d1738b9b320aa9cd4bcc6eca65caca94164f
will <will@bugabinga.net > · 14 Sep 2026
SSH signature · not checked
Browse files Compare with HEAD
buildFacts closed over the boot-time syncWorktree snapshot, so after any
post-boot worktree movement every wake reported the boot HEAD (observed:
facts claimed c30d2b6 for hours while HEAD was ffca180). The closure also
referenced the const before initialization and only worked because facts
build lazily after boot.
Add readWorktreeState (rev-parse + status --porcelain; no fetch, no merge
- fetch+ff stays a boot-time behavior per spec AC15), hold the snapshot in
a let declared before the engine, refresh it in buildFacts, and cover the
fresh-read semantics with a unit test. Ratchet 90.9%.
Changed files (4) Diff layout Auto Unified Split
coverage-ratchet.json Modified +2 / −2 text lines
3 - "updatedAt" : "2026-09-13T01:09:27.958Z" ,3 + "updatedAt" : "2026-09-13T04:04:47.630Z" ,4 4 "note" : "ratchet only rises; commit the raise with the change that caused it" "note" : "ratchet only rises; commit the raise with the change that caused it" src/agent/main.ts Modified +12 / −2 text lines
19 19 import { TelegramClient } from './telegram-client.ts' import { TelegramClient } from './telegram-client.ts' 20 20 import { createTelegramRuntime } from './telegram-runtime.ts' import { createTelegramRuntime } from './telegram-runtime.ts' 21 21 import { createWillTools } from './tools.ts' import { createWillTools } from './tools.ts' 22 - import { syncWorktree } from './worktree.ts' 22 + import { readWorktreeState , syncWorktree, type WorktreeStatus } from './worktree.ts' 23 23 import { ZaiRestClient } from './zai/client.ts' import { ZaiRestClient } from './zai/client.ts' 24 24 import { createZaiTools } from './zai/tools.ts' import { createZaiTools } from './zai/tools.ts' 144 144 void sessionToolSummaries void sessionToolSummaries
149 + let worktreeStatus: WorktreeStatus = {152 + fastForwarded: false ,147 155 const engine = createEngine ({ const engine = createEngine ({156 164 } catch { } catch {157 165 storageState = undefined storageState = undefined
168 + worktreeStatus = await readWorktreeState (config.workDir)160 170 timeUtc: new Date ().toISOString (), timeUtc: new Date ().toISOString (),161 171 revision: config.revision, revision: config.revision,176 - const worktreeStatus = await syncWorktree (config.workDir, config.vcs.gitUrl, config.vcs.branch)186 + worktreeStatus = await syncWorktree (config.workDir, config.vcs.gitUrl, config.vcs.branch)177 187 if (worktreeStatus.error) log.warn ('worktree not ready' , { error: worktreeStatus.error }) if (worktreeStatus.error) log.warn ('worktree not ready' , { error: worktreeStatus.error })179 189 log.info ('worktree synced' , { log.info ('worktree synced' , {src/agent/runtime.int.test.ts Modified +38 / −1 text lines
17 17 import { AgentState } from './state.ts' import { AgentState } from './state.ts' 18 18 import { createWillTools } from './tools.ts' import { createWillTools } from './tools.ts' 19 19 import type { Tool } from './tools-shape.ts' import type { Tool } from './tools-shape.ts' 20 - import { syncWorktree } from './worktree.ts' 20 + import { readWorktreeState , syncWorktree } from './worktree.ts' 22 22 const exec = promisify (execFile)const exec = promisify (execFile)62 62 assert.equal (s4.diverged, true ) assert.equal (s4.diverged, true )
65 + test ('readWorktreeState: fresh head and dirty flag without fetch or merge' , async () => {66 + const dir = await mkdtemp (join (tmpdir (), 'wt-read-' ))67 + const remote = join (dir, 'origin.git' )68 + const work = join (dir, 'work' )69 + await exec ('git' , ['init' , '--bare' , '-b' , 'trunk' , remote])70 + const seed = join (dir, 'seed' )71 + await exec ('git' , ['clone' , remote, seed])72 + await writeFile (join (seed, 'a.txt' ), 'one\n' )73 + await exec ('git' , ['add' , '.' ], { cwd: seed })74 + await exec ('git' , ['commit' , '-m' , 'one' , '--author' , 't <t@t>' ], { cwd: seed })75 + await exec ('git' , ['push' , 'origin' , 'trunk' ], { cwd: seed })76 + await exec ('git' , ['clone' , '--quiet' , remote, work])78 + const head = () => exec ('git' , ['rev-parse' , 'HEAD' ], { cwd: work })79 + const s1 = await readWorktreeState (work)80 + assert.equal (s1.head, (await head ()).stdout.trim ())81 + assert.equal (s1.dirty, false )84 + await writeFile (join (work, 'b.txt' ), 'local\n' )85 + await exec ('git' , ['add' , '.' ], { cwd: work })86 + await exec ('git' , ['commit' , '-m' , 'local' , '--author' , 't <t@t>' ], { cwd: work })87 + const s2 = await readWorktreeState (work)88 + assert.equal (s2.head, (await head ()).stdout.trim ())89 + assert.notEqual (s2.head, s1.head)92 + await writeFile (join (work, 'c.txt' ), 'uncommitted\n' )93 + const s3 = await readWorktreeState (work)94 + assert.equal (s3.dirty, true )97 + const s4 = await readWorktreeState (join (dir, 'missing' ))99 + assert.equal (s4.head, undefined )65 102 test ('ci watch enqueues one failure wake per failed run of a tracked sha' , async () => {test ('ci watch enqueues one failure wake per failed run of a tracked sha' , async () => {66 103 const runs: unknown [] = [] const runs: unknown [] = []67 104 const server = createServer ((_req, res) => { const server = createServer ((_req, res) => {src/agent/worktree.ts Modified +23 / −0 text lines
16 16 error?: string | undefined error?: string | undefined
24 + export async function readWorktreeState (workDir: string ): Promise <WorktreeStatus > {25 + const status: WorktreeStatus = {28 + fastForwarded: false ,32 + const git = (... args: string []) => exec ('git' , args, { cwd: workDir, maxBuffer: 10 << 20 })33 + status.head = (await git ('rev-parse' , 'HEAD' )).stdout.trim ()34 + const dirty = await git ('status' , '--porcelain' )35 + status.dirty = dirty.stdout.trim ().length > 0 37 + status.error = err instanceof Error ? err.message : String (err)