refactor: strip doc and issue narration from code comments
Remove PRD/doc paths, bead IDs, phase notes and deleted-test references from comments; drop test-only hooks left by the test deletion. Includes in-progress archied bootstrap, gateway and query changes.
This commit is contained in:
269 files changed
+1201
-2609
No files matched your search
@@ -1,6 +1,6 @@
|
||||
// Access policies and denial records: the Postgres implementation of
|
||||
// internal/domain/access's PolicyStore, Resetter and DenialStore
|
||||
// (docs/prds/orgs-and-access.md). Policy changes are versioned per level
|
||||
// internal/domain/access's PolicyStore, Resetter and DenialStore.
|
||||
// Policy changes are versioned per level
|
||||
// scope and audited as one sys_audit row per change naming who made it.
|
||||
package postgres
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// Orgs, workspaces, memberships and agent assignments: the Postgres
|
||||
// implementation of internal/domain/org's contracts, plus the resumable
|
||||
// default org/workspace upgrade the State Store runs at boot
|
||||
// (docs/prds/orgs-and-access.md, "Upgrading existing installs").
|
||||
//
|
||||
// The upgrade refuses nothing itself; the refusal to serve scoped calls
|
||||
// until it has finished is enforced by the boot order -- the State Store
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
// Package pgtest runs a throwaway PostgreSQL 18 container for one test binary
|
||||
// and gives each test its own database on it.
|
||||
//
|
||||
// A package using it calls Main from TestMain:
|
||||
//
|
||||
// func TestMain(m *testing.M) { os.Exit(pgtest.Main(m)) }
|
||||
//
|
||||
// It needs a running Docker daemon.
|
||||
|
||||
@@ -19,9 +19,6 @@ type CountShippedOrgPoliciesParams struct {
|
||||
Column2 []string
|
||||
}
|
||||
|
||||
// How many of an org's shipped role policies are stored. The seeding runs
|
||||
// only when the org carries none of them, so a restart never overwrites an
|
||||
// edited role policy (the shipped IDs are reserved for the shipped text).
|
||||
func (q *Queries) CountShippedOrgPolicies(ctx context.Context, arg CountShippedOrgPoliciesParams) (int64, error) {
|
||||
row := q.db.QueryRow(ctx, countShippedOrgPolicies, arg.OrgID, arg.Column2)
|
||||
var count int64
|
||||
@@ -72,7 +69,6 @@ type DeleteAccessPolicyVersionParams struct {
|
||||
WorkspaceID string
|
||||
}
|
||||
|
||||
// Tidy a level-scope with no policies left: its version row has no reader.
|
||||
func (q *Queries) DeleteAccessPolicyVersion(ctx context.Context, arg DeleteAccessPolicyVersionParams) error {
|
||||
_, err := q.db.Exec(ctx, deleteAccessPolicyVersion, arg.Level, arg.OrgID, arg.WorkspaceID)
|
||||
return err
|
||||
@@ -88,8 +84,6 @@ type DeleteOrgPoliciesNotShippedParams struct {
|
||||
Column2 []string
|
||||
}
|
||||
|
||||
// The org reset's removal half: every org-level policy except the shipped
|
||||
// role set.
|
||||
func (q *Queries) DeleteOrgPoliciesNotShipped(ctx context.Context, arg DeleteOrgPoliciesNotShippedParams) error {
|
||||
_, err := q.db.Exec(ctx, deleteOrgPoliciesNotShipped, arg.OrgID, arg.Column2)
|
||||
return err
|
||||
@@ -139,8 +133,6 @@ type InsertAccessPolicyAuditParams struct {
|
||||
RequestID string
|
||||
}
|
||||
|
||||
// One audit row per policy change: the policy's old and new text
|
||||
// (docs/prds/orgs-and-access.md, "Storing and changing policies").
|
||||
func (q *Queries) InsertAccessPolicyAudit(ctx context.Context, arg InsertAccessPolicyAuditParams) error {
|
||||
_, err := q.db.Exec(ctx, insertAccessPolicyAudit,
|
||||
arg.RecordKey,
|
||||
@@ -159,9 +151,6 @@ INSERT INTO sys_audit (at, table_name, record_key, field, record_version, actor,
|
||||
VALUES (now(), 'access_policies', $1, 'reset', 1, 'archied access reset', 'archied', '')
|
||||
`
|
||||
|
||||
// The one audit row a reset is recorded as; the reset's policy changes
|
||||
// carry their own rows (docs/prds/orgs-and-access.md, "Recovering from a
|
||||
// locked-out org").
|
||||
func (q *Queries) InsertAccessResetAudit(ctx context.Context, recordKey string) error {
|
||||
_, err := q.db.Exec(ctx, insertAccessResetAudit, recordKey)
|
||||
return err
|
||||
@@ -173,9 +162,7 @@ SELECT level, org_id, workspace_id, object_kind, object_id, policy_id, text, upd
|
||||
FROM access_policies ORDER BY level, org_id, workspace_id, object_kind, object_id, policy_id
|
||||
`
|
||||
|
||||
// Access policies and denial records (internal/domain/access): the durable
|
||||
// half of the policy-chain contract. Versioning is per level-scope; every
|
||||
// policy change writes one sys_audit row naming who made it.
|
||||
// Access policies and denial records (internal/domain/access)
|
||||
func (q *Queries) ListAccessPolicies(ctx context.Context) ([]AccessPolicy, error) {
|
||||
rows, err := q.db.Query(ctx, listAccessPolicies)
|
||||
if err != nil {
|
||||
@@ -266,8 +253,6 @@ type RecordDenialParams struct {
|
||||
}
|
||||
|
||||
// One row per (principal, action, resource, level, policies, minute);
|
||||
// a repeat inside the minute bumps the count (docs/prds/orgs-and-access.md,
|
||||
// "Audit retention").
|
||||
func (q *Queries) RecordDenial(ctx context.Context, arg RecordDenialParams) error {
|
||||
_, err := q.db.Exec(ctx, recordDenial,
|
||||
arg.OrgID,
|
||||
|
||||
@@ -81,8 +81,6 @@ type InsertResourceAuditParams struct {
|
||||
Value []byte
|
||||
}
|
||||
|
||||
// Records the fields one resource write changed, against the version it
|
||||
// replaced. Runs in the write's own transaction.
|
||||
func (q *Queries) InsertResourceAudit(ctx context.Context, arg InsertResourceAuditParams) error {
|
||||
_, err := q.db.Exec(ctx, insertResourceAudit,
|
||||
arg.At,
|
||||
|
||||
@@ -54,15 +54,7 @@ type EnqueueCallTaskParams struct {
|
||||
MaxDepth int32
|
||||
}
|
||||
|
||||
// The callee of a workflow.call step (docs/prds/workflow-calls.md). The
|
||||
// caller row is read FOR UPDATE, so two steps of the same run cannot race a
|
||||
// depth re-check, and the callee inherits the caller's org, workspace,
|
||||
// identity, owner and repo: a called workflow works the same run's context
|
||||
// under its own definition and profile. The issue number is a fresh
|
||||
// synthetic one for the inherited owner/repo, the same allocator
|
||||
// InsertChatTask uses. The insert refuses a caller that is not running and
|
||||
// a call that would pass the depth limit (the engine checks it too; the
|
||||
// store is what owns the table, so it re-checks).
|
||||
// The callee of a workflow.call step (docs/prds/workflow-calls.md)
|
||||
func (q *Queries) EnqueueCallTask(ctx context.Context, arg EnqueueCallTaskParams) (Task, error) {
|
||||
row := q.db.QueryRow(ctx, enqueueCallTask,
|
||||
arg.ID,
|
||||
|
||||
@@ -757,9 +757,6 @@ type ListUndispatchedCapturesParams struct {
|
||||
EntryLimit int32
|
||||
}
|
||||
|
||||
// A capture is undispatched while some armed binding on its source, whose
|
||||
// mapping belongs to the capture's event type, has not dispatched it. An
|
||||
// unidentified capture has no event type, so it is never listed.
|
||||
func (q *Queries) ListUndispatchedCaptures(ctx context.Context, arg ListUndispatchedCapturesParams) ([]Capture, error) {
|
||||
rows, err := q.db.Query(ctx, listUndispatchedCaptures, arg.Sources, arg.EntryLimit)
|
||||
if err != nil {
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
-- Access policies and denial records (internal/domain/access): the durable
|
||||
-- half of the policy-chain contract. Versioning is per level-scope; every
|
||||
-- policy change writes one sys_audit row naming who made it.
|
||||
-- Access policies and denial records (internal/domain/access)
|
||||
|
||||
-- name: ListAccessPolicies :many
|
||||
SELECT level, org_id, workspace_id, object_kind, object_id, policy_id, text, updated_at
|
||||
@@ -23,15 +21,10 @@ WHERE level = $1 AND org_id = $2 AND workspace_id = $3 AND object_kind = $4
|
||||
AND object_id = $5 AND policy_id = $6;
|
||||
|
||||
-- name: CountShippedOrgPolicies :one
|
||||
-- How many of an org's shipped role policies are stored. The seeding runs
|
||||
-- only when the org carries none of them, so a restart never overwrites an
|
||||
-- edited role policy (the shipped IDs are reserved for the shipped text).
|
||||
SELECT count(*) FROM access_policies
|
||||
WHERE level = 'org' AND org_id = $1 AND policy_id = ANY($2::text[]);
|
||||
|
||||
-- name: DeleteOrgPoliciesNotShipped :exec
|
||||
-- The org reset's removal half: every org-level policy except the shipped
|
||||
-- role set.
|
||||
DELETE FROM access_policies
|
||||
WHERE level = 'org' AND org_id = $1 AND NOT (policy_id = ANY($2::text[]));
|
||||
|
||||
@@ -45,22 +38,17 @@ DO UPDATE SET version = access_policy_versions.version + 1, updated_at = now()
|
||||
RETURNING version;
|
||||
|
||||
-- name: DeleteAccessPolicyVersion :exec
|
||||
-- Tidy a level-scope with no policies left: its version row has no reader.
|
||||
DELETE FROM access_policy_versions v
|
||||
WHERE v.level = $1 AND v.org_id = $2 AND v.workspace_id = $3
|
||||
AND NOT EXISTS (SELECT 1 FROM access_policies p
|
||||
WHERE p.level = v.level AND p.org_id = v.org_id AND p.workspace_id = v.workspace_id);
|
||||
|
||||
-- name: InsertAccessPolicyAudit :exec
|
||||
-- One audit row per policy change: the policy's old and new text
|
||||
-- (docs/prds/orgs-and-access.md, "Storing and changing policies").
|
||||
INSERT INTO sys_audit (at, table_name, record_key, field, old_value, new_value, record_version, actor, source, request_id)
|
||||
VALUES (now(), 'access_policies', $1, 'text', $2, $3, $4, $5, $6, $7);
|
||||
|
||||
-- name: RecordDenial :exec
|
||||
-- One row per (principal, action, resource, level, policies, minute);
|
||||
-- a repeat inside the minute bumps the count (docs/prds/orgs-and-access.md,
|
||||
-- "Audit retention").
|
||||
INSERT INTO access_denials (org_id, principal, action, resource_kind, resource_id, level, policies)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
||||
ON CONFLICT (org_id, principal, action, resource_kind, resource_id, level, policies, minute_at)
|
||||
@@ -69,9 +57,7 @@ DO UPDATE SET count = access_denials.count + 1, updated_at = now();
|
||||
-- name: ListDenials :many
|
||||
SELECT id, org_id, principal, action, resource_kind, resource_id, level, policies, minute_at, count, created_at, updated_at
|
||||
FROM access_denials WHERE org_id = $1 ORDER BY id DESC LIMIT $2;
|
||||
|
||||
-- name: InsertAccessResetAudit :exec
|
||||
-- The one audit row a reset is recorded as; the reset's policy changes
|
||||
-- carry their own rows (docs/prds/orgs-and-access.md, "Recovering from a
|
||||
-- locked-out org").
|
||||
INSERT INTO sys_audit (at, table_name, record_key, field, record_version, actor, source, request_id)
|
||||
VALUES (now(), 'access_policies', $1, 'reset', 1, 'archied access reset', 'archied', '');
|
||||
@@ -1,6 +1,4 @@
|
||||
-- name: InsertResourceAudit :exec
|
||||
-- Records the fields one resource write changed, against the version it
|
||||
-- replaced. Runs in the write's own transaction.
|
||||
INSERT INTO sys_audit (at, table_name, record_key, field, old_value, new_value, record_version, actor, source, request_id)
|
||||
SELECT sqlc.arg(at)::timestamptz, 'resources', sqlc.arg(record_key)::text, d.field, d.old_value, d.new_value,
|
||||
sqlc.arg(version)::bigint, sqlc.arg(actor)::text, sqlc.arg(source)::text, sqlc.arg(request_id)::text
|
||||
|
||||
@@ -1,13 +1,5 @@
|
||||
-- name: EnqueueCallTask :one
|
||||
-- The callee of a workflow.call step (docs/prds/workflow-calls.md). The
|
||||
-- caller row is read FOR UPDATE, so two steps of the same run cannot race a
|
||||
-- depth re-check, and the callee inherits the caller's org, workspace,
|
||||
-- identity, owner and repo: a called workflow works the same run's context
|
||||
-- under its own definition and profile. The issue number is a fresh
|
||||
-- synthetic one for the inherited owner/repo, the same allocator
|
||||
-- InsertChatTask uses. The insert refuses a caller that is not running and
|
||||
-- a call that would pass the depth limit (the engine checks it too; the
|
||||
-- store is what owns the table, so it re-checks).
|
||||
-- The callee of a workflow.call step (docs/prds/workflow-calls.md)
|
||||
WITH caller AS (
|
||||
SELECT t.* FROM tasks t WHERE t.id = $1 FOR UPDATE
|
||||
)
|
||||
|
||||
@@ -11,9 +11,6 @@ ORDER BY received_at DESC
|
||||
LIMIT $1;
|
||||
|
||||
-- name: ListUndispatchedCaptures :many
|
||||
-- A capture is undispatched while some armed binding on its source, whose
|
||||
-- mapping belongs to the capture's event type, has not dispatched it. An
|
||||
-- unidentified capture has no event type, so it is never listed.
|
||||
SELECT c.id, c.source, c.remote_addr, c.content_type, c.headers, c.body, c.authenticated, c.received_at, c.unsigned, c.event_type, c.org_id, c.workspace_id
|
||||
FROM captures c
|
||||
WHERE c.source = ANY(@sources::text[])
|
||||
|
||||
@@ -16,13 +16,9 @@ import (
|
||||
"github.com/samcharles93/archie-core/internal/taskstate"
|
||||
)
|
||||
|
||||
// The step-execution writes of docs/prds/execution-tree-state-machine.md.
|
||||
// Each is one transaction: the guarded row write, and the domain event row
|
||||
// the step transition produces, so the events table records exactly the
|
||||
// transitions the step row does. The events land in the table; the caller
|
||||
// publishes the returned event to its bus after the write commits, and the
|
||||
// daemon's event sink skips already-persisted rows by their assigned ID --
|
||||
// the EmitDurable convention.
|
||||
// The events land in the table; the caller publishes the returned event to its
|
||||
// bus after the write commits, and the daemon's event sink skips
|
||||
// already-persisted rows by their assigned ID -- the EmitDurable convention.
|
||||
|
||||
// StartStep records a StepExecution entering running: the row is created
|
||||
// pending, guarded into running under the shared step transition table, and
|
||||
@@ -251,7 +247,7 @@ func stepEventData(to taskstate.StepStatus, durationMS int64, detail string) map
|
||||
|
||||
// ListSteps reads one execution's recorded steps, every attempt oldest first
|
||||
// when attempt is 0, or just the one it names. It is the dashboard run
|
||||
// detail's authoritative source (docs/prds/execution-tree-state-machine.md),
|
||||
// detail's authoritative source,
|
||||
// replacing the fold over stage_start/stage_finish events tasks.stage used to
|
||||
// back -- unlike StartStep/FinishStep, this is a plain read with no
|
||||
// transition to guard, so it takes no transaction.
|
||||
@@ -291,14 +287,14 @@ func stepParentID(parentID int64) pgtype.Int8 {
|
||||
return pgtype.Int8{Int64: parentID, Valid: parentID != 0}
|
||||
}
|
||||
|
||||
// CancelExecution is the one cancel path (docs/prds/execution-tree-state-machine.md,
|
||||
// "Cancellation"): one transaction moves every non-terminal StepExecution of
|
||||
// the execution's current attempt to cancelled -- one event row each -- and
|
||||
// the execution itself to the status the operator action names, under the
|
||||
// shared execution transition table. Staleness is decided before legality, as
|
||||
// guardTransition decides it, and the audit row lands in the same write. The
|
||||
// caller cancels the in-memory context after this commits; the worker's next
|
||||
// step write then fails ErrStaleTransition and stops.
|
||||
// CancelExecution is the one cancel path: one transaction moves every
|
||||
// non-terminal StepExecution of the execution's current attempt to cancelled --
|
||||
// one event row each -- and the execution itself to the status the operator
|
||||
// action names, under the shared execution transition table. Staleness is
|
||||
// decided before legality, as guardTransition decides it, and the audit row
|
||||
// lands in the same write. The caller cancels the in-memory context after this
|
||||
// commits; the worker's next step write then fails ErrStaleTransition and
|
||||
// stops.
|
||||
func (s *Store) CancelExecution(ctx context.Context, taskID int64, reason, to string) ([]int64, error) {
|
||||
tx, err := s.pool.Begin(ctx)
|
||||
if err != nil {
|
||||
|
||||
@@ -40,8 +40,8 @@ func (s *Store) queries() *postgresdb.Queries {
|
||||
// guardTransition locks the task's row and checks the status write the caller
|
||||
// is about to perform: a row whose status is not the expected from is stale
|
||||
// (ErrStaleTransition), a from->to pair outside the shared transition table is
|
||||
// refused with ErrIllegalTransition
|
||||
// (docs/prds/execution-tree-state-machine.md). Staleness is decided first, so
|
||||
// refused with ErrIllegalTransition.
|
||||
// Staleness is decided first, so
|
||||
// a caller that is wrong about the row's state gets the stale sentinel even
|
||||
// when its pair is also unroutable. The row stays locked for the caller's
|
||||
// transaction, so the checks cannot race the guarded write that follows.
|
||||
@@ -78,7 +78,7 @@ const syntheticIssueNumberBase = 1_000_000_000_000_000
|
||||
// structured payload (review_payload today, task outputs now). A value that
|
||||
// would exceed it is refused for outputs -- clipped JSON does not parse, and a
|
||||
// caller must receive an object or nothing -- where the legacy review payload
|
||||
// is still clipped (docs/prds/workflow-call-outputs.md, "Storage and wire").
|
||||
// is still clipped.
|
||||
const structuredPayloadBytes = 4000
|
||||
|
||||
// taskFromRow maps the generated task row to the workflow.Task the daemon and
|
||||
@@ -295,7 +295,7 @@ func (s *Store) ParkTask(ctx context.Context, taskID int64, from, detail, class
|
||||
|
||||
// Update persists mutable task fields written by workflows.
|
||||
func (s *Store) Update(ctx context.Context, t *workflow.Task) error {
|
||||
// The row write is where a run's outputs land (docs/prds/workflow-call-outputs.md).
|
||||
// The row write is where a run's outputs land.
|
||||
// An encoded set past the bound the store applies to a structured payload
|
||||
// is refused rather than clipped: clipped JSON does not parse, and a caller
|
||||
// would receive a broken object as a value. The engine turns the refusal
|
||||
@@ -414,8 +414,8 @@ func (s *Store) RetryTask(ctx context.Context, taskID int64, fromStatus, wf, ret
|
||||
})
|
||||
}
|
||||
|
||||
// RespondReviewGate is the review gate response write
|
||||
// (docs/prds/pr-review-operator-response.md, Decision 2): one guarded
|
||||
// RespondReviewGate is the review gate response write:
|
||||
// one guarded
|
||||
// requeue that records the operator's answer, increments rereview_rounds for
|
||||
// a re-review only, and writes one audit row -- all in one transaction. The
|
||||
// cap is checked under the row lock the transition guard takes, so two
|
||||
@@ -522,13 +522,9 @@ func (s *Store) ArchiveTask(ctx context.Context, taskID int64, fromStatus string
|
||||
|
||||
// RecoverStale re-queues tasks left running by a crashed or replaced daemon
|
||||
// and, in the same transaction, moves the steps those executions left running
|
||||
// to the step transition table's interrupted outcome
|
||||
// (docs/prds/execution-tree-state-machine.md, "Crash recovery"): one event row
|
||||
// per step transition and the execution's audit row land in the same write.
|
||||
// Both edges are pinned in SQL (the execution's running->queued, the step's
|
||||
// running->interrupted) and pinned to the tables by
|
||||
// TestSQLPinnedTransitionsAreTableLegal. The next attempt starts with fresh
|
||||
// steps; earlier attempts are never rewritten.
|
||||
// to the step transition table's interrupted outcome: one event row per step
|
||||
// transition and the execution's audit row land in the same write. The next
|
||||
// attempt starts with fresh steps; earlier attempts are never rewritten.
|
||||
func (s *Store) RecoverStale(ctx context.Context) (int64, error) {
|
||||
tx, err := s.pool.Begin(ctx)
|
||||
if err != nil {
|
||||
@@ -675,8 +671,8 @@ func (s *Store) TaskByID(ctx context.Context, taskID int64) (*workflow.Task, err
|
||||
return taskFromRow(t), nil
|
||||
}
|
||||
|
||||
// StartCall enqueues the callee of callerTaskID's workflow.call step
|
||||
// (docs/prds/workflow-calls.md). The store owns the table, so it re-checks
|
||||
// StartCall enqueues the callee of callerTaskID's workflow.call step.
|
||||
// The store owns the table, so it re-checks
|
||||
// both runtime invariants the engine checks: the caller must be running and
|
||||
// the call must not pass workflow.MaxCallDepth. The callee inherits the
|
||||
// caller's org, workspace, identity, owner and repo, and takes a fresh
|
||||
@@ -741,8 +737,8 @@ func (s *Store) CallStatus(ctx context.Context, callerTaskID, callTaskID int64)
|
||||
if callee.CallParentTaskID != callerTaskID {
|
||||
return "", "", nil, storecontract.ErrCallNotYours
|
||||
}
|
||||
// The row is the callee's own; its outputs travel beside status and detail
|
||||
// (docs/prds/workflow-call-outputs.md, "Storage and wire"). The caller
|
||||
// The row is the callee's own; its outputs travel beside status and detail.
|
||||
// The caller
|
||||
// decides whether to use them -- only a successful terminal state's values
|
||||
// reach it.
|
||||
outputs, _ := task.DecodeOutputs(callee.Outputs)
|
||||
|
||||
Reference in new issue
Block a user