Repository navigation
confirmations: persist intents and the lead across a restart - #116
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8d4e7fd11f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| requiresHuman = false, // destructive/credential/paid: never delegable to a | ||
| // team lead, however sound the lead is. A sleeping | ||
| // owner is a reason to WAIT on these, not to widen | ||
| // who may authorise them. |
There was a problem hiding this comment.
Mark typed actions as requiring the human owner
The new requiresHuman flag defaults to false, but createActionRequest() does not override it when creating intents for merge_pr, deploy_site, upload_play_internal, or install_debug_apk. Consequently, a sitting lead can approve another agent's high-risk typed action and runApprovedAction() will execute it, despite the stated invariant that destructive, credential, and paid actions remain owner-only.
Useful? React with 👍 / 👎.
| // Retained so canDecide can refuse self-approval. Without it a lead could | ||
| // raise a confirmation and clear it themselves, which is not delegation, | ||
| // it is a bypass with extra steps (codexmb, 2026-09-18). | ||
| requestedBy: typeof fromHandle === 'string' ? fromHandle : null, |
There was a problem hiding this comment.
Derive the requester from authenticated identity
requestedBy is now used to prevent lead self-approval, but it comes from the caller-controlled optional fromHandle: the MCP tool explicitly accepts it and POST /intent copies payload.from_handle. A lead can omit it or name another handle, then use its principal token to approve its own request, bypassing the new self-approval boundary; the requester must be bound to authenticated or otherwise trusted provenance.
Useful? React with 👍 / 👎.
| if (e.kind === 'intent' && e.id && e.intent) { | ||
| intents.set(e.id, { ...e.intent, resolvers: [] }); |
There was a problem hiding this comment.
Persist and replay typed action records
When persistence is enabled, replay restores only intents; the associated entry in the actions map 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, and GET /actions/:nonce returns unknown.
Useful? React with 👍 / 👎.
| if (seen.size > 0 && seededRooms.size === 0) { | ||
| for (const room of rooms) seededRooms.add(room); | ||
| try { markSeeded(rooms[0]); } catch {} |
There was a problem hiding this comment.
Seed all rooms when migrating a legacy seen file
On the first upgrade from the legacy format, any nonempty seen file causes every currently configured room to be marked seeded without fetching it. If a room is added in the same deployment as this upgrade, none of its IDs can be in the legacy file, yet the following poll treats its historical messages—including old /lead commands or executable automation matches—as new and dispatches them.
Useful? React with 👍 / 👎.
| // shadowed, cooled down or overridden by whatever is in the rules | ||
| // array. | ||
| const leadReply = await handleLeadCommand(m, { | ||
| daemonUrl: config?.confirmations?.daemon_url || 'http://127.0.0.1:8788', |
There was a problem hiding this comment.
Honor the configured confirmations daemon address
Room automation ignores the documented mcp.confirmations.host and mcp.confirmations.port settings and instead looks for an unrelated top-level confirmations.daemon_url, falling back to port 8788. For configurations using another port, such as the repository's Grok example on 8791, every /lead command contacts the wrong daemon and cannot update the actual confirmation registry.
Useful? React with 👍 / 👎.
| if (parsed.op === 'status') { | ||
| const { status, payload } = await callDaemon(daemonUrl, '/lead'); |
There was a problem hiding this comment.
Authenticate lead status requests
When the confirmations server has auth_token configured, its global bearer check also protects GET /lead, but the status branch calls the daemon without the available principalToken. Thus /lead status consistently receives 401 and misleadingly reports that the daemon lacks the route, even though assignment requests using the same principal token work.
Useful? React with 👍 / 👎.
| // With no principals configured, privileged routes refuse and delegation is | ||
| // simply unavailable. That is deliberate: this feature ships INERT rather | ||
| // than insecure, and an unconfigured daemon behaves exactly as it does today. | ||
| principals = {}, |
There was a problem hiding this comment.
Pass principals to the in-process confirmation server
The new principal-based lead API only works when callers provide principals, but the in-process fallback in src/mcp-server.mjs still starts startConfirmationsServer() without confirmCfg.principals. In deployments without the standalone daemon, configured principal tokens are therefore discarded and every POST /lead returns that delegation is unavailable.
Useful? React with 👍 / 👎.
| persistIntent(id, i); | ||
| i.decidedByRole = permitted.role; |
There was a problem hiding this comment.
Persist the decision role after assigning it
persistIntent() runs before decidedByRole is assigned, so the durable decision record omits whether the owner or lead approved it. After a restart, listIntents() reports decidedByRole: null, losing part of the audit trail that this change explicitly exposes; assign the role before appending the state entry.
Useful? React with 👍 / 👎.
`intents` lived only in this process. A restart threw the queue away with no warning and nothing read it back, so every pending approval card silently became undecidable. That bit three times on 2026-09-19, once wiping an intent that was mid-review. Append-only JSONL, replayed at boot. Append-only because a rewrite in place can truncate on a crash and take the whole queue with it: that is the failure being removed, not relocated. A persistence error is logged and swallowed, never raised into the decision path -- losing the record is bad, refusing the approval is worse. The id is the Map KEY, not a field on the intent, so it is written explicitly. Without that the log looks perfectly healthy and replays nothing; the restart test is what caught it. Deliberately not persisted: `resolvers`, which are live promise callbacks that died with the old process. A replayed intent gets an empty list and a new caller can wait on it again. SCOPE. This is a re-cut off current main, replacing a version that was stacked on claudemm/team-lead-approvals and carried all 13 of that draft's commits -- including the `principals` code that locked the owner out of approvals earlier tonight. Merging that would have shipped the thing we agreed stays on a branch. Caught by @claudemb reading the PR's commit list. The lead-appointment half of the original commit is NOT here: main has no team-lead feature, so setLead/getLead do not exist to persist or to test. `kind: 'lead'` rows are skipped on replay rather than rejected, so a log written by that branch still replays its intents cleanly. That half rides with the team-lead PR. Suite 338 pass, 0 fail (334 + 4 new). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
8d4e7fd to
76358a9
Compare
intentswas a barenew Map()andteamLeada barelet, with nothing read back at boot, so a daemon restart silently threw both away: pending approval cards became undecidable and any sitting lead was unseated, with no log line and no error to the caller. That bit three times on 19 Sep 2026 while wiring /lead.Fix is append-only JSONL replayed at boot via
loadPersistedState(path). Append-only because a rewrite-in-place can truncate on a crash and take the whole queue with it. A truncated final line is skipped and counted; the rest still loads.resolversis deliberately not persisted - those are live promise callbacks that died with the old process.Opt-in: with no path configured nothing is written and behaviour is unchanged. NOT wired into the daemon here, per codexmb's request for no live toggles while the credential design is open.
Verified: test/persist-intents.test.mjs, 5 cases (intent survives, decision survives, appointment survives, truncated line skipped with the rest intact, nothing written when unconfigured). Suite 393 pass, 0 fail.
Note for reviewers: this branch contains the 13 commits of claudemm/team-lead-approvals plus the one persistence commit, so it is stacked on that draft PR.
🤖 Generated with Claude Code