feat(database,web): an automation's runs start agents in its workspace on no plan, and one that archives its successful runs archives each agent that finished well

Merged
DA
4d ago
+9479-20

Step 10 (first half) of the automations plan (docs/proposals/automations-scope.md). It is stacked on #2701 (agent page read).

What changes

  • A run starts a planless agent.
    • With "New agent each run" (the default target), a run starts its agent through #2674's workspace path: in the automation's workspace (its own organization_id, coalesced from its plan on rows the backfill hasn't reached), on no plan, on the first of its repositories, handed the task, and naming the automation (automation_id).
    • The run's agent therefore shows on the automation (its runs, the Inbox grouped by automation from #2688, the agent page from #2701), not as a tab on the plan the automation was made on.
    • The checks are the same as before: creator membership (decided under the lock), the repository reached through the workspace's installation, and the model.
    • An automation with no workspace or no repository fails the run as plan-unreachable or no-repository before anything starts.
  • Archive successful runs.
    • The minute sweep archives, as their starter, the agents of runs whose automation has archive_successful and starts a new agent each run, once each agent's tab would read completed.
    • An agent that failed, was stopped, or still works is left standing, and so is one holding an open Inbox item, since archiving it would put away the question it's waiting on.
    • Each run's archive is settled once, in a new nullable automation_run.archive_settled_at (idempotent expand migration): archived here, already put away by hand, or left standing for good as failed or stopped. Once settled, a run is never read again, so an agent the developer brings back stays.
    • An agent still at work or waiting on the Inbox is read again by later sweeps for a week, so one whose question is answered days later is still archived.
    • At most 100 a sweep, oldest first.
    • The sweep's answer gains archived.
  • A GitHub-event run's repository check reads the automation's repositories, not the plan's (GitHub triggers stay dormant per the plan).
  • automation-runs.ts's header no longer claims three failed starts pause an automation; #2598 removed that.

Still to come: "Same agent" (steer an existing agent each run) follows in its own PR. It needs the steer path and stranded-run recovery under a steer key, and stays a stored setting until then. No desktop build creates automations yet, so no one's plan loses agents it used to show.

Tests

  • automation-runs.test.ts:
    • A scheduled run's agent stands in the automation's workspace with planId null, on its repository, naming the automation.
    • A new test: an archiving automation's agent whose turn settled is archived by the sweep (archived: 1). One that failed, one holding an open Inbox item, and a settled agent of an automation that doesn't archive all stay.
    • Then the archived agent is brought back by hand and the item closed. Three days later the sweep leaves the restored agent standing and archives the one that was waiting.
    • This fails without the sweep step.
  • The existing automation, sweep, and maintenance tests pass.

pnpm check:affected passes. This change is server only; CI cannot verify the Mac UI, and ./scripts/verify.sh was not run (LUKE-159 stands in before the first release).

šŸ¤– Generated with Claude Code