Skip to content

Plans tell the truth: task state follows runs and pull requests - #800

Merged
nambok merged 1 commit into
mainfrom
plans-follow-the-work
Nov 22, 2026
Merged

nambok merged 1 commit into
mainfrom
plans-follow-the-work

Conversation

@nambok

@nambok nambok commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

A plan now tells the truth about its work. A task's state is derived from the runs of its ticket and their pull requests, never from filing the ticket, and a plan is Done only when every task merged or was dropped. Every run started from a plan task names its plan and task, plans made before this are linked to their runs and read again (the backfill), approving one task never ends the plan, and every route that starts work checks the run budget.

Before: the worker marked a task done the moment its ticket was filed and the plan done once no task waited on another. Nothing wrote runs or pull requests back to tasks, so plans read Done with most of their pull requests open, closed unmerged or failing, and approving one task from its row stranded the other drafts.

Changes

  • common::plan_state (new, pure): the task states (Draft, Queued with what it waits on, Working, Needs you with the exact ask, Failed with its reason, In review, Merged, Dropped) derived from the task row and its runs; the plan states (Drafting, Running, Needs you, Done, Stalled after 3 days of silence); pull request chips coloured by checks and review with their size; the Needs you list; drift marks (tasks added, changed or dropped after approval, pull requests that change files outside the paths the task names, scope ledger items moved into scope, with who made each change); success criteria with evidence from each task's newest criteria trace (Code map kept current, criteria traced to proof, non-functional checks in plans #780); the count line; cost and attempts per task and per plan.
  • common::plan_sync (new): finds each task's runs through its ticket (Jira key, or GH-<n> in the issue's repository), stamps runs that lack it with plan_id and plan_task_id, writes a missing ticket link so later runs carry the plan from their first write, derives the states and writes the derived fields on the task and plan rows only when they changed. Idempotent. Also the start estimate (runs and cost range from the team's recent runs).
  • Worker: filing a ticket sets the task to filed (a fact) and refreshes the plan; it never writes done. Filing failures store their reason. Runs carry plan_task_id from their first write. Every run status event (emit_run) refreshes the run's plan.
  • Gateway: GET /api/plans/:id derives the plan live and returns tasks with runs, pull request chips, needs, drift and covered criteria, plus criteria with evidence, needs and the start estimate. GET /api/plans returns per-plan state, count line, counts by state, needs count, cost and attempts, and refreshes plans written before this (up to 8 per page) or open plans last derived over 10 minutes ago: this is the backfill. Pull request opened, reviewed, checked, merged and closed events refresh the plan of the run they belong to and keep the pull request's size and a person's review verdict on the run.
  • Approval: approving one task queues it, starts it, keeps the plan running and open, and refuses a task that already started. approve-and-execute, execute, single approve and force-run all check the run budget, and tasks are marked queued before the message that starts them (the old order could write queued over a task the worker had already filed), with a rollback to approved when the message can't be sent. Plans accept success_criteria, tasks accept covers, and task edits record who made them.
  • Incident case pl_plan_follows_the_work with its page: replays the stranded plan and the false-Done plan.
  • OpenAPI document regenerated.

Other open work: this touches github_webhook.rs only in dispatch (one call after the event is routed) and makes lookup_run_item_by_pr visible to plans.rs; none of the reward paths. It touches no file of #796.

Verification

  • cargo fmt --all --check, rustfmt --check --edition 2021 worker/src/passes/incidents/*.rs, cargo clippy --workspace --all-targets -- -D warnings, cargo test --workspace.
  • New tests that fail on origin/main and pass here: filing a ticket is never done (plan_state, and the incident case reading plan_execute.rs); state follows run and pull request events; one approved task leaves the plan open with the drafts asked for; every start route checks the run budget before starting and queues before sending (main: single approve, approve-all and force-run had no budget check, approve-all queued after sending); backfill links runs and recomputes, idempotently; drift marks; list counts and the list refresh rule.
  • The backfill replayed locally on exported plans: plans whose tasks all merged stay Done, plans that read Done with open, failed or unmerged work become Needs you, drafts stay Drafting, and every plan-made run gets linked to its task, with ticket links written for later runs.

A task's state is derived from the runs of its ticket and their pull
requests (common::plan_state), never from filing the ticket, and a plan
is Done only when every task merged or was dropped. common::plan_sync
links each run to its plan and task, writes missing ticket links, and
writes the derived states; it runs on run status events, pull request
events, approvals, the plan page, and from the plans list for plans
written before it (the backfill).

Approving one task keeps the plan open, every start route checks the
run budget, tasks are queued before the message that starts them, and
filing failures keep their reason. The plan API returns tasks with runs,
pull request chips, needs, drift and covered criteria, plus criteria
with evidence and the start estimate; the list returns counts by state,
cost and the needs-you count.

Incident case pl_plan_follows_the_work replays the stranded plan and the
false-Done plan.
@nambok
nambok merged commit 4cadb61 into main Nov 22, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant