Files
archie/internal/infrastructure/postgres/postgresdb/models.go
T
sam 3f0071e27b feat(statestore): step_executions, StartStep/FinishStep under the run credential
Plan item 3 of docs/prds/execution-tree-state-machine.md (archie-core-1220), on
top of the transition tables and ErrIllegalTransition enforcement (1214/1215,
archie-core-qdbo.5):

- Migration 0017 adds step_executions -- id, org_id, workspace_id, execution_id,
  attempt, parent_id, depth, kind, name, called_execution_id, status, detail,
  tokens_used, started_at, finished_at, indexed on (execution_id, attempt, id).
  Ownership fields are stamped from the execution's row; depth is derived from
  the parent, never supplied by a caller. Existing rows gain no backfilled
  steps.
- task.Store (the workflow engine's mid-run facade) gains StartStep/FinishStep
  (5 methods, within the 8 cap), with storecontract.StepRecorder fronting them
  on the server; deadlineStore wraps both with its per-call timeout.
- The store enforces each write as one transaction: the guarded row write
  under the shared step transition table plus the transition's own
  stage_start/stage_finish event row. Staleness is decided before legality,
  the way guardTransition decides it, and the store returns the persisted
  event for the caller's post-commit publish -- the EmitDurable convention
  (the daemon's event sink skips already-persisted rows by assigned ID), which
  is why workflow.Run stops emitting stage events beside the store and no
  longer discards step-write errors: a failed start or finish parks the
  execution, and the stage does not run unrecorded. An interrupted stage
  records interrupted rather than failed; a recording failure on that
  shutdown path is logged and left to RecoverStale, which owns the
  interrupted-execution sweep in plan item 6.
- The run credential of docs/prds/orgs-and-access.md authorises StartStep and
  FinishStep on its own execution only: both requests carry the execution ID
  the grant check verifies (FinishStep carries it because the interceptor
  never reads the database), and FinishStep verifies handler-side that the
  step really is that execution's. authorizesTaskScopedCall's sanctioned
  widenings are now held as a lookup table so the next one stops growing a
  switch.
- The PRD's wire contract is StartStep(execution, attempt, parent, kind, name)
  -> step id; the responses also carry the persisted event (needed for the
  post-commit publish) and FinishStep's request carries execution_id (needed
  for the grant check) -- both noted here as deliberate additions to the PRD's
  shorthand. called_execution_id exists in the table but not yet on the wire:
  its named consumer is the workflow-call recording of plan item 4 (#1216).

Conformance drives both adapters; grant tests pin the own-execution scoping;
the wire sentinel set gains ErrInvalidStep (InvalidArgument, "step execution
invalid") for a step kind no consumer names.
2026-09-27 05:42:32 +10:00

432 lines
8.2 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.31.1
package postgresdb
import (
"time"
"github.com/jackc/pgx/v5/pgtype"
)
type AccessDenial struct {
ID int64
OrgID string
Principal string
Action string
ResourceKind string
ResourceID string
Level string
Policies []string
MinuteAt time.Time
Count int64
CreatedAt time.Time
UpdatedAt time.Time
}
type AccessPolicy struct {
Level string
OrgID string
WorkspaceID string
ObjectKind string
ObjectID string
PolicyID string
Text string
UpdatedAt time.Time
}
type AccessPolicyVersion struct {
Level string
OrgID string
WorkspaceID string
Version int64
UpdatedAt time.Time
}
type ApplyStatus struct {
Process string
Kind string
AppliedVersion int64
Error string
ReportedAt time.Time
}
type Binding struct {
ID string
Name string
Source string
Mapping string
Workflow string
Owner string
Repo string
Version int64
Status string
Secret string
CreatedAt time.Time
UpdatedAt time.Time
Filter string
Inputs string
RepoParam string
OrgID string
WorkspaceID string
}
type BindingDispatch struct {
Binding string
BindingVersion int64
Capture string
TaskID int64
DispatchedAt time.Time
}
type Capture struct {
ID string
Source string
RemoteAddr string
ContentType string
Headers string
Body string
Authenticated bool
ReceivedAt time.Time
Unsigned bool
EventType string
OrgID string
WorkspaceID string
}
type ChannelStatus struct {
ID string
Name string
State string
Detail string
Configured bool
ReloadSupported bool
ObservedAt time.Time
}
type ConfigSnapshot struct {
ID int64
Schema string
Document string
PublishedAt time.Time
}
type Event struct {
ID int64
At time.Time
Kind string
TaskID int64
Repo string
Issue int64
Workflow string
Stage string
Attempt int64
ActorID string
ActorKind string
PrincipalID string
Detail string
Data string
OrgID string
WorkspaceID string
}
type EventType struct {
ID string
Source string
Name string
Rule string
Schema string
CreatedAt time.Time
UpdatedAt time.Time
OrgID string
WorkspaceID string
}
type Identity struct {
ID string
Kind string
DisplayName string
Lifecycle string
Version int64
CreatedAt time.Time
UpdatedAt time.Time
}
type IdentityAlias struct {
Alias string
IdentityID string
}
type IdentityEvent struct {
ID int64
IdentityID string
EventType string
FromLifecycle string
ToLifecycle string
DisplayName string
ActorID string
Source string
RequestID string
At time.Time
}
type IdentitySubject struct {
Issuer string
Subject string
IdentityID string
BoundAt time.Time
}
type InstalledPackage struct {
OrgID string
Name string
Reference string
Digest string
Descriptor []byte
Layer []byte
UpdatePolicy string
InstalledAt time.Time
}
type InstalledPackageRequirement struct {
OrgID string
PackageName string
RequiredName string
RequiredDigest string
}
type Mapping struct {
ID string
Name string
SourceHint string
Fields string
CreatedAt time.Time
UpdatedAt time.Time
EventType string
OrgID string
WorkspaceID string
}
type MappingMatch struct {
Mapping string
Capture string
MatchedAt time.Time
}
type Membership struct {
IdentityID string
OrgID string
WorkspaceID pgtype.Text
Role string
CreatedAt time.Time
}
type Message struct {
ID int64
MessageID string
SessionID string
SourceID string
Sender string
SenderID string
Role string
Text string
Ts int64
Search interface{}
}
type Org struct {
ID string
Name string
CreatedAt time.Time
UpdatedAt time.Time
}
type OrgAgent struct {
IdentityID string
OrgID string
CreatedAt time.Time
}
type OrgUpgrade struct {
Phase string
CompletedAt time.Time
}
type PlaybookDispatch struct {
PlaybookID string
PlaybookVersion string
EventID string
ActionID string
DispatchedAt time.Time
}
type Resource struct {
Kind string
Value []byte
Version int64
UpdatedAt time.Time
OrgID string
}
type ResourceHistory struct {
ID int64
Kind string
Value []byte
Version int64
Actor string
Source string
RequestID string
ExpectedVersion int64
CurrentVersion int64
At time.Time
OrgID string
}
type Session struct {
SessionID string
Platform string
BotUser string
ChannelID string
ThreadID string
Title string
ParentSessionID string
BranchName string
CreatedAt int64
LastActiveAt int64
}
type Source struct {
Path string
Signing string
Secret string
CreatedAt time.Time
UpdatedAt time.Time
OrgID string
WorkspaceID string
}
type StepExecution struct {
ID int64
OrgID string
WorkspaceID string
ExecutionID int64
Attempt int64
ParentID pgtype.Int8
Depth int32
Kind string
Name string
CalledExecutionID int64
Status string
Detail string
TokensUsed int64
StartedAt pgtype.Timestamptz
FinishedAt pgtype.Timestamptz
}
type SysAudit struct {
ID int64
At time.Time
TableName string
RecordKey string
Field string
OldValue []byte
NewValue []byte
RecordVersion int64
Actor string
Source string
RequestID string
}
type Task struct {
ID int64
Owner string
Repo string
IssueNumber int64
Title string
Body string
Labels string
Status string
Workflow string
Stage string
Branch string
Plan string
Notes string
PrNumber int64
TokensUsed int64
Iterations int64
Attempt int64
ParkReason string
WatchCommentID int64
ParkClass string
RemediationRounds int64
RetryCount int64
Source string
Identity string
BindingID string
BindingVersion int64
ReviewPayload string
WorkflowDefinitionVersion int64
WorkflowDefinitionDigest string
WorkflowDefinitionYaml string
CreatedAt time.Time
UpdatedAt time.Time
ReviewCursor int64
Inputs string
OrgID string
WorkspaceID string
CallParentTaskID int64
CallDepth int32
}
type ToolCall struct {
ID string
TaskID int64
Attempt int64
Tool string
Args string
Result string
Error string
DurationMs int64
CalledAt time.Time
OrgID string
WorkspaceID string
}
type Transition struct {
ID int64
TaskID int64
At time.Time
FromStatus string
ToStatus string
Detail string
OrgID string
WorkspaceID string
}
type Turn struct {
TurnID string
SessionID string
SourceID string
Status string
Attempt int64
OwnerID string
InputMessageID string
AssistantMessageID string
PartialText string
ResponseText string
ToolCalls string
Error string
CreatedAt int64
UpdatedAt int64
}
type Workspace struct {
ID string
OrgID string
Name string
Environment string
CreatedAt time.Time
UpdatedAt time.Time
}