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
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).
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
judgement.decisionsandapprovals.requestsstoreconnector,action,target_kindandenvironment(target_idon requests) as text, and find their action type by joiningjudgement.action_typeson all four. Neither storesaction_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.decisions_by_classin00005_judgement.sqlexists 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_idonly.Change
Schema, editing the baselines in place:
00005_judgement.sql: addaction_type_id uuid NOT NULL REFERENCES judgement.action_types (id)tojudgement.decisions. Replacedecisions_by_classwith an index on(org_id, action_type_id, created_at).00006_approvals.sql: addaction_type_id uuidtoapprovals.requestswith no foreign key (another module's table). It is set forkind = 'action'and forkind = 'autonomy'(the proposal's action type); addCHECK (action_type_id IS NOT NULL)if both kinds always have one.Getting the id to the decision:
ActionTypes.Level(modules/judgement/action_types.go), called by thePrecedentguard (modules/judgement/guards.go) before the decision is recorded inModule.record(modules/judgement/judgement.go). MakeLevelreturn the row's id with the level (or add a method that returns the action type), carry it on the verdict or theDecision, and write it inrecord. A decision recorded without the precedent guard must still get an id: callEnsureActionTypeinrecordif none is carried, so the column can beNOT NULL.ActionTypeIDonjudgement.Decisionso approvals can copy it.Reads by id:
ActionTypeOfDecisionbecomes a lookup bydecisions.action_type_id.ActionTypeDecisionsfiltersWHERE org_id = $1 AND action_type_id = $2 AND NOT dry.Approvals (
modules/approvals):approvals.go: setActionTypeIDin the action requestPut(fromd.ActionTypeID) and inaskProposal(fromr.ActionType.ID).internal/store/store.go: add the column to the insert and the column list.Done when
action_type_id.action_type_id.task checkpasses.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).