feat(pr-review): operator/chat trigger queues a pr-review task

review_pr self-omitted since 7299b923 deleted the synchronous reviewer it
called. It is rebuilt on the task enqueue path everything else uses: the
tool resolves the identity's configured repo, then queues a pr-review task
naming the pull request through the workflow's declared pr_number input,
which is the same generic input mechanism a watched-repos binding uses.

That input has to reach the store with the task, so
EnqueueChatTaskRequest gains inputs_json and the tasks insert writes the
inputs column directly. StampTaskBinding no longer writes it: the insert is
now the column's only writer, and a chat task must not acquire binding
provenance just to carry an input.

ChatPRReviewer, its result shape and the reviewer wiring are deleted with
the path they served.
This commit is contained in:
sam committed 2026-09-28 18:24:36 +10:00
1 parent a6627954bd
commit 5c91575166
39 files changed
+227 -192

No files matched your search

@@ -138,7 +138,7 @@ func titles(t *testing.T, pool *pgxpool.Pool) []string {
func enqueue(t *testing.T, pool *pgxpool.Pool, title string) {
t.Helper()
if _, err := New(pool).EnqueueChatTask(t.Context(), "acme", "widget", title, "body", "implement", ""); err != nil {
if _, err := New(pool).EnqueueChatTask(t.Context(), "acme", "widget", title, "body", "implement", "", nil); err != nil {
t.Fatalf("enqueue %q: %v", title, err)
}
}
@@ -251,7 +251,7 @@ func (q *Queries) EnqueueIssue(ctx context.Context, arg EnqueueIssueParams) (int
}
const insertChatTask = `-- name: InsertChatTask :one
INSERT INTO tasks (owner, repo, issue_number, title, body, labels, workflow, source, identity, org_id)
INSERT INTO tasks (owner, repo, issue_number, title, body, labels, workflow, source, identity, org_id, inputs)
VALUES (
$1, $2,
COALESCE((
@@ -266,7 +266,8 @@ VALUES (
(SELECT m.org_id FROM memberships m WHERE m.identity_id = $7
ORDER BY m.created_at, m.org_id, m.workspace_id NULLS LAST LIMIT 1),
'default'
)
),
$8
)
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
`
@@ -279,12 +280,16 @@ type InsertChatTaskParams struct {
Body string
Workflow string
Identity string
Inputs string
}
// The synthetic issue number keeps chat-sourced tasks off the forge's real
// issue numbers; this allocator is the single source of truth for it.
// fallback_issue_number is only the seed for a repo's first chat task -- the
// passed value is not the issue number that lands.
// inputs is the chat task's own workflow inputs; a binding dispatch passes
// its inputs here too, so this insert is the single writer of the column and
// StampTaskBinding adds only the provenance.
func (q *Queries) InsertChatTask(ctx context.Context, arg InsertChatTaskParams) (Task, error) {
row := q.db.QueryRow(ctx, insertChatTask,
arg.Owner,
@@ -294,6 +299,7 @@ func (q *Queries) InsertChatTask(ctx context.Context, arg InsertChatTaskParams)
arg.Body,
arg.Workflow,
arg.Identity,
arg.Inputs,
)
var i Task
err := row.Scan(
@@ -599,23 +605,17 @@ func (q *Queries) SetReviewCursors(ctx context.Context, arg SetReviewCursorsPara
}
const stampTaskBinding = `-- name: StampTaskBinding :exec
UPDATE tasks SET binding_id = $2, binding_version = $3, inputs = $4 WHERE id = $1
UPDATE tasks SET binding_id = $2, binding_version = $3 WHERE id = $1
`
type StampTaskBindingParams struct {
ID int64
BindingID string
BindingVersion int64
Inputs string
}
func (q *Queries) StampTaskBinding(ctx context.Context, arg StampTaskBindingParams) error {
_, err := q.db.Exec(ctx, stampTaskBinding,
arg.ID,
arg.BindingID,
arg.BindingVersion,
arg.Inputs,
)
_, err := q.db.Exec(ctx, stampTaskBinding, arg.ID, arg.BindingID, arg.BindingVersion)
return err
}
@@ -42,7 +42,10 @@ SELECT status, count(*)::int AS count FROM tasks GROUP BY status;
-- issue numbers; this allocator is the single source of truth for it.
-- fallback_issue_number is only the seed for a repo's first chat task -- the
-- passed value is not the issue number that lands.
INSERT INTO tasks (owner, repo, issue_number, title, body, labels, workflow, source, identity, org_id)
-- inputs is the chat task's own workflow inputs; a binding dispatch passes
-- its inputs here too, so this insert is the single writer of the column and
-- StampTaskBinding adds only the provenance.
INSERT INTO tasks (owner, repo, issue_number, title, body, labels, workflow, source, identity, org_id, inputs)
VALUES (
sqlc.arg(owner), sqlc.arg(repo),
COALESCE((
@@ -57,12 +60,13 @@ VALUES (
(SELECT m.org_id FROM memberships m WHERE m.identity_id = sqlc.arg(identity)
ORDER BY m.created_at, m.org_id, m.workspace_id NULLS LAST LIMIT 1),
'default'
)
),
sqlc.arg(inputs)
)
RETURNING *;
-- name: StampTaskBinding :exec
UPDATE tasks SET binding_id = $2, binding_version = $3, inputs = $4 WHERE id = $1;
UPDATE tasks SET binding_id = $2, binding_version = $3 WHERE id = $1;
-- name: UpdateTask :exec
UPDATE tasks SET workflow = $2, branch = $3, plan = $4, notes = $5,
@@ -19,7 +19,7 @@ import (
// runningExecution enqueues and claims one task, the state a step runs in.
func runningExecution(t *testing.T, s *Store) *workflow.Task {
t.Helper()
seed, err := s.EnqueueChatTask(t.Context(), "acme", "widgets", "t", "b", "implement", "")
seed, err := s.EnqueueChatTask(t.Context(), "acme", "widgets", "t", "b", "implement", "", nil)
if err != nil || seed == nil {
t.Fatalf("EnqueueChatTask: %+v %v", seed, err)
}
+14 -10
View File
@@ -148,10 +148,17 @@ func (s *Store) EnqueueIssue(ctx context.Context, owner, repo string, number int
// EnqueueChatTask inserts a queued chat-sourced task and returns the full row.
// The store allocates the synthetic issue number durably so processes sharing
// the database cannot generate the same value.
func (s *Store) EnqueueChatTask(ctx context.Context, owner, repo, title, body, wf, identity string) (*workflow.Task, error) {
// the database cannot generate the same value. inputs are the task's workflow
// inputs (the operator trigger's pr_number, for instance); a chat task carries
// no binding provenance, so the insert is the only writer of that column.
func (s *Store) EnqueueChatTask(ctx context.Context, owner, repo, title, body, wf, identity string, inputs map[string]any) (*workflow.Task, error) {
encoded, err := task.EncodeInputs(inputs)
if err != nil {
return nil, err
}
t, err := s.queries().InsertChatTask(ctx, postgresdb.InsertChatTaskParams{
Owner: owner, Repo: repo, Title: title, Body: body, Workflow: wf, Identity: identity,
Inputs: encoded,
FallbackIssueNumber: syntheticIssueNumberBase - 1,
})
if err != nil {
@@ -161,24 +168,21 @@ func (s *Store) EnqueueChatTask(ctx context.Context, owner, repo, title, body, w
}
// EnqueueBindingTask enqueues a binding-triggered task and stamps its binding
// provenance in a second statement (best-effort, as in the SQLite store).
// provenance in a second statement (best-effort, as in the SQLite store). The
// inputs travel with the insert, so a failed stamp leaves a task whose inputs
// are already right and whose provenance is absent, never the reverse.
func (s *Store) EnqueueBindingTask(ctx context.Context, owner, repo, title, body, wf, identity, bindingID string, bindingVersion int, inputs map[string]any) (*workflow.Task, error) {
encoded, err := task.EncodeInputs(inputs)
if err != nil {
return nil, err
}
t, err := s.EnqueueChatTask(ctx, owner, repo, title, body, wf, identity)
t, err := s.EnqueueChatTask(ctx, owner, repo, title, body, wf, identity, inputs)
if err != nil {
return nil, err
}
if err := s.queries().StampTaskBinding(ctx, postgresdb.StampTaskBindingParams{
ID: t.ID, BindingID: bindingID, BindingVersion: int64(bindingVersion), Inputs: encoded,
ID: t.ID, BindingID: bindingID, BindingVersion: int64(bindingVersion),
}); err != nil {
return nil, fmt.Errorf("store: stamp binding provenance: %w", err)
}
t.BindingID = bindingID
t.BindingVersion = bindingVersion
t.Inputs = inputs
return t, nil
}
@@ -60,7 +60,7 @@ func TestIllegalTransitionsAreRejected(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := storeFor(t)
task, err := s.EnqueueChatTask(t.Context(), "acme", "widgets", "t", "b", "implement", "")
task, err := s.EnqueueChatTask(t.Context(), "acme", "widgets", "t", "b", "implement", "", nil)
if err != nil || task == nil {
t.Fatalf("EnqueueChatTask: %+v %v", task, err)
}
@@ -91,7 +91,7 @@ func TestIllegalTransitionsAreRejected(t *testing.T) {
// conformance battery has always asserted).
func TestStaleFromBeatsIllegalPair(t *testing.T) {
s := storeFor(t)
task, err := s.EnqueueChatTask(t.Context(), "acme", "widgets", "t", "b", "implement", "")
task, err := s.EnqueueChatTask(t.Context(), "acme", "widgets", "t", "b", "implement", "", nil)
if err != nil || task == nil {
t.Fatalf("EnqueueChatTask: %+v %v", task, err)
}
@@ -106,7 +106,7 @@ func TestStaleFromBeatsIllegalPair(t *testing.T) {
// and the audit row is written as before.
func TestLegalTransitionStillWrites(t *testing.T) {
s := storeFor(t)
task, err := s.EnqueueChatTask(t.Context(), "acme", "widgets", "t", "b", "implement", "")
task, err := s.EnqueueChatTask(t.Context(), "acme", "widgets", "t", "b", "implement", "", nil)
if err != nil || task == nil {
t.Fatalf("EnqueueChatTask: %+v %v", task, err)
}