fix(archied): post each reportable status a chat task reaches, recorded by status not by flag
This commit is contained in:
1 parent
1a386dae7e
commit
4e2edc911f
13 files changed
+85
-51
No files matched your search
@@ -0,0 +1,18 @@
|
||||
-- A chat task's conversation is told about each state worth reporting (an
|
||||
-- approval request, an open pull request, a final outcome). Recording which
|
||||
-- status was posted, rather than whether anything was, makes every status
|
||||
-- change due for posting without each write path having to reset a flag.
|
||||
|
||||
-- +goose Up
|
||||
ALTER TABLE tasks ADD COLUMN outcome_posted_status text NOT NULL DEFAULT '';
|
||||
UPDATE tasks SET outcome_posted_status = status WHERE outcome_posted;
|
||||
DROP INDEX IF EXISTS idx_tasks_outcome_unposted;
|
||||
ALTER TABLE tasks DROP COLUMN outcome_posted;
|
||||
CREATE INDEX idx_tasks_outcome_unposted ON tasks (id) WHERE origin <> '' AND outcome_posted_status <> status;
|
||||
|
||||
-- +goose Down
|
||||
DROP INDEX IF EXISTS idx_tasks_outcome_unposted;
|
||||
ALTER TABLE tasks ADD COLUMN outcome_posted boolean NOT NULL DEFAULT false;
|
||||
UPDATE tasks SET outcome_posted = outcome_posted_status = status;
|
||||
ALTER TABLE tasks DROP COLUMN outcome_posted_status;
|
||||
CREATE INDEX idx_tasks_outcome_unposted ON tasks (id) WHERE origin <> '' AND NOT outcome_posted;
|
||||
@@ -24,7 +24,7 @@ func (q *Queries) CallStatusDetail(ctx context.Context, taskID int64) (string, e
|
||||
|
||||
const enqueueCallTask = `-- name: EnqueueCallTask :one
|
||||
WITH caller AS (
|
||||
SELECT t.id, t.owner, t.repo, t.issue_number, t.title, t.body, t.labels, t.status, t.workflow, t.branch, t.plan, t.notes, t.pr_number, t.tokens_used, t.iterations, t.attempt, t.park_reason, t.watch_comment_id, t.park_class, t.remediation_rounds, t.retry_count, t.source, t.identity, t.binding_id, t.binding_version, t.review_payload, t.workflow_definition_version, t.workflow_definition_digest, t.workflow_definition_yaml, t.created_at, t.updated_at, t.review_cursor, t.inputs, t.org_id, t.workspace_id, t.call_parent_task_id, t.call_depth, t.outputs, t.review_gate, t.rereview_rounds, t.retry_mode, t.resume_from, t.resume_results, t.pending_reviews, t.origin, t.call_key, t.outcome_posted, t.binding_signature, t.binding_addr, t.park_blocker FROM tasks t WHERE t.id = $1 FOR UPDATE
|
||||
SELECT t.id, t.owner, t.repo, t.issue_number, t.title, t.body, t.labels, t.status, t.workflow, t.branch, t.plan, t.notes, t.pr_number, t.tokens_used, t.iterations, t.attempt, t.park_reason, t.watch_comment_id, t.park_class, t.remediation_rounds, t.retry_count, t.source, t.identity, t.binding_id, t.binding_version, t.review_payload, t.workflow_definition_version, t.workflow_definition_digest, t.workflow_definition_yaml, t.created_at, t.updated_at, t.review_cursor, t.inputs, t.org_id, t.workspace_id, t.call_parent_task_id, t.call_depth, t.outputs, t.review_gate, t.rereview_rounds, t.retry_mode, t.resume_from, t.resume_results, t.pending_reviews, t.origin, t.call_key, t.binding_signature, t.binding_addr, t.park_blocker, t.outcome_posted_status FROM tasks t WHERE t.id = $1 FOR UPDATE
|
||||
), number AS (
|
||||
INSERT INTO chat_issue_numbers (owner, repo, last_number)
|
||||
SELECT caller.owner, caller.repo, $9::bigint + 1 FROM caller
|
||||
@@ -43,7 +43,7 @@ SELECT
|
||||
FROM caller, number
|
||||
WHERE caller.status = 'running' AND caller.call_depth + 1 <= $8::int
|
||||
ON CONFLICT (call_parent_task_id, call_key) WHERE call_key <> '' AND status NOT IN ('dead', 'closed_wont_do') DO UPDATE SET call_key = EXCLUDED.call_key
|
||||
RETURNING id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, outcome_posted, binding_signature, binding_addr, park_blocker
|
||||
RETURNING id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, binding_signature, binding_addr, park_blocker, outcome_posted_status
|
||||
`
|
||||
|
||||
type EnqueueCallTaskParams struct {
|
||||
@@ -132,10 +132,10 @@ func (q *Queries) EnqueueCallTask(ctx context.Context, arg EnqueueCallTaskParams
|
||||
&i.PendingReviews,
|
||||
&i.Origin,
|
||||
&i.CallKey,
|
||||
&i.OutcomePosted,
|
||||
&i.BindingSignature,
|
||||
&i.BindingAddr,
|
||||
&i.ParkBlocker,
|
||||
&i.OutcomePostedStatus,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -538,10 +538,10 @@ type Task struct {
|
||||
PendingReviews []byte
|
||||
Origin string
|
||||
CallKey string
|
||||
OutcomePosted bool
|
||||
BindingSignature string
|
||||
BindingAddr string
|
||||
ParkBlocker string
|
||||
OutcomePostedStatus string
|
||||
}
|
||||
|
||||
type ToolCall struct {
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
)
|
||||
|
||||
const activeTasksByOrigin = `-- name: ActiveTasksByOrigin :many
|
||||
SELECT id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, outcome_posted, binding_signature, binding_addr, park_blocker FROM tasks
|
||||
SELECT id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, binding_signature, binding_addr, park_blocker, outcome_posted_status FROM tasks
|
||||
WHERE origin = $1 AND origin <> '' AND status IN ('queued', 'running') AND ($2::text IS NULL OR org_id = $2)
|
||||
ORDER BY id
|
||||
`
|
||||
@@ -80,10 +80,10 @@ func (q *Queries) ActiveTasksByOrigin(ctx context.Context, arg ActiveTasksByOrig
|
||||
&i.PendingReviews,
|
||||
&i.Origin,
|
||||
&i.CallKey,
|
||||
&i.OutcomePosted,
|
||||
&i.BindingSignature,
|
||||
&i.BindingAddr,
|
||||
&i.ParkBlocker,
|
||||
&i.OutcomePostedStatus,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -140,7 +140,7 @@ func (q *Queries) ArchiveTaskDelete(ctx context.Context, arg ArchiveTaskDeletePa
|
||||
}
|
||||
|
||||
const beginRemediationTask = `-- name: BeginRemediationTask :execrows
|
||||
UPDATE tasks SET status = 'queued', workflow = 'remediate', park_reason = '', park_class = 'needs_human', review_payload = $2, outcome_posted = false, retry_mode = 'continue_pushed_work', resume_from = '', resume_results = '{}', updated_at = now()
|
||||
UPDATE tasks SET status = 'queued', workflow = 'remediate', park_reason = '', park_class = 'needs_human', review_payload = $2, retry_mode = 'continue_pushed_work', resume_from = '', resume_results = '{}', updated_at = now()
|
||||
WHERE id = $1 AND status = 'pr_open'
|
||||
`
|
||||
|
||||
@@ -163,7 +163,7 @@ func (q *Queries) BeginRemediationTask(ctx context.Context, arg BeginRemediation
|
||||
const claimByIssue = `-- name: ClaimByIssue :one
|
||||
UPDATE tasks SET status = 'running', attempt = attempt + 1, outputs = '', updated_at = now()
|
||||
WHERE owner = $1 AND repo = $2 AND issue_number = $3 AND status = 'queued'
|
||||
RETURNING id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, outcome_posted, binding_signature, binding_addr, park_blocker
|
||||
RETURNING id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, binding_signature, binding_addr, park_blocker, outcome_posted_status
|
||||
`
|
||||
|
||||
type ClaimByIssueParams struct {
|
||||
@@ -224,10 +224,10 @@ func (q *Queries) ClaimByIssue(ctx context.Context, arg ClaimByIssueParams) (Tas
|
||||
&i.PendingReviews,
|
||||
&i.Origin,
|
||||
&i.CallKey,
|
||||
&i.OutcomePosted,
|
||||
&i.BindingSignature,
|
||||
&i.BindingAddr,
|
||||
&i.ParkBlocker,
|
||||
&i.OutcomePostedStatus,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -242,7 +242,7 @@ WHERE id = (
|
||||
FOR UPDATE SKIP LOCKED
|
||||
LIMIT 1
|
||||
)
|
||||
RETURNING id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, outcome_posted, binding_signature, binding_addr, park_blocker
|
||||
RETURNING id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, binding_signature, binding_addr, park_blocker, outcome_posted_status
|
||||
`
|
||||
|
||||
// FOR UPDATE SKIP LOCKED replaces the SQLite single-writer assumption: two
|
||||
@@ -301,10 +301,10 @@ func (q *Queries) ClaimNextTask(ctx context.Context) (Task, error) {
|
||||
&i.PendingReviews,
|
||||
&i.Origin,
|
||||
&i.CallKey,
|
||||
&i.OutcomePosted,
|
||||
&i.BindingSignature,
|
||||
&i.BindingAddr,
|
||||
&i.ParkBlocker,
|
||||
&i.OutcomePostedStatus,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -422,7 +422,7 @@ FROM number, (SELECT COALESCE(
|
||||
'org-sys'
|
||||
) AS id) AS owner_org
|
||||
WHERE $11::text IS NULL OR owner_org.id = $11
|
||||
RETURNING id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, outcome_posted, binding_signature, binding_addr, park_blocker
|
||||
RETURNING id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, binding_signature, binding_addr, park_blocker, outcome_posted_status
|
||||
`
|
||||
|
||||
type InsertChatTaskParams struct {
|
||||
@@ -515,10 +515,10 @@ func (q *Queries) InsertChatTask(ctx context.Context, arg InsertChatTaskParams)
|
||||
&i.PendingReviews,
|
||||
&i.Origin,
|
||||
&i.CallKey,
|
||||
&i.OutcomePosted,
|
||||
&i.BindingSignature,
|
||||
&i.BindingAddr,
|
||||
&i.ParkBlocker,
|
||||
&i.OutcomePostedStatus,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -750,11 +750,17 @@ func (q *Queries) LockTaskStatus(ctx context.Context, id int64) (string, error)
|
||||
}
|
||||
|
||||
const markOutcomePosted = `-- name: MarkOutcomePosted :exec
|
||||
UPDATE tasks SET outcome_posted = true WHERE id = $1
|
||||
UPDATE tasks SET outcome_posted_status = $2 WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) MarkOutcomePosted(ctx context.Context, id int64) error {
|
||||
_, err := q.db.Exec(ctx, markOutcomePosted, id)
|
||||
type MarkOutcomePostedParams struct {
|
||||
ID int64
|
||||
OutcomePostedStatus string
|
||||
}
|
||||
|
||||
// Records the status whose state reached the task's conversation.
|
||||
func (q *Queries) MarkOutcomePosted(ctx context.Context, arg MarkOutcomePostedParams) error {
|
||||
_, err := q.db.Exec(ctx, markOutcomePosted, arg.ID, arg.OutcomePostedStatus)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -788,7 +794,7 @@ func (q *Queries) ParkTask(ctx context.Context, arg ParkTaskParams) (int64, erro
|
||||
|
||||
const promotePendingReview = `-- name: PromotePendingReview :execrows
|
||||
UPDATE tasks SET status = 'queued', workflow = 'remediate', park_reason = '',
|
||||
park_class = 'needs_human', outcome_posted = false,
|
||||
park_class = 'needs_human',
|
||||
review_payload = pending_reviews->>0, pending_reviews = pending_reviews - 0,
|
||||
retry_mode = 'continue_pushed_work', resume_from = '', resume_results = '{}',
|
||||
updated_at = now()
|
||||
@@ -992,7 +998,7 @@ func (q *Queries) StampTaskBinding(ctx context.Context, arg StampTaskBindingPara
|
||||
}
|
||||
|
||||
const taskByID = `-- name: TaskByID :one
|
||||
SELECT id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, outcome_posted, binding_signature, binding_addr, park_blocker FROM tasks WHERE id = $1 AND ($2::text IS NULL OR org_id = $2)
|
||||
SELECT id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, binding_signature, binding_addr, park_blocker, outcome_posted_status FROM tasks WHERE id = $1 AND ($2::text IS NULL OR org_id = $2)
|
||||
`
|
||||
|
||||
type TaskByIDParams struct {
|
||||
@@ -1050,16 +1056,16 @@ func (q *Queries) TaskByID(ctx context.Context, arg TaskByIDParams) (Task, error
|
||||
&i.PendingReviews,
|
||||
&i.Origin,
|
||||
&i.CallKey,
|
||||
&i.OutcomePosted,
|
||||
&i.BindingSignature,
|
||||
&i.BindingAddr,
|
||||
&i.ParkBlocker,
|
||||
&i.OutcomePostedStatus,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const taskByIssue = `-- name: TaskByIssue :one
|
||||
SELECT id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, outcome_posted, binding_signature, binding_addr, park_blocker FROM tasks WHERE owner = $1 AND repo = $2 AND issue_number = $3
|
||||
SELECT id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, binding_signature, binding_addr, park_blocker, outcome_posted_status FROM tasks WHERE owner = $1 AND repo = $2 AND issue_number = $3
|
||||
AND ($4::text IS NULL OR org_id = $4)
|
||||
`
|
||||
|
||||
@@ -1125,16 +1131,16 @@ func (q *Queries) TaskByIssue(ctx context.Context, arg TaskByIssueParams) (Task,
|
||||
&i.PendingReviews,
|
||||
&i.Origin,
|
||||
&i.CallKey,
|
||||
&i.OutcomePosted,
|
||||
&i.BindingSignature,
|
||||
&i.BindingAddr,
|
||||
&i.ParkBlocker,
|
||||
&i.OutcomePostedStatus,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const taskByPR = `-- name: TaskByPR :one
|
||||
SELECT id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, outcome_posted, binding_signature, binding_addr, park_blocker FROM tasks WHERE owner = $1 AND repo = $2 AND pr_number = $3 AND status = $4
|
||||
SELECT id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, binding_signature, binding_addr, park_blocker, outcome_posted_status FROM tasks WHERE owner = $1 AND repo = $2 AND pr_number = $3 AND status = $4
|
||||
AND ($5::text IS NULL OR org_id = $5)
|
||||
`
|
||||
|
||||
@@ -1205,10 +1211,10 @@ func (q *Queries) TaskByPR(ctx context.Context, arg TaskByPRParams) (Task, error
|
||||
&i.PendingReviews,
|
||||
&i.Origin,
|
||||
&i.CallKey,
|
||||
&i.OutcomePosted,
|
||||
&i.BindingSignature,
|
||||
&i.BindingAddr,
|
||||
&i.ParkBlocker,
|
||||
&i.OutcomePostedStatus,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -1216,7 +1222,6 @@ func (q *Queries) TaskByPR(ctx context.Context, arg TaskByPRParams) (Task, error
|
||||
const transitionTask = `-- name: TransitionTask :execrows
|
||||
UPDATE tasks
|
||||
SET status = $2,
|
||||
outcome_posted = CASE WHEN status IN ('waiting_approval', 'pr_open') THEN false ELSE outcome_posted END,
|
||||
park_reason = CASE WHEN $2 = 'parked' THEN $3 ELSE park_reason END,
|
||||
park_class = CASE WHEN $2 = 'parked' THEN $4 ELSE park_class END,
|
||||
park_blocker = CASE WHEN $2 = 'parked' THEN '' ELSE park_blocker END,
|
||||
@@ -1234,8 +1239,6 @@ type TransitionTaskParams struct {
|
||||
|
||||
// Arriving at 'parked' also records why. The class is normalized by the
|
||||
// caller, so an unknown value persists as needs_human rather than as itself.
|
||||
// Leaving a state the conversation was told about (an approval request, an
|
||||
// open pull request) clears outcome_posted, so the next state is posted too.
|
||||
func (q *Queries) TransitionTask(ctx context.Context, arg TransitionTaskParams) (int64, error) {
|
||||
result, err := q.db.Exec(ctx, transitionTask,
|
||||
arg.ID,
|
||||
@@ -1251,8 +1254,8 @@ func (q *Queries) TransitionTask(ctx context.Context, arg TransitionTaskParams)
|
||||
}
|
||||
|
||||
const unpostedOutcomes = `-- name: UnpostedOutcomes :many
|
||||
SELECT id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, outcome_posted, binding_signature, binding_addr, park_blocker FROM tasks
|
||||
WHERE origin <> '' AND NOT outcome_posted
|
||||
SELECT id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, binding_signature, binding_addr, park_blocker, outcome_posted_status FROM tasks
|
||||
WHERE origin <> '' AND outcome_posted_status <> status
|
||||
AND status IN ('merged', 'rejected', 'dead', 'closed_wont_do', 'completed', 'waiting_approval', 'pr_open')
|
||||
AND ($1::text IS NULL OR org_id = $1)
|
||||
ORDER BY id
|
||||
@@ -1317,10 +1320,10 @@ func (q *Queries) UnpostedOutcomes(ctx context.Context, scopeOrg pgtype.Text) ([
|
||||
&i.PendingReviews,
|
||||
&i.Origin,
|
||||
&i.CallKey,
|
||||
&i.OutcomePosted,
|
||||
&i.BindingSignature,
|
||||
&i.BindingAddr,
|
||||
&i.ParkBlocker,
|
||||
&i.OutcomePostedStatus,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -105,14 +105,15 @@ ORDER BY id;
|
||||
-- Chat tasks that finished, wait for approval or have a pull request open,
|
||||
-- whose state has not reached their conversation yet.
|
||||
SELECT * FROM tasks
|
||||
WHERE origin <> '' AND NOT outcome_posted
|
||||
WHERE origin <> '' AND outcome_posted_status <> status
|
||||
AND status IN ('merged', 'rejected', 'dead', 'closed_wont_do', 'completed', 'waiting_approval', 'pr_open')
|
||||
AND (sqlc.narg(scope_org)::text IS NULL OR org_id = sqlc.narg(scope_org))
|
||||
ORDER BY id
|
||||
LIMIT 50;
|
||||
|
||||
-- name: MarkOutcomePosted :exec
|
||||
UPDATE tasks SET outcome_posted = true WHERE id = $1;
|
||||
-- Records the status whose state reached the task's conversation.
|
||||
UPDATE tasks SET outcome_posted_status = $2 WHERE id = $1;
|
||||
|
||||
-- name: StampTaskBinding :exec
|
||||
-- The capture's signature result is spelled as the access context spells it.
|
||||
@@ -152,11 +153,8 @@ SELECT status FROM tasks WHERE id = $1 FOR UPDATE;
|
||||
-- name: TransitionTask :execrows
|
||||
-- Arriving at 'parked' also records why. The class is normalized by the
|
||||
-- caller, so an unknown value persists as needs_human rather than as itself.
|
||||
-- Leaving a state the conversation was told about (an approval request, an
|
||||
-- open pull request) clears outcome_posted, so the next state is posted too.
|
||||
UPDATE tasks
|
||||
SET status = $2,
|
||||
outcome_posted = CASE WHEN status IN ('waiting_approval', 'pr_open') THEN false ELSE outcome_posted END,
|
||||
park_reason = CASE WHEN $2 = 'parked' THEN $3 ELSE park_reason END,
|
||||
park_class = CASE WHEN $2 = 'parked' THEN $4 ELSE park_class END,
|
||||
park_blocker = CASE WHEN $2 = 'parked' THEN '' ELSE park_blocker END,
|
||||
@@ -210,7 +208,7 @@ RETURNING *;
|
||||
-- A remediation must continue the branch its pull request lives on, so it
|
||||
-- records that dispatch mode explicitly (taskstate.RetryContinuePushedWork)
|
||||
-- rather than leaving prepareWorkspace to infer it from the workflow.
|
||||
UPDATE tasks SET status = 'queued', workflow = 'remediate', park_reason = '', park_class = 'needs_human', review_payload = $2, outcome_posted = false, retry_mode = 'continue_pushed_work', resume_from = '', resume_results = '{}', updated_at = now()
|
||||
UPDATE tasks SET status = 'queued', workflow = 'remediate', park_reason = '', park_class = 'needs_human', review_payload = $2, retry_mode = 'continue_pushed_work', resume_from = '', resume_results = '{}', updated_at = now()
|
||||
WHERE id = $1 AND status = 'pr_open';
|
||||
|
||||
-- name: AppendPendingReview :execrows
|
||||
@@ -231,7 +229,7 @@ WHERE id = $1 AND status IN ('queued', 'running') AND workflow = 'remediate';
|
||||
-- waiting: the oldest becomes the active payload and the task is queued
|
||||
-- again, so it is remediated after the run that just finished.
|
||||
UPDATE tasks SET status = 'queued', workflow = 'remediate', park_reason = '',
|
||||
park_class = 'needs_human', outcome_posted = false,
|
||||
park_class = 'needs_human',
|
||||
review_payload = pending_reviews->>0, pending_reviews = pending_reviews - 0,
|
||||
retry_mode = 'continue_pushed_work', resume_from = '', resume_results = '{}',
|
||||
updated_at = now()
|
||||
|
||||
@@ -954,9 +954,10 @@ func (s *Store) UnpostedOutcomes(ctx context.Context) ([]*workflow.Task, error)
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// MarkOutcomePosted records that a task's outcome reached its conversation.
|
||||
func (s *Store) MarkOutcomePosted(ctx context.Context, taskID int64) error {
|
||||
if err := s.queries().MarkOutcomePosted(ctx, taskID); err != nil {
|
||||
// MarkOutcomePosted records that the task's state at status reached its
|
||||
// conversation.
|
||||
func (s *Store) MarkOutcomePosted(ctx context.Context, taskID int64, status string) error {
|
||||
if err := s.queries().MarkOutcomePosted(ctx, postgresdb.MarkOutcomePostedParams{ID: taskID, OutcomePostedStatus: status}); err != nil {
|
||||
return fmt.Errorf("store: mark outcome posted: %w", err)
|
||||
}
|
||||
return nil
|
||||
|
||||
Reference in new issue
Block a user