Skip to content

fix: Refuse a replayed plan approval at any age - #180

Closed
ecv wants to merge 1 commit into
mainfrom
fix/178-spent-approval-replay
Closed

ecv wants to merge 1 commit into
mainfrom
fix/178-spent-approval-replay

Conversation

@ecv

@ecv ecv commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Summary

A used plan approval could apply a change again after a restart, on a second replica, or 15 minutes later in the streaming chat and API; now it is refused at any age. An assistant with no database to record approvals no longer offers to plan or apply changes, only to validate them.

Fixes #178

Warning

In the streaming chat and API, each approval code works once per conversation, so re-approving after a failed apply needs the new plan's token or the plan card.

Test plan

  • Vet, build, unit tests and lint on the changed packages pass, with no new lint findings
  • A replay at 15 minutes, 25 hours and 1 year is refused, with and without a message id. On main, the replay at 15 minutes applied the plan
  • Against a local Postgres, an approval recorded 400 days ago survives pruning and is refused
  • CI passes. CI skips the Postgres test because it sets no database URL

Without Postgres, spent plan approvals lived in one process's memory, so a
restart or a second replica accepted an approval that was already used. On
/chat/stream and the apiserver, a text approval carries no message id, and it
was refused on replay for only 7.5 to 15 minutes, then accepted again against
a re-plan of the same manifests.

Key changes:
- Leave resources_plan and resources_apply out when no approval store is
  configured; deployments without Postgres keep resources_validate only.
- Spend text approvals in a permanent ledger record that pruning never
  removes; without a message id, each approval code works once per
  conversation.
- When a spent code is refused, tell the model to ask for approval by the
  new plan's token, which differs on every re-plan.
- Add a permanent column to assistant_exec_approvals; plan card and exec
  approvals keep the one-day retention, longer than any token they carry.
@ecv ecv mentioned this pull request Nov 17, 2026
2 tasks
@ecv
ecv marked this pull request as ready for review November 17, 2026 15:25
@ecv
ecv enabled auto-merge November 17, 2026 15:25
@ecv
ecv disabled auto-merge November 17, 2026 15:26
@ecv
ecv marked this pull request as draft November 17, 2026 15:26

@andrewb3000 andrewb3000 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.

Non-blocking

  • internal/execapproval/postgres.go:61: Rolling back to the previous image brings back its prune, which ignores permanent. Text approvals older than a day would then be deleted and could be replayed again. Note this in the release notes or the runbook.
  • internal/execapproval/postgres.go:59: Permanent rows are never pruned, so the table grows by one row per typed approval forever. That is small today, but consider a long cap, such as a year, or a follow-up issue.

Checked

  • internal/agentwiring/wiring.go:277: Checked the wiring. The only agent.New caller passes the Postgres store whenever CONVERSATION_STORE_URL is set. config/base/assistant.yaml and the production overlay both set that variable, so deployed assistants keep plan and apply. Only local runs without a database lose them.
  • internal/execapproval/postgres.go:17: The ALTER TABLE ADD COLUMN IF NOT EXISTS with a constant default is metadata-only, and the table is pruned daily, so the brief exclusive lock is harmless. Concurrent replicas run it one after another. Old pods still insert with the default false during the rollout.

@kevwilliams kevwilliams left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Verified marking used is one atomic insert, errors refuse, and the replay test fails on main; with no database the apply tool is removed.

@ecv

ecv commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #181, which merged on 18 Nov. It keys each spent approval to a code the server derives from the verified plan, so no conversation or message id from the client can make an approval fresh again. That closes the replay this PR targeted.

@ecv ecv closed this Nov 18, 2026
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.

Spent plan approvals can be replayed

3 participants