From 7b7aa62c282abe07da6b08e2d4a481ada7a2d919 Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Thu, 24 Sep 2026 20:53:51 +1000 Subject: [PATCH] fix(eda): clear completed tasks; document the tool allowlist's reach and unchecked profile names ClearTerminalTasks now deletes completed tasks, with a test that holds its SQL list to taskstate.Terminal. The AllowTools comment says agentloop's built-in file tools are outside the allowlist and why. The PRD model diagram lists only what a profile holds (image, tools), and the profile field and AgentProfile say a workflow's profile name is resolved at dispatch, not when the workflow is saved. --- docs/data/generated/dev-docs.json | 2 +- docs/prds/event-automation.md | 4 +-- internal/agentexec/loop_runner.go | 9 +++-- internal/config/config.go | 4 ++- internal/domain/workflow/task/interface.go | 4 ++- .../postgres/clear_terminal_test.go | 34 +++++++++++++++++++ .../postgres/postgresdb/tasks.sql.go | 2 +- .../infrastructure/postgres/queries/tasks.sql | 2 +- 8 files changed, 51 insertions(+), 10 deletions(-) create mode 100644 internal/infrastructure/postgres/clear_terminal_test.go diff --git a/docs/data/generated/dev-docs.json b/docs/data/generated/dev-docs.json index 43f5d6b40..9d0c3d32a 100644 --- a/docs/data/generated/dev-docs.json +++ b/docs/data/generated/dev-docs.json @@ -244,7 +244,7 @@ "url": "/dev/prds/event-automation/", "title": "Event automation: identified events, typed parameters, purpose-built agents", "section": "PRDs", - "body": "# Event automation: identified events, typed parameters, purpose-built agents\n\n**Status:** Approved\n**Date:** 2026-09-23\n**Parent:** epic `archie-core-t2db`\n\n## Why this exists\n\nArchie is an event-driven automation system. Any system that can send a\nwebhook (a forge, an error tracker, a firewall, a monitoring stack) should be\nable to start an agent built for that job. The shape this replaces cannot:\n\n- A binding matches only the URL segment an event was posted to, and a source\n may have one binding. Two kinds of event from one sender cannot go to\n different workflows.\n- A mapping is a list of JSON paths written against one example payload.\n Nothing recognises what kind of event arrived.\n- Mapped values reach the task only as `key=value` lines in its body text.\n- Every task needs a repository and runs in a git worktree.\n- Every agent runs the same image with the same forwarded keys.\n\n## The model\n\n```\nsource ─▶ event type ─▶ mapping ─▶ binding ─▶ workflow ─▶ agent profile\n (identified) (params) (+ filter, (inputs, (image, tools,\n repo) profile) secrets, access)\n```\n\n### Sources\n\nA source is the endpoint one sender posts to. Its path is a generated UUIDv7\n(`/webhooks/capture/0199…`), so an endpoint cannot be guessed or collide. The\noperator may replace it with a custom path for a sender that cannot use that\nformat; a custom path must be unique and URL-safe, and is refused otherwise.\nA source owns the signing setting:\n\n- **Signed** (default). Archie generates the secret. Only events with a valid\n `X-Hub-Signature-256` or `X-Signature-256` HMAC are dispatched.\n- **Unsigned.** The operator turns signing off for a sender that cannot sign.\n The source and every event from it are marked unsigned in the inspector,\n the binding list and the task timeline. Turning signing off needs the same\n approval as arming a binding.\n\nUnauthenticated events on a signed source are captured and never\ndispatched.\n\n### Event types\n\nAn event type is a named kind of event from one source, such as\n`github / pull_request.opened` or `firewall / blocked_connection`. It is\ndefined by a match rule:\n\n- header equality (`X-GitHub-Event = pull_request`), and\n- payload conditions (`action = \"opened\"`, or a path being present).\n\nAn event type can be created two ways:\n\n- **From an example payload.** The operator pastes a payload (and optionally\n its headers), and archie converts it to the type's schema. No event needs to\n have arrived.\n- **From captures.** Archie proposes types from what has arrived, as below.\n\nEither way, archie infers the schema, not the operator:\n\n- Each capture gets a structural signature: the set of JSON paths with their\n value types, plus the headers that look like discriminators (`*-Event`,\n `*-Type`, `Content-Type`).\n- Captures from one source that share a signature are grouped. The inspector\n shows each group as a proposed event type, with its inferred schema, its\n number of events and a sample, until the operator names it or dismisses it.\n- The proposed match rule is the set of discriminators that separates the\n group from its siblings. The operator can edit it before saving.\n- A capture that matches no named type is shown as unidentified. It is never\n dispatched.\n\nTwo event types on one source whose rules can match the same event are\nrefused when the second one is saved.\n\n### Mappings\n\nA mapping belongs to an event type. It maps payload paths to named, typed\nparameters, and it is checked against the type's inferred schema, so a path\nthe type does not have is refused when the mapping is saved. Any number of\nbindings may reuse one mapping.\n\nEach mapping shows how many events it has matched, with the time of the most\nrecent, so an operator can see which mappings are live and which have never\nfired.\n\n### Workflows declare inputs\n\nA workflow definition declares its inputs:\n\n```yaml\nid: firewall-investigate\ninputs:\n src_ip: { type: string, required: true }\n severity: { type: string }\nrepository: none # none | optional | required\nprofile: network-investigator\nsteps: ...\n```\n\n- `repository: none` runs the agent in a scratch workspace with no clone.\n `required`, the default, gives the agent a worktree of the task's\n repository. `optional` gives it a worktree when the binding names a\n repository and a scratch workspace when it does not.\n- A workflow whose `repository` is not `required` may use only steps that need\n no repository. `agent.run` is one: it runs one agent mission and finishes\n the task as done, with no pull request.\n- The declared inputs reach the agent as structured data in the task brief\n and in the agent's context. They are not body text.\n- A workflow may declare `outputs`, the structured result it returns when it\n finishes.\n\n### Workflows call workflows\n\nA workflow step can call another workflow. The call passes the callee's\ninputs, and the callee runs as its own run with its own agent profile, so one\nevent can start an investigator that then calls a containment workflow:\n\n```yaml\nsteps:\n - type: workflow.call\n workflow: firewall-contain\n inputs: { src_ip: inputs.src_ip }\n wait: true # false starts the callee and continues\n```\n\n- With `wait: true` the caller receives the callee's outputs and fails if the\n callee fails. With `wait: false` the caller continues and the callee's\n outcome is reported on its own run.\n- A call's inputs are checked against the callee's declared inputs when the\n calling workflow is saved.\n- A workflow that calls itself, directly or through other workflows, is\n refused when it is saved. Calls are limited to a fixed depth at run time.\n- A callee must be enabled for the caller's org.\n\n### Bindings\n\nA binding connects an event type to one workflow:\n\n- an optional filter on mapped parameters (`severity in [\"high\", \"critical\"]`),\n written in the CEL the playbook engine already uses;\n- an assignment of workflow inputs from mapped parameters or constants,\n checked against the workflow's declared inputs when the binding is saved;\n- a repository, when the workflow's `repository` is not `none`: either fixed\n (`acme/api`) or taken from a parameter (the GitHub webhook's\n `repository.full_name`). A repository taken from a parameter must be a\n configured one, or the event does not dispatch.\n\nAny number of bindings may use one event type. Approval and re-approval after\nan edit are unchanged. A binding whose workflow input types no longer match is\nrefused at dispatch and reported on the binding.\n\n### Agent profiles\n\nA profile is a named execution environment that a workflow selects:\n\n- the container image;\n- an allowlist over the tools Archie adds to the agent: MCP servers,\n repository scripts and skill plugins. The agent's own file tools are always\n present;\n- the secrets injected into it, by reference to the secret store, never\n inline (superseded by `docs/prds/orgs-and-access.md`: secrets are granted to\n identities, and a profile holds no secrets);\n- its network access and forge access (superseded by\n `docs/prds/orgs-and-access.md`: permissions are granted to identities).\n\nProfiles are configured under `[containers.profiles.\u003cname\u003e]`. The global\n`[containers].image` becomes the default profile, so existing workflows are\nunchanged. A task whose workflow names an unconfigured profile is parked for\nan operator. A secret or permission is granted to an identity, never to a binding, so an\nevent can never widen what an agent can do (`docs/prds/orgs-and-access.md`).\n\n### Workflows belong to orgs\n\nArchie ships a default workflow catalogue that every org can use. An org can\nadd its own workflows, and can enable or disable any workflow, default or its\nown, for itself. A binding can target only a workflow enabled for its org, and\ndisabling a workflow stops its bindings dispatching and marks them on the\nbinding list.\n\n## Delivery order\n\n1. Event types: structural signatures, grouping, naming, match rules, and the\n inspector view of proposed and unidentified events.\n2. Mappings per event type, and multiple bindings per source.\n3. Workflow inputs, structured parameters in the task brief, and\n `repository: none | optional | required`.\n4. Agent profiles with image and tools.\n5. Signing as a source setting, with the unsigned option; UUIDv7 source paths\n with a custom-path override.\n6. Workflows calling workflows, with declared outputs.\n7. Org-scoped workflow catalogue, once orgs exist.\n\nEach step ships usable on its own. Step 3 is the first where an event that has\nnothing to do with a repository can run a workflow.\n\n## Out of scope\n\n- How forge-issue playbook triggers (`internal/domain/eda/playbook`) relate to\n event types. They stay as they are until event types exist.\n- Built-in catalogues of event types for known senders.\n- Orgs themselves: membership, access, and how sources and bindings belong to\n one. This design needs only an org to own workflows and their enabled state.\n- Running an agent outside a container.\n\n## Verification\n\n- Two GitHub webhooks with different `X-GitHub-Event` headers posted to one\n source are grouped into two proposed event types, and a firewall payload\n with a different shape is grouped separately.\n- A capture matching no named type is shown as unidentified and starts\n nothing.\n- A firewall event runs a `repository: none` workflow with its mapped inputs\n readable by the agent as structured data, and no clone is made.\n- A GitHub `pull_request.opened` event runs a PR review workflow against the\n repository named in the payload.\n- An event type created from a pasted payload has that payload's schema, and a\n later matching event is identified as it.\n- A new source gets a UUIDv7 path; a custom path that is already taken is\n refused.\n- A workflow that calls another with `wait: true` receives its outputs; one\n that calls itself through another workflow is refused when saved.\n- A mapping's matched-event count rises by one for each event it resolves.\n- A workflow disabled for an org cannot be targeted, and its existing bindings\n stop dispatching.\n- A binding whose filter excludes an event does not dispatch it.\n- An agent receives only the secrets its identity is granted.\n- An unsigned event on a signed source is captured and not dispatched. An\n event on an unsigned source is dispatched and marked unsigned.\n" + "body": "# Event automation: identified events, typed parameters, purpose-built agents\n\n**Status:** Approved\n**Date:** 2026-09-23\n**Parent:** epic `archie-core-t2db`\n\n## Why this exists\n\nArchie is an event-driven automation system. Any system that can send a\nwebhook (a forge, an error tracker, a firewall, a monitoring stack) should be\nable to start an agent built for that job. The shape this replaces cannot:\n\n- A binding matches only the URL segment an event was posted to, and a source\n may have one binding. Two kinds of event from one sender cannot go to\n different workflows.\n- A mapping is a list of JSON paths written against one example payload.\n Nothing recognises what kind of event arrived.\n- Mapped values reach the task only as `key=value` lines in its body text.\n- Every task needs a repository and runs in a git worktree.\n- Every agent runs the same image with the same forwarded keys.\n\n## The model\n\n```\nsource ─▶ event type ─▶ mapping ─▶ binding ─▶ workflow ─▶ agent profile\n (identified) (params) (+ filter, (inputs, (image, tools)\n repo) profile)\n```\n\n### Sources\n\nA source is the endpoint one sender posts to. Its path is a generated UUIDv7\n(`/webhooks/capture/0199…`), so an endpoint cannot be guessed or collide. The\noperator may replace it with a custom path for a sender that cannot use that\nformat; a custom path must be unique and URL-safe, and is refused otherwise.\nA source owns the signing setting:\n\n- **Signed** (default). Archie generates the secret. Only events with a valid\n `X-Hub-Signature-256` or `X-Signature-256` HMAC are dispatched.\n- **Unsigned.** The operator turns signing off for a sender that cannot sign.\n The source and every event from it are marked unsigned in the inspector,\n the binding list and the task timeline. Turning signing off needs the same\n approval as arming a binding.\n\nUnauthenticated events on a signed source are captured and never\ndispatched.\n\n### Event types\n\nAn event type is a named kind of event from one source, such as\n`github / pull_request.opened` or `firewall / blocked_connection`. It is\ndefined by a match rule:\n\n- header equality (`X-GitHub-Event = pull_request`), and\n- payload conditions (`action = \"opened\"`, or a path being present).\n\nAn event type can be created two ways:\n\n- **From an example payload.** The operator pastes a payload (and optionally\n its headers), and archie converts it to the type's schema. No event needs to\n have arrived.\n- **From captures.** Archie proposes types from what has arrived, as below.\n\nEither way, archie infers the schema, not the operator:\n\n- Each capture gets a structural signature: the set of JSON paths with their\n value types, plus the headers that look like discriminators (`*-Event`,\n `*-Type`, `Content-Type`).\n- Captures from one source that share a signature are grouped. The inspector\n shows each group as a proposed event type, with its inferred schema, its\n number of events and a sample, until the operator names it or dismisses it.\n- The proposed match rule is the set of discriminators that separates the\n group from its siblings. The operator can edit it before saving.\n- A capture that matches no named type is shown as unidentified. It is never\n dispatched.\n\nTwo event types on one source whose rules can match the same event are\nrefused when the second one is saved.\n\n### Mappings\n\nA mapping belongs to an event type. It maps payload paths to named, typed\nparameters, and it is checked against the type's inferred schema, so a path\nthe type does not have is refused when the mapping is saved. Any number of\nbindings may reuse one mapping.\n\nEach mapping shows how many events it has matched, with the time of the most\nrecent, so an operator can see which mappings are live and which have never\nfired.\n\n### Workflows declare inputs\n\nA workflow definition declares its inputs:\n\n```yaml\nid: firewall-investigate\ninputs:\n src_ip: { type: string, required: true }\n severity: { type: string }\nrepository: none # none | optional | required\nprofile: network-investigator\nsteps: ...\n```\n\n- `repository: none` runs the agent in a scratch workspace with no clone.\n `required`, the default, gives the agent a worktree of the task's\n repository. `optional` gives it a worktree when the binding names a\n repository and a scratch workspace when it does not.\n- A workflow whose `repository` is not `required` may use only steps that need\n no repository. `agent.run` is one: it runs one agent mission and finishes\n the task as done, with no pull request.\n- The declared inputs reach the agent as structured data in the task brief\n and in the agent's context. They are not body text.\n- A workflow may declare `outputs`, the structured result it returns when it\n finishes.\n\n### Workflows call workflows\n\nA workflow step can call another workflow. The call passes the callee's\ninputs, and the callee runs as its own run with its own agent profile, so one\nevent can start an investigator that then calls a containment workflow:\n\n```yaml\nsteps:\n - type: workflow.call\n workflow: firewall-contain\n inputs: { src_ip: inputs.src_ip }\n wait: true # false starts the callee and continues\n```\n\n- With `wait: true` the caller receives the callee's outputs and fails if the\n callee fails. With `wait: false` the caller continues and the callee's\n outcome is reported on its own run.\n- A call's inputs are checked against the callee's declared inputs when the\n calling workflow is saved.\n- A workflow that calls itself, directly or through other workflows, is\n refused when it is saved. Calls are limited to a fixed depth at run time.\n- A callee must be enabled for the caller's org.\n\n### Bindings\n\nA binding connects an event type to one workflow:\n\n- an optional filter on mapped parameters (`severity in [\"high\", \"critical\"]`),\n written in the CEL the playbook engine already uses;\n- an assignment of workflow inputs from mapped parameters or constants,\n checked against the workflow's declared inputs when the binding is saved;\n- a repository, when the workflow's `repository` is not `none`: either fixed\n (`acme/api`) or taken from a parameter (the GitHub webhook's\n `repository.full_name`). A repository taken from a parameter must be a\n configured one, or the event does not dispatch.\n\nAny number of bindings may use one event type. Approval and re-approval after\nan edit are unchanged. A binding whose workflow input types no longer match is\nrefused at dispatch and reported on the binding.\n\n### Agent profiles\n\nA profile is a named execution environment that a workflow selects:\n\n- the container image;\n- an allowlist over the tools Archie adds to the agent: MCP servers,\n repository scripts and skill plugins. The agent's own file tools are always\n present;\n- the secrets injected into it, by reference to the secret store, never\n inline (superseded by `docs/prds/orgs-and-access.md`: secrets are granted to\n identities, and a profile holds no secrets);\n- its network access and forge access (superseded by\n `docs/prds/orgs-and-access.md`: permissions are granted to identities).\n\nProfiles are configured under `[containers.profiles.\u003cname\u003e]`. The global\n`[containers].image` becomes the default profile, so existing workflows are\nunchanged. A task whose workflow names an unconfigured profile is parked for\nan operator. A secret or permission is granted to an identity, never to a binding, so an\nevent can never widen what an agent can do (`docs/prds/orgs-and-access.md`).\n\n### Workflows belong to orgs\n\nArchie ships a default workflow catalogue that every org can use. An org can\nadd its own workflows, and can enable or disable any workflow, default or its\nown, for itself. A binding can target only a workflow enabled for its org, and\ndisabling a workflow stops its bindings dispatching and marks them on the\nbinding list.\n\n## Delivery order\n\n1. Event types: structural signatures, grouping, naming, match rules, and the\n inspector view of proposed and unidentified events.\n2. Mappings per event type, and multiple bindings per source.\n3. Workflow inputs, structured parameters in the task brief, and\n `repository: none | optional | required`.\n4. Agent profiles with image and tools.\n5. Signing as a source setting, with the unsigned option; UUIDv7 source paths\n with a custom-path override.\n6. Workflows calling workflows, with declared outputs.\n7. Org-scoped workflow catalogue, once orgs exist.\n\nEach step ships usable on its own. Step 3 is the first where an event that has\nnothing to do with a repository can run a workflow.\n\n## Out of scope\n\n- How forge-issue playbook triggers (`internal/domain/eda/playbook`) relate to\n event types. They stay as they are until event types exist.\n- Built-in catalogues of event types for known senders.\n- Orgs themselves: membership, access, and how sources and bindings belong to\n one. This design needs only an org to own workflows and their enabled state.\n- Running an agent outside a container.\n\n## Verification\n\n- Two GitHub webhooks with different `X-GitHub-Event` headers posted to one\n source are grouped into two proposed event types, and a firewall payload\n with a different shape is grouped separately.\n- A capture matching no named type is shown as unidentified and starts\n nothing.\n- A firewall event runs a `repository: none` workflow with its mapped inputs\n readable by the agent as structured data, and no clone is made.\n- A GitHub `pull_request.opened` event runs a PR review workflow against the\n repository named in the payload.\n- An event type created from a pasted payload has that payload's schema, and a\n later matching event is identified as it.\n- A new source gets a UUIDv7 path; a custom path that is already taken is\n refused.\n- A workflow that calls another with `wait: true` receives its outputs; one\n that calls itself through another workflow is refused when saved.\n- A mapping's matched-event count rises by one for each event it resolves.\n- A workflow disabled for an org cannot be targeted, and its existing bindings\n stop dispatching.\n- A binding whose filter excludes an event does not dispatch it.\n- An agent receives only the secrets its identity is granted.\n- An unsigned event on a signed source is captured and not dispatched. An\n event on an unsigned source is dispatched and marked unsigned.\n" }, { "url": "/dev/prds/event-capture-storage/", diff --git a/docs/prds/event-automation.md b/docs/prds/event-automation.md index e7f317335..67f0d732e 100644 --- a/docs/prds/event-automation.md +++ b/docs/prds/event-automation.md @@ -23,8 +23,8 @@ able to start an agent built for that job. The shape this replaces cannot: ``` source ─▶ event type ─▶ mapping ─▶ binding ─▶ workflow ─▶ agent profile - (identified) (params) (+ filter, (inputs, (image, tools, - repo) profile) secrets, access) + (identified) (params) (+ filter, (inputs, (image, tools) + repo) profile) ``` ### Sources diff --git a/internal/agentexec/loop_runner.go b/internal/agentexec/loop_runner.go index d84934ff9..212393c77 100644 --- a/internal/agentexec/loop_runner.go +++ b/internal/agentexec/loop_runner.go @@ -43,7 +43,10 @@ type LoopRunner struct { // AllowTools is the agent profile's allowlist over the tools archie adds // (central/MCP, repository scripts and skill plugins). Empty allows them // all. A stage's capture tools are how it returns structured results, so - // they are never filtered. + // they are never filtered. The agent loop's built-in file tools are not + // covered either: ai-sdk agentloop registers them itself with no filter + // hook, so they are always present (read-only when the stage asks), and + // restricting them needs an ai-sdk change. AllowTools []string } @@ -393,8 +396,6 @@ func scriptToolSet(workspace string) core.ToolSet { } } -// mergeToolSets combines tool sets into one; later sets win on name -// collisions. // allowedTools keeps the tools allow names; an empty allow keeps them all. func allowedTools(set core.ToolSet, allow []string) core.ToolSet { if len(allow) == 0 { @@ -409,6 +410,8 @@ func allowedTools(set core.ToolSet, allow []string) core.ToolSet { return kept } +// mergeToolSets combines tool sets into one; later sets win on name +// collisions. func mergeToolSets(sets ...core.ToolSet) core.ToolSet { merged := core.ToolSet{} for _, set := range sets { diff --git a/internal/config/config.go b/internal/config/config.go index 10bd4a65a..460b165e8 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -914,7 +914,9 @@ type ContainerConfig struct { // AgentProfile is a named execution environment for an agent. Secrets and // forge or network access are granted to identities, not profiles -// (docs/prds/orgs-and-access.md). +// (docs/prds/orgs-and-access.md). A workflow's profile name is not checked +// when the workflow is saved: a name with no profile here parks the task for +// an operator when it is dispatched (daemon pinTaskProfile). type AgentProfile struct { // Image is the container image; empty means [containers].image. Image string `toml:"image" yaml:"image" json:"image,omitempty"` diff --git a/internal/domain/workflow/task/interface.go b/internal/domain/workflow/task/interface.go index 06385ea15..3de3e16d8 100644 --- a/internal/domain/workflow/task/interface.go +++ b/internal/domain/workflow/task/interface.go @@ -39,7 +39,9 @@ type InputSpec struct { type WorkflowInterface struct { Inputs map[string]InputSpec `yaml:"inputs,omitempty" json:"inputs,omitempty"` Repository RepositoryMode `yaml:"repository,omitempty" json:"repository,omitempty"` - Profile string `yaml:"profile,omitempty" json:"profile,omitempty"` + // Profile names a [containers.profiles] entry. It is resolved when a task + // is dispatched, not when the workflow is saved. + Profile string `yaml:"profile,omitempty" json:"profile,omitempty"` } var ( diff --git a/internal/infrastructure/postgres/clear_terminal_test.go b/internal/infrastructure/postgres/clear_terminal_test.go new file mode 100644 index 000000000..1d2004355 --- /dev/null +++ b/internal/infrastructure/postgres/clear_terminal_test.go @@ -0,0 +1,34 @@ +package postgres + +import ( + "testing" + + "github.com/samcharles93/archie-core/internal/taskstate" +) + +// ClearTerminalTasks deletes exactly the statuses taskstate.Terminal names, so +// the SQL list cannot fall behind a new terminal status. +func TestClearTerminalTasksMatchesTaskstate(t *testing.T) { + s := storeFor(t) + statuses := taskstate.Statuses() + for i, meta := range statuses { + if _, err := s.EnqueueIssue(t.Context(), "acme", "widgets", i+1, "t", "b", "", ""); err != nil { + t.Fatal(err) + } + if _, err := s.pool.Exec(t.Context(), "UPDATE tasks SET status = $1 WHERE issue_number = $2", meta.ID, i+1); err != nil { + t.Fatal(err) + } + } + if _, err := s.ClearTerminalTasks(t.Context()); err != nil { + t.Fatal(err) + } + for i, meta := range statuses { + task, err := s.TaskByIssue(t.Context(), "acme", "widgets", i+1) + if err != nil { + t.Fatal(err) + } + if kept := task != nil; kept == taskstate.Terminal(meta.ID) { + t.Errorf("status %q: kept = %v, want kept only when not terminal", meta.ID, kept) + } + } +} diff --git a/internal/infrastructure/postgres/postgresdb/tasks.sql.go b/internal/infrastructure/postgres/postgresdb/tasks.sql.go index f3230150a..c20ee4898 100644 --- a/internal/infrastructure/postgres/postgresdb/tasks.sql.go +++ b/internal/infrastructure/postgres/postgresdb/tasks.sql.go @@ -159,7 +159,7 @@ func (q *Queries) ClaimNextTask(ctx context.Context) (Task, error) { const clearTerminalTasks = `-- name: ClearTerminalTasks :execrows DELETE FROM tasks -WHERE status IN ('merged', 'rejected', 'dead', 'closed_wont_do') +WHERE status IN ('merged', 'rejected', 'dead', 'closed_wont_do', 'completed') ` func (q *Queries) ClearTerminalTasks(ctx context.Context) (int64, error) { diff --git a/internal/infrastructure/postgres/queries/tasks.sql b/internal/infrastructure/postgres/queries/tasks.sql index 15daa1ef1..392e51228 100644 --- a/internal/infrastructure/postgres/queries/tasks.sql +++ b/internal/infrastructure/postgres/queries/tasks.sql @@ -88,7 +88,7 @@ WHERE id = $1 AND status = $4; -- name: ClearTerminalTasks :execrows DELETE FROM tasks -WHERE status IN ('merged', 'rejected', 'dead', 'closed_wont_do'); +WHERE status IN ('merged', 'rejected', 'dead', 'closed_wont_do', 'completed'); -- name: RecoverStaleTasks :execrows UPDATE tasks SET status = 'queued', updated_at = now() WHERE status = 'running';