Confirmation state machine for write operations #8

Closed
opened 2026-03-28 19:25:15 +00:00 by forgejo_admin · 2 comments

Type

Feature

Lineage

Depends on forgejo_admin/westside-ai-assistant #6 (AI engine core). Split from original #6 per review-598-2026-03-28 decomposition recommendation.

Repo

forgejo_admin/westside-ai-assistant

User Story

As Marcus (admin)
I want write operations to require explicit confirmation before executing
So that I can't accidentally modify program data through a misinterpreted message

Context

When the AI engine (#6) identifies a write operation, it returns a confirmation indicator instead of executing. This ticket implements the confirmation UX: posting a confirmation prompt to GroupMe, storing the pending action, handling "yes" (execute) or anything else (cancel), and expiring stale confirmations after 5 minutes.

File Targets

Files the agent should create:

  • app/confirmation.py — confirmation state machine: pending action store (dict keyed by group_id), store_pending(group_id, action), check_pending(group_id, message), expire_stale(), 5-minute TTL
  • tests/test_confirmation.py — full state machine tests

Files the agent should modify:

  • app/ai.py — integrate confirmation module: write tool_use → post confirmation prompt → store pending; incoming "yes" → execute pending → post result; anything else → cancel pending → post cancellation; check expiry on each message

Files the agent should NOT touch:

  • app/basketball.py — consumed as-is
  • app/groupme.py — already wired to ai.process_message() in #6
  • app/config.py — no new config needed

Acceptance Criteria

  • Write request ("Update height to 6'1") → confirmation prompt posted to GroupMe, action NOT executed
  • "yes" reply → pending action executed via basketball.py → success message posted
  • Non-"yes" reply → pending action canceled → cancellation message posted
  • No reply for 5 minutes → pending action expired → no execution
  • Only one pending action per group at a time (new write request replaces old pending)

Test Expectations

  • Unit test: store_pending stores action correctly
  • Unit test: check_pending with "yes" returns action for execution
  • Unit test: check_pending with "no" returns cancellation
  • Unit test: expire_stale removes actions older than 5 minutes
  • Unit test: end-to-end confirmation flow via ai.process_message()
  • Run command: pytest tests/test_confirmation.py -v

Constraints

  • Confirmation prompt format: "I'll [action description]. Reply 'yes' to confirm."
  • Success format: "Done. [what was changed]."
  • Cancel format: "Canceled."
  • Expiry check runs on every incoming message (no background timer needed)
  • Case-insensitive "yes" matching

Checklist

  • PR opened
  • Tests pass
  • No unrelated changes
  • project-westside-ai-assistant — parent project
  • story-westside-ai-assistant-write-ops — write operations story
  • story-westside-ai-assistant-safety — safety story
### Type Feature ### Lineage Depends on forgejo_admin/westside-ai-assistant #6 (AI engine core). Split from original #6 per review-598-2026-03-28 decomposition recommendation. ### Repo `forgejo_admin/westside-ai-assistant` ### User Story As Marcus (admin) I want write operations to require explicit confirmation before executing So that I can't accidentally modify program data through a misinterpreted message ### Context When the AI engine (#6) identifies a write operation, it returns a confirmation indicator instead of executing. This ticket implements the confirmation UX: posting a confirmation prompt to GroupMe, storing the pending action, handling "yes" (execute) or anything else (cancel), and expiring stale confirmations after 5 minutes. ### File Targets Files the agent should create: - `app/confirmation.py` — confirmation state machine: pending action store (dict keyed by group_id), store_pending(group_id, action), check_pending(group_id, message), expire_stale(), 5-minute TTL - `tests/test_confirmation.py` — full state machine tests Files the agent should modify: - `app/ai.py` — integrate confirmation module: write tool_use → post confirmation prompt → store pending; incoming "yes" → execute pending → post result; anything else → cancel pending → post cancellation; check expiry on each message Files the agent should NOT touch: - `app/basketball.py` — consumed as-is - `app/groupme.py` — already wired to ai.process_message() in #6 - `app/config.py` — no new config needed ### Acceptance Criteria - [ ] Write request ("Update height to 6'1") → confirmation prompt posted to GroupMe, action NOT executed - [ ] "yes" reply → pending action executed via basketball.py → success message posted - [ ] Non-"yes" reply → pending action canceled → cancellation message posted - [ ] No reply for 5 minutes → pending action expired → no execution - [ ] Only one pending action per group at a time (new write request replaces old pending) ### Test Expectations - [ ] Unit test: store_pending stores action correctly - [ ] Unit test: check_pending with "yes" returns action for execution - [ ] Unit test: check_pending with "no" returns cancellation - [ ] Unit test: expire_stale removes actions older than 5 minutes - [ ] Unit test: end-to-end confirmation flow via ai.process_message() - Run command: `pytest tests/test_confirmation.py -v` ### Constraints - Confirmation prompt format: "I'll [action description]. Reply 'yes' to confirm." - Success format: "Done. [what was changed]." - Cancel format: "Canceled." - Expiry check runs on every incoming message (no background timer needed) - Case-insensitive "yes" matching ### Checklist - [ ] PR opened - [ ] Tests pass - [ ] No unrelated changes ### Related - `project-westside-ai-assistant` — parent project - `story-westside-ai-assistant-write-ops` — write operations story - `story-westside-ai-assistant-safety` — safety story
Author
Owner

Scope Review: READY

Review note: review-604-2026-03-28

Ticket scope is solid. All template sections present, traceability complete (story:write-ops, story:safety, arch:A2), file targets well-specified, acceptance criteria agent-verifiable, and blast radius low. Dependency on #6 is documented and clean — #6 explicitly leaves a "confirmation needed" indicator for this ticket to consume. Fits in a single agent pass (~3-4 min).

## Scope Review: READY Review note: `review-604-2026-03-28` Ticket scope is solid. All template sections present, traceability complete (story:write-ops, story:safety, arch:A2), file targets well-specified, acceptance criteria agent-verifiable, and blast radius low. Dependency on #6 is documented and clean — #6 explicitly leaves a "confirmation needed" indicator for this ticket to consume. Fits in a single agent pass (~3-4 min).
Author
Owner

QA agent reading issue for acceptance criteria review.

_QA agent reading issue for acceptance criteria review._
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
forgejo_admin/westside-ai-assistant#8
No description provided.