Discovery: guarded state transitions are encoded four different ways #1783

Open
opened 2026-11-02 15:24:35 +00:00 by sam · 0 comments
Owner

From the 2026-08 architecture review follow-up (related to #1781, #1782).

What is wrong: "move an entity from one state to another only if it is in the expected state, else a typed conflict error" is implemented meaningfully the same but encoded four different ways:

  1. internal/taskstate/transitions.go — data-driven transition maps + CanTransition/CanStepTransition (the one place the shape lives as a reusable form).
  2. internal/domain/identity/identity.go — switch-encoded commands (case CommandSuspend/Reactivate/Retire).
  3. Binding state machine — store-guarded methods in internal/infrastructure/postgres/edastore.go (ApproveBinding/PauseBinding/ResumeBinding → ErrBindingTransition), with the atomic guard in SQL (WHERE id = @id AND status = @from_status, edastore.sql:135, tasks.sql:261).
  4. Control-plane resources — optimistic expected_version guard (resources.sql).

Wanted: one generic guarded-transition primitive in the domain (a Machine[S] with the legal moves as data and Can(from,to) + a typed stale/illegal error, generalizing what taskstate already has), which identity/binding/source-signing adopt as data; the SQL WHERE status = @from guard stays per-table (it is the atomicity), but the Go-side validation and error mapping stop being re-encoded.

Done when:

  • one shared transition primitive in internal/domain; at least two of identity/binding/source-signing use it as data
  • SQL guards unchanged (atomicity stays in the store); task check green
From the 2026-08 architecture review follow-up (related to #1781, #1782). **What is wrong:** "move an entity from one state to another only if it is in the expected state, else a typed conflict error" is implemented meaningfully the same but encoded four different ways: 1. `internal/taskstate/transitions.go` — data-driven transition maps + `CanTransition`/`CanStepTransition` (the one place the shape lives as a reusable form). 2. `internal/domain/identity/identity.go` — switch-encoded commands (`case CommandSuspend/Reactivate/Retire`). 3. Binding state machine — store-guarded methods in `internal/infrastructure/postgres/edastore.go` (`ApproveBinding`/`PauseBinding`/`ResumeBinding` → `ErrBindingTransition`), with the atomic guard in SQL (`WHERE id = @id AND status = @from_status`, edastore.sql:135, tasks.sql:261). 4. Control-plane resources — optimistic `expected_version` guard (resources.sql). **Wanted:** one generic guarded-transition primitive in the domain (a `Machine[S]` with the legal moves as data and `Can(from,to)` + a typed stale/illegal error, generalizing what taskstate already has), which identity/binding/source-signing adopt as data; the SQL `WHERE status = @from` guard stays per-table (it is the atomicity), but the Go-side validation and error mapping stop being re-encoded. **Done when:** - one shared transition primitive in `internal/domain`; at least two of identity/binding/source-signing use it as data - SQL guards unchanged (atomicity stays in the store); `task check` green
sam added the discovery label 2026-11-02 15:24:35 +00:00
sam added the medium label 2026-11-14 14:45:42 +00:00
sam added the deferred label 2026-11-15 17:26:12 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sam/archie#1783