Decisions and approval requests identify the action type by its four names #2130

Closed
opened 2026-11-23 13:13:57 +00:00 by sam · 1 comment
Owner

judgement.decisions and approvals.requests store connector, action, target_kind and environment (target_id on requests) as text, and find their action type by joining judgement.action_types on all four. Neither stores action_type_id.

The four-column joins and filters:

  • modules/judgement/internal/store/autonomy.go, ActionTypeOfDecision: joins decisions to action types on the four columns. ActionTypes.Approved (modules/judgement/autonomy.go) uses it to count an approval towards loosening.
  • modules/judgement/internal/store/action_types.go, ActionTypeDecisions: filters decisions on the four columns for the action type's history.
  • Index decisions_by_class in 00005_judgement.sql exists only for that filter.

Decision

Connector package names are immutable (see the connectors issue), so the text columns may stay as a point-in-time snapshot shown in the audit trail and approval messages. The link to the action type is action_type_id only.

Change

Schema, editing the baselines in place:

  • 00005_judgement.sql: add action_type_id uuid NOT NULL REFERENCES judgement.action_types (id) to judgement.decisions. Replace decisions_by_class with an index on (org_id, action_type_id, created_at).
  • 00006_approvals.sql: add action_type_id uuid to approvals.requests with no foreign key (another module's table). It is set for kind = 'action' and for kind = 'autonomy' (the proposal's action type); add CHECK (action_type_id IS NOT NULL) if both kinds always have one.

Getting the id to the decision:

  • The action type row is created or read in ActionTypes.Level (modules/judgement/action_types.go), called by the Precedent guard (modules/judgement/guards.go) before the decision is recorded in Module.record (modules/judgement/judgement.go). Make Level return the row's id with the level (or add a method that returns the action type), carry it on the verdict or the Decision, and write it in record. A decision recorded without the precedent guard must still get an id: call EnsureActionType in record if none is carried, so the column can be NOT NULL.
  • Expose ActionTypeID on judgement.Decision so approvals can copy it.

Reads by id:

  • ActionTypeOfDecision becomes a lookup by decisions.action_type_id.
  • ActionTypeDecisions filters WHERE org_id = $1 AND action_type_id = $2 AND NOT dry.

Approvals (modules/approvals):

  • approvals.go: set ActionTypeID in the action request Put (from d.ActionTypeID) and in askProposal (from r.ActionType.ID).
  • internal/store/store.go: add the column to the insert and the column list.

Done when

  • Every decision and every approval request stores action_type_id.
  • No query joins or filters decisions or requests on connector, action, target kind and environment.
  • An action type's history and its autonomy count read decisions by action_type_id.
  • task check passes.
`judgement.decisions` and `approvals.requests` store `connector`, `action`, `target_kind` and `environment` (`target_id` on requests) as text, and find their action type by joining `judgement.action_types` on all four. Neither stores `action_type_id`. The four-column joins and filters: - `modules/judgement/internal/store/autonomy.go`, `ActionTypeOfDecision`: joins decisions to action types on the four columns. `ActionTypes.Approved` (`modules/judgement/autonomy.go`) uses it to count an approval towards loosening. - `modules/judgement/internal/store/action_types.go`, `ActionTypeDecisions`: filters decisions on the four columns for the action type's history. - Index `decisions_by_class` in `00005_judgement.sql` exists only for that filter. ## Decision Connector package names are immutable (see the connectors issue), so the text columns may stay as a point-in-time snapshot shown in the audit trail and approval messages. The link to the action type is `action_type_id` only. ## Change Schema, editing the baselines in place: - `00005_judgement.sql`: add `action_type_id uuid NOT NULL REFERENCES judgement.action_types (id)` to `judgement.decisions`. Replace `decisions_by_class` with an index on `(org_id, action_type_id, created_at)`. - `00006_approvals.sql`: add `action_type_id uuid` to `approvals.requests` with no foreign key (another module's table). It is set for `kind = 'action'` and for `kind = 'autonomy'` (the proposal's action type); add `CHECK (action_type_id IS NOT NULL)` if both kinds always have one. Getting the id to the decision: - The action type row is created or read in `ActionTypes.Level` (`modules/judgement/action_types.go`), called by the `Precedent` guard (`modules/judgement/guards.go`) before the decision is recorded in `Module.record` (`modules/judgement/judgement.go`). Make `Level` return the row's id with the level (or add a method that returns the action type), carry it on the verdict or the `Decision`, and write it in `record`. A decision recorded without the precedent guard must still get an id: call `EnsureActionType` in `record` if none is carried, so the column can be `NOT NULL`. - Expose `ActionTypeID` on `judgement.Decision` so approvals can copy it. Reads by id: - `ActionTypeOfDecision` becomes a lookup by `decisions.action_type_id`. - `ActionTypeDecisions` filters `WHERE org_id = $1 AND action_type_id = $2 AND NOT dry`. Approvals (`modules/approvals`): - `approvals.go`: set `ActionTypeID` in the action request `Put` (from `d.ActionTypeID`) and in `askProposal` (from `r.ActionType.ID`). - `internal/store/store.go`: add the column to the insert and the column list. ## Done when - Every decision and every approval request stores `action_type_id`. - No query joins or filters decisions or requests on connector, action, target kind and environment. - An action type's history and its autonomy count read decisions by `action_type_id`. - `task check` passes.
sam added the mediumbug labels 2026-11-23 13:13:57 +00:00
Author
Owner

Landed in c5591d95d. Verified with task check and against a throwaway PostgreSQL 18 instance (baseline migrations 00001-00012, judgement.decisions.action_type_id NOT NULL populated from Precedent and via EnsureActionType fallback when Precedent does not run, ActionTypeOfDecision and ActionTypeDecisions lookup by action_type_id independent of snapshot columns, and approvals.requests.action_type_id stored for both action and autonomy requests).

Landed in c5591d95d. Verified with task check and against a throwaway PostgreSQL 18 instance (baseline migrations 00001-00012, judgement.decisions.action_type_id NOT NULL populated from Precedent and via EnsureActionType fallback when Precedent does not run, ActionTypeOfDecision and ActionTypeDecisions lookup by action_type_id independent of snapshot columns, and approvals.requests.action_type_id stored for both action and autonomy requests).
sam closed this issue 2026-11-23 19:54:37 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sam/archie#2130