fix(events): settle a finished run whose last resource expired while it ran
Found walking Rust PLAN_FIXES step 2 (run 46 on the walk core): a zone expired while its run was still going, so expireResource left the run's cleanup status to its terminal path. When the run was cancelled the sweep never selected it, because runsNeedingCleanup joins on an unresolved row and it had none, so cleanup_status sat at `pending` for ever over an empty ledger. The sweep now settles finished runs that are `pending` with no unresolved row as `complete` (never over `incomplete`, which is a human's to clear). Checked against the walk database: the query returns run 46 and nothing else. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E14m6SuuY6i1vASFeGDBeY
This commit is contained in:
@@ -101,6 +101,7 @@ beforeEach(() => {
|
||||
...new Set([...store.rows.values()].filter((r) => ['pending', 'confirmed'].includes(r.status)).map((r) => r.owner_module)),
|
||||
]
|
||||
resourcesDb.runsNeedingCleanup = async () => store.candidates || []
|
||||
resourcesDb.finishedRunsWithNothingLeft = async () => store.nothingLeft || []
|
||||
|
||||
runsDb.setCleanupStatus = async (id, to, from = null) => {
|
||||
if (from && !from.includes(store.cleanupStatus)) return false
|
||||
@@ -728,3 +729,20 @@ test('a run still in flight keeps its cleanup status, and so does one with rows
|
||||
await cleanup.expireResource('demo', { kind: 'zone', ref: 'y' })
|
||||
assert.equal(store.cleanupStatus, 'incomplete')
|
||||
})
|
||||
|
||||
test('a run whose last resource expired while it ran is settled complete when it ends', async () => {
|
||||
// The step-2 walk's run 46: the zone expired while the run was still going, so
|
||||
// expireResource left its status to the terminal path — and the sweep's scan,
|
||||
// which joins on an unresolved row, would never have selected it. `pending`
|
||||
// for ever, on a ledger with nothing left in it.
|
||||
store.cleanupStatus = 'pending'
|
||||
store.candidates = []
|
||||
store.nothingLeft = [RUN.id]
|
||||
assert.equal(await cleanup.sweep(), 1)
|
||||
assert.equal(store.cleanupStatus, 'complete')
|
||||
|
||||
// And never over an incomplete one — that is a human's to clear.
|
||||
store.cleanupStatus = 'incomplete'
|
||||
await cleanup.sweep()
|
||||
assert.equal(store.cleanupStatus, 'incomplete')
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user