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
@@ -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
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user