Skip to content

Keep pending approvals across app restarts (#349) - #1692

Merged
currentbits merged 2 commits into
mainfrom
coder/approval-state-must-survive-app-restarts-0e5997
Oct 19, 2026
Merged

currentbits merged 2 commits into
mainfrom
coder/approval-state-must-survive-app-restarts-0e5997

Conversation

@currentbits

Copy link
Copy Markdown
Owner

Quitting or crashing Solenta while an agent waited on a permission prompt used to lose the prompt: the CLI died, the card vanished, and the thread kept a "waiting" badge with nothing to answer. Now the card comes back after restart with the same tool, command, and context, and answering it picks the work back up. Closes #349.

Changes

  • The prompt the user sees is mirrored onto the thread (pendingApproval) every time it changes, so a crash or quit finds it on disk. A user Stop, an answer, or a new human message clears it. Machine turns (notices, auto-resume) keep it, as they already do for question and plan cards.
  • After a restart the card is restored and marked as such ("Asked before Solenta restarted…"). Allow resumes the session with a [restart] turn telling the agent to make that exact call again. The re-issued call (same tool and input, by hash) runs without a second card. Deny closes the card and starts no turn.
  • Restored plan approvals still leave plan mode and save the plan. Restored questions send the chosen answers as the resume turn.

Verification

  • New tests in electron/test/claude.test.js: ask → stopAll → fresh Store and runner loaded from disk → the restored card matches → Allow → the fake CLI's re-ask is auto-allowed and the run finishes with no second card. Deny on a restored card closes it without starting a run. Both pass, along with the existing permission tests.
  • Full npm run test:electron: 4938 pass / 19 fail. I re-ran the 10 failing files one at a time on a clean HEAD worktree and on this branch. Both show the same 3 failures (pdfjs, PTY, serve-web QR, all from the local environment); the other 16 only fail under full-suite load.
  • tsc --noEmit: no errors in the files touched here. The remaining errors come from xterm/highlight.js/mermaid, which aren't installed locally.
  • Not tested: the real app's quit/relaunch by hand, or a real Codex/OpenCode re-ask.

Notes for reviewers

  • The one-shot grant is spent by the first gated ask, match or not, so it can't linger. If the agent asks for something else first, the re-run shows a card again (fails closed). Deny guardrails still run before it. It does bypass a profile.ask rule, but only for the exact call the user just approved.
  • The grant works for Claude and Codex. On OpenCode the re-ask shows one more card. Codex inputs include reason, so a reworded re-ask also shows a second card.
  • MCP elicitations aren't persisted: their request dies with the MCP server. The CI-workflow sign-off stays in memory on purpose, so it still needs a fresh click after a restart.
  • A restored card has no command editing and no Allow always: the CLI those were for is gone.

🤖 Generated with Claude Code

Solenta-Message-Id: 00d9a10c-0062-45ce-80c1-46a3d951ee2b
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-19T08:56:28.722065Z 7f2d6ba PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7f2d6bac47

ℹ️ 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".

Comment on lines +993 to +995
} else if (approved) {
patch.restartGrant = saved.grantKey || null;
line = `[restart] The app restarted while ${card.summary} waited for approval. The user approved it: make that exact ${card.toolName} call again now; it will run without asking.`;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Expire unused restart grants after the resumed turn

The approval hash is persisted without a run identifier or expiry and is only cleared by takeRestartGrant. If the resumed turn finishes, fails, or is stopped before reissuing the exact call, the hash remains on the thread; a later unrelated turn that requests the same operation will therefore execute it without a fresh permission prompt. Scope the grant to the immediate resume run and clear it on every terminal or superseding path.

Useful? React with 👍 / 👎.

Comment on lines +169 to +170
if (p && !p.inputRequest) {
if (saved && saved.id === p.id) return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Include the run when identifying an already-saved prompt

When a machine-delivered turn runs over a restored card, a provider can reuse the previous process's connection-local request ID, especially numeric JSON-RPC IDs. This early return then leaves the old card and old runId persisted instead of recording the new live ask; after the live ask is answered, the cleanup at lines 186-188 refuses to clear that old card because its run differs, so the stale approval reappears and can start another resume turn. Treat the prompt as synchronized only when both its ID and run ID match.

Useful? React with 👍 / 👎.

@currentbits
currentbits merged commit a7b13dc into main Oct 19, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Approval state must survive app restarts

1 participant