Repository navigation
confirmations: persist intents and the lead across a restart #116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| // Durable intents across a restart. | ||
| // | ||
| // Scope note: the lead-appointment case from the original commit is NOT here. | ||
| // Main has no team-lead feature, so setLead/getLead do not exist to test. That | ||
| // case rides with the team-lead branch; this file covers the queue only. | ||
| // | ||
| // Written because on 2026-09-19 three daemon restarts silently wiped every | ||
| // pending intent AND the lead petrus had just appointed. The store was a bare | ||
| // `new Map()` with nothing read back at boot, so an approval card became | ||
| // undecidable and nobody was told. | ||
| import { test } from 'node:test'; | ||
| import assert from 'node:assert/strict'; | ||
| import { mkdtempSync, writeFileSync, readFileSync, existsSync } from 'node:fs'; | ||
| import { tmpdir } from 'node:os'; | ||
| import { join } from 'node:path'; | ||
|
|
||
| const dir = mkdtempSync(join(tmpdir(), 'iak-persist-')); | ||
| const statePath = join(dir, 'state.jsonl'); | ||
|
|
||
| // Fresh module instance per "process", which is what a restart actually is. | ||
| async function boot(path) { | ||
| const m = await import('../src/confirmations.mjs?v=' + Math.random()); | ||
| const summary = m.loadPersistedState(path); | ||
| return { m, summary }; | ||
| } | ||
|
|
||
| test('an intent survives a restart, with its decision', async () => { | ||
| const a = await boot(statePath); | ||
| const id = await a.m.createIntent({ prompt: 'benign test', session: 's', channels: [] }); | ||
| assert.ok(id, 'intent created'); | ||
|
|
||
| // Restart: a brand new module instance replays the log. | ||
| const b = await boot(statePath); | ||
| assert.equal(b.summary.intents, 1, 'one intent replayed'); | ||
| const after = b.m.listIntents().find((i) => i.id === id); | ||
| assert.ok(after, 'the intent came back'); | ||
| assert.equal(after.status, 'pending', 'and it is still pending, so it can still be decided'); | ||
| }); | ||
|
|
||
| test('a decision survives a restart', async () => { | ||
| const p2 = join(dir, 'state2.jsonl'); | ||
| const a = await boot(p2); | ||
| const id = await a.m.createIntent({ prompt: 'decide me', session: 's', channels: [] }); | ||
| a.m.decideIntent(id, 'approve', { actor: 'petrus' }); | ||
|
|
||
| const b = await boot(p2); | ||
| const after = b.m.listIntents().find((i) => i.id === id); | ||
| assert.equal(after.status, 'decided'); | ||
| assert.equal(after.decision, 'approve', 'the decision replayed, not just the intent'); | ||
| }); | ||
|
|
||
| test('a truncated final line is skipped, the rest survives', async () => { | ||
| const p4 = join(dir, 'state4.jsonl'); | ||
| const a = await boot(p4); | ||
| await a.m.createIntent({ prompt: 'first', session: 's', channels: [] }); | ||
| // Simulate a hard kill mid-append: valid lines, then a partial one. | ||
| writeFileSync(p4, readFileSync(p4, 'utf8') + '{"kind":"intent","intent":{"id":"trunc"'); | ||
|
|
||
| const b = await boot(p4); | ||
| assert.equal(b.summary.skipped, 1, 'the partial line was skipped'); | ||
| assert.equal(b.summary.intents, 1, 'and the intact intent still loaded'); | ||
| }); | ||
|
|
||
| test('with no state path nothing is written — persistence is opt-in', async () => { | ||
| const unused = join(dir, 'never.jsonl'); | ||
| const a = await boot(null); | ||
| await a.m.createIntent({ prompt: 'no persistence', session: 's', channels: [] }); | ||
| assert.equal(existsSync(unused), false, 'no file appeared'); | ||
| assert.equal(a.summary.intents, 0, 'and loading nothing reports nothing'); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When persistence is enabled, replay restores only
intents; the associated entry in theactionsmap is never stored or reconstructed. If the process restarts after/actions/request, approving the surviving intent takes the pure-confirmation branch because no action is found, so the UI records approval but the requested merge or other executor never runs, andGET /actions/:noncereturns unknown.Useful? React with 👍 / 👎.