Repository navigation
feat(workflow)!: let a workflow own its copy, hand runs to a person, clean up run branches, and read a step's PR - #1704
Conversation
…iver: pr A workflow could not tell a step that delivered a pull request from one that had nothing to deliver. Pull now accepts steps.<id>.pr, its url, the pr of each pass and of each for_each result, and a workflow output that passes it on. It rejects a read of pr on a step without deliver: pr, on a for_each step (whose pull requests are per item), and of any field other than url.
A step with deliver: pr now keeps { url } once its delivery opens or takes a
pull request, the same way it keeps its outputs: on the step for its current
pass, on each archived pass, and on each for_each result. A step with nothing
to deliver keeps none, so steps.<id>.pr reads null and a fix-ci workflow can
end nothing-to-fix instead of fixed. The field is optional, so run files and
snapshots written before it still read; a snapshot publishes it as it does
deliveries.
A bare-path origin opens no pull request, so the fix-ci acceptance runs against the delivery cases' fake provider. A patch that changes the copy delivers one pull request, which fix keeps as its pr, and the run ends fixed; a patch that changes nothing opens none and the run ends nothing-to-fix. The stub drivers now report a step that changed nothing with no commits instead of failing to commit.
The Deliver a PR section now says a deliver: pr step with no commits succeeds and opens no pull request, and shows a fix-ci workflow that ends nothing-to-fix or fixed by reading steps.fix.pr, with the output of both runs. The expression reference lists pr on a step, a pass and a for_each result.
…nly one can take resume --next refused any offered run with a step left that might need a person, so a runner never took ship-issue, whose pair step runs only when a choice picks it. The static check cannot tell whether a step is reachable; the runner now finds out by running. - A runner leaves an offered run only when a step ready now in the published state needs a person. The steps that may need one later are listed as information: "may need a person at <step>". - A local driver with nobody at its terminal no longer fails a required approval or an unanswered choice with hitl_required. The step waits, held for hitl like an interactive step, and the driver publishes the run offered, says on stderr which step needs a person and the resume --claim command, and exits 0. - When the run cannot be offered (no teamai-reports, origin down, no origin), the step fails hitl_required, saying why and how to continue the run from this machine, which keeps its state.
…once it is A local driver that drove a run another terminal cancelled answered done with "record":"pending": its next found the run already ended and read the record queue once, while the cancel was still pushing the record to teamai-reports. A next that finds a settled run's record still queued now publishes the queue for that run first, so done says published when the record reached teamai-reports, and pending only when it still could not.
score --drain groups the step sessions it skips by reason, but each reason named its session id and the session lookup's message, so one ship-issue run printed eleven "Skipped 1 step session" lines. A session the tool does not keep here, or cannot read, now gets one reason per kind of failure, and the drain prints one line per run with every step and pass it skipped.
The CI recipe's required approval now ends with the run offered on teamai-reports and the job exiting 0. A runner that takes release before its build ran hands it back at ship, leaves its own offer alone afterwards, and the person who started it sees it as needing a person.
…ake runs The guide shows a CI start that reaches a required approval, the run offered on teamai-reports, a runner that leaves it, and a person who claims and finishes it, plus a ship-issue run a runner takes although its pair step may need a person. The --next table, the HITL notes and the local workflow skill say the step waits and the run is handed over, failing hitl_required only when the run cannot be offered.
…hat hands the run off A driver without HITL that does not hand runs off keeps the wait reason it had.
…ail with the retry
The levels around a step were built five times: ancestorsOf and roleLevelsOf at lease time, describe's visit, deliveryProblem and the parse-time role walk. None of them had a level for the run itself, and copyRoleFailure named the step that opened a copy by indexing the step path with a level index, which only holds while every level is a path segment. Every walk now starts from runLevels(definition), which holds the run's own copy once a workflow header can open one, and the lease-time walk is one function, levelsTo, that the mode, role, clone-branch and planned-branch lookups share. Role failures name the opener and the namer by the instance each level records. describe and deliveryProblem share one writesBranch. Nothing sets the header yet, so behaviour is unchanged.
review-and-fix is meant to run on its own and inside ship-issue's change copy. Its fix step continues whatever copy is around it, so on its own it ran read-only in the member's checkout and failed read_only_dirty, while workspace: new on fix broke the nested case by opening a branch of its own. A header workspace: new says the whole workflow works in one copy: - started on its own, the run opens that copy, on teamai/<run>/_run, and workflow start ends by naming the branch and the git merge that brings it in; - run by a step that has a copy or is inside one, its steps continue that copy and open no other; - run by a step with no copy around it, that step opens one, as workspace: new on it would, so deliver: pr on that step delivers it. pull rejects any other header value, a header deliver (delivery belongs to the step that runs the workflow), and a workspace: read-only step that runs such a workflow, naming both. Role conflicts and the skill driver's local route name the run's copy instead of an empty step id. next, report and driver.can are unchanged: drivers get the copy through the leases they already take. Git conformance runs review-and-fix on its own, inside ship-issue's change copy, and from a step with no copy, under every driver under test.
Shows review-and-fix with workspace: new in its header, run on its own, with the branch the run names at its end, and inside the copy of the step that runs it, plus the pull refusal for a read-only step that runs it.
…place workflow start names the run copy's branch when a run whose header says workspace: new left commits on it. The skill driver's done needs the same rule, so it moves into workspace.ts as changedRunCopy, next to runCopyBranch. Behaviour is unchanged.
A run whose header says workspace: new, started on its own, leaves its changes on teamai/<run>/_run. workflow start --driver local names that branch on stderr, but a run an agent drives ended with a done that carried only outcome, prs and failure, so the person was never told where the changes went. The engine's done now carries branch when a succeeded run left commits on its own copy. The skill driver keeps it with the end and shows it on the done action, next to prs, and the workflow skill tells the person the branch and the git merge that brings it in. A failed run names no branch. The field is optional, so drivers that do not read it are unaffected. Git conformance expects the branch on done for the standalone review-and-fix run under every driver under test.
The start example's done now carries branch, as the engine answers, and the guide says an agent driving the run names the same branch and git merge line when it ends.
The local driver told a person to merge the copy of a run whose header says workspace: new even when the run failed, while the skill driver names the branch only for a succeeded run. Both now read the branch from the engine's done, which carries it only for a succeeded run that left commits on its copy. Tested: a failed run's stderr names no git merge, and the succeeded case still does (workflow-commands.test.ts, 59 passed).
A retention of two weeks reads as 14d. Every duration teamai reads goes through durationMs, so a workflow timeout, a step timeout, --timeout and a benchmark suite timeout take d as well.
A run left every teamai/<run>/... branch behind, here and on origin, so for_each items and steps already merged piled up. Once a run succeeds and its end is published, each run branch whose tip a branch that stays holds is deleted: the branches its pull requests use and its final copy stay. A deletion that fails warns with the branch and is recorded on the run; a branch checked out where the host put it stays in the checkout. Failed and cancelled runs keep everything. The git conformance scenarios now check that merged branches are gone.
How long doctor --fix leaves what a settled run left behind: a duration or never, 14d by default. It is read like every member setting, from the scope's config, then ~/.teamai/config.yaml, then the team's teamai.yaml. Each level keeps the value as written, so a wrong one never fails its file: it is skipped with a warning and shown as not used, and the next level decides.
…tention doctor --fix now deletes again the branches a succeeded run could not delete as it settled, and removes what a run that settled longer ago than workflows.retention left: its branches but those a pull request uses, the worktrees teamai made on them, its kept refs and its base pin on origin. It finds runs other machines started, such as CI runners, through their end records on teamai-reports, which now name the branches their pull requests use. A second run, or one after a crash midway, ends the same.
… may need a person A run's details now list the branches a succeeded run kept and why, the ones it deleted and the ones teamai doctor --fix still has to delete; for a failed or cancelled run, from when doctor --fix removes them under workflows.retention. The handoff panel tells steps that need a person now from steps that may need one, and offers resume --claim for the latter.
…branches It removes them all but the pull request branches; the time it may do so now follows as its own label, which also reads right in Chinese.
…on, and doctor --fix Show the branch list before and after a succeeded run, the retention levels and their doctor output, what doctor --fix removes, the dashboard's Branches and may-need-a-person rows, and the d duration unit.
…deletes A succeeded run deletes the step branches a kept branch holds, so these tests read the commit the run recorded instead of the branch name, and expect only the kept branches on origin.
…engine's done The resolution for Tencent#1689 keeps `next` unchanged, so the engine's `done` no longer carries `branch`. `runCopyToMerge` derives it from a succeeded run's file: `workflow start`/`resume` read it to print the `git merge` line, and the skill driver gets it from the run file it already reads at D16 and still puts it on its own `done` action. The CLI tests for a succeeded and a failed header-copy run and the skill transition tests for D16 pass unchanged.
…e CLI The CLI git conformance wrote only the scenario's own workflow, so the two scenarios that run review-and-fix from another workflow could not start. It now writes `scenario.workflows` into the team repo, checks the copies the run records and holds on origin, and, for the local driver, that `workflow resume` names the run's copy branch and its `git merge` line only when the scenario expects one. Before: 6 failed, 27 passed. After, filtered to the header-copy scenarios and one other: 12 passed.
… no workspace Tencent#1689 reports review-and-fix whose `fix` prompt sets no `workspace`. The conformance copy used a command with `workspace: continue`, which never exercised a writing step inheriting the run's copy. `fix` is now that prompt. A git conformance prompt is a shell command the scenario's agent runs in the step's place: the in-process local driver gets an adapter that does so, the protocol driver runs a prepared prompt lease the same way, and the CLI runner puts a fake `claude` on PATH that runs its `-p` text. Before the runners could run it, every profile failed with the lease shown: `fix` leased `continue` on `teamai/<run>/_run` standalone, on `change/p1` nested, and on `check/p1` under a step with no copy, so the engine needed no change. In-process and CLI: 9 passed for the three header-copy scenarios.
… on origin only A branch the host had checked out was deleted on origin but kept here, so the cleanup ledger did not list it, and publishing still asked origin for it. The ledger cannot answer this, so publishing a succeeded run now goes by what cleanup guarantees: a missing branch passes when a branch still on origin contains its recorded commit.
|
Confirmed and fixed in 74673bb. This finding showed that the cleanup ledger is the wrong source for this rule. A branch deleted on origin but kept locally (host worktree, or a local
Tests:
|
|
No new findings I’m confident are real in the current diff.
I only read the diff; I ran, built, and installed nothing from the PR. |
…nothing to clean up The end of every run took the run's cleanup lock before it checked that the run succeeded. A retry right after cancelling a run could meet the driver finishing the cancelled run inside that lock and answer busy. The checks now run before the lock as well, and again under it.
Earlier findings: Both cleanup-related publication failures are resolved, including origin-only deletions with host-managed worktrees. Testing: The PR description provides sufficient built real-CLI verification. One provider/agent combination suffices; the others are explicitly deferred to CI. I only read the diff and trusted base review criteria; I ran, built, and installed nothing from the PR. |
…succeeded run kept Cleanup deletes such a branch on origin and leaves it in the checkout, but recorded it nowhere, so the dashboard's Branches left out a branch that still exists. It is now kept, as checked out by the host.
|
Fixed in da2ba52.
The host-worktree test now expects |
Earlier findings: Both cleanup-related publication failures and the success-cleanup Branches omission are resolved. Testing: The PR description documents sufficient built real-CLI verification. One provider/agent combination suffices; the others are explicitly deferred to CI. I only read the specified diff and trusted base review criteria; I ran, built, and installed nothing from the PR. |
@hz89Dev, the cleanup and publish fixes look good. The one thing still holding my approval is the CHANGELOG entry from my review. An existing team meets five changes on upgrade:
Please add a bullet per group in |
…ctor --fix kept Past workflows.retention, doctor --fix deletes such a branch on origin and leaves it in the checkout, but recorded only pull request branches as kept, so the run's Branches left it out. It is now kept, as checked out by the host.
|
Fixed in cdc4d49.
New test: "lists a branch the host keeps checked out among what it kept, past the retention". A failed run's branch is checked out in a host worktree, and the run is swept at +14d. The test expects the branch deleted on origin, still present locally, and recorded as |
|
No new findings I’m confident are real in the current diff.
I only read the specified diff and trusted base review criteria. I ran, built, and installed nothing from the PR. |
|
The Windows failure on cdc4d49 is a timeout, and this PR doesn't touch the code involved. |
Agreed: |
# Conflicts: # docs/dev/workflow-engine.md # docs/guide/dashboard.md # docs/guide/zh-CN/dashboard.md # oxlint-plugin-teamai/failure-codes.js # skill-data/workflow/SKILL.md # src/__tests__/score-drain.test.ts # src/__tests__/workflow-expression.test.ts # src/__tests__/workflow-skill-transitions.test.ts # src/dashboard/client.ts # src/dashboard/locales.ts # src/dashboard/workflow-runs.ts # src/session-flow/session-publish.ts # src/workflow-commands.ts # src/workflow/describe.ts # src/workflow/drivers/local/local-driver.ts # src/workflow/drivers/skill/preflight.ts # src/workflow/drivers/skill/skill-state.ts # src/workflow/drivers/skill/tick.ts # src/workflow/drivers/skill/transitions.ts # src/workflow/drivers/skill/turn.ts # src/workflow/engine.ts # src/workflow/expression.ts # src/workflow/handoff.ts # src/workflow/parse.ts # src/workflow/protocol.ts # src/workflow/run-controls.ts
|
No new findings I’m confident are real in the specified diff.
I only read the specified diff and trusted base review criteria. I ran, built, and installed nothing from the PR. |
SaulMoro
left a comment
There was a problem hiding this comment.
This was generated by AI during triage.
I checked the merge of main (549900e). Nothing from either side is lost.
- #1700: the kept-patch queue, confined steps,
private,continue_on_failure,$TEAMAI_RUN_DIRand the three-argumentretryContainersare intact. - This PR:
workspace: new, the person-step handoff andresume --next, success cleanup, the retention sweep andsteps.<id>.prare intact.
On a build of this head I reran my earlier fixtures. The handoff and the doctor --fix sweep behave as before. A run that was never published now publishes after cleanup with exit 0, where ab622df exited 1 with commit_missing. A scored step on the local driver still goes through one teamai-score run, with one judge launch and the label written.
Two things are left:
[P2 non-blocking] The CHANGELOG entry for the breaking change is still missing, and it is the only thing holding my approval. Please add a bullet per group under [Unreleased], plus a "Changed" entry naming the five upgrade-visible changes from my review.
[P3 nit] docs/dev/workflow-engine.md:25 still says the run is offered back at "(D28)". Main took D28 and D29, and this PR's rows moved to D30–D32, so that should read D30.
I agree with the CI review that the earlier findings are resolved, but it does not cover the CHANGELOG or the merge. CI was still running at this head.
…e the hand-off row D30 One bullet per part of the change, and a Changed entry with the five things an existing team runs into on upgrade, before teamai starts deleting run branches. The engine notes still named the hand-off row by its number before the merge of main.
|
@SaulMoro both are in 202f791.
Sorry for answering this late: I acted on the CI review and missed your review until now. |
SaulMoro
left a comment
There was a problem hiding this comment.
This was generated by AI during triage.
Approving at 202f791.
Since 549900e this head changes only CHANGELOG.md and one word in docs/dev/workflow-engine.md, and both close what my last comment left open:
- CHANGELOG: four Features bullets, one per group of #1689, and a Changed entry that lists the five things an upgrade changes for a team, including the
hitl_requiredexit 1 that becomes ahandoffexit 0 for CI jobs. That was the part I most wanted written down. - D28 → D30: the skill-driver hand-off paragraph now names the right decision row.
No runtime code moved, so the real-CLI record from the earlier rounds still covers this head. The CI review of 549900e raised nothing we had not already resolved. The Codex review of this head is still running, and I'll read it before merging.
[P3 nit] The four new Features bullets sit after a blank line, apart from the existing bullets, so some renderers will show them as a separate list. Optional.
|
No new findings I’m confident are real in the specified diff.
I only read the specified diff and trusted base review criteria. I ran, built, and installed nothing from the PR. |
|
Thanks. I'm leaving the blank line before the four Features bullets as it is, so this head doesn't start another CI run and Codex review. If you'd rather have it fixed before merging, I'll push the one-line change. |
Summary
Running a software factory end to end hit four gaps (#1689):
resume --nextrefused any run that might need a person later;teamai/<run>/…branches;deliver: prstep with nothing to deliver looked the same as one that opened a pull request.This PR implements every decision in the issue's Resolution, plus its two smaller output notes, in one change.
Where it lives:
Dashboard: Member settings shows where
workflows.retentioncomes from. Handed-off runs say whether a run needs a person now or may need one later, with the claim command. A settled run's details list its Branches: kept with the reason, deleted, not deleted with the error, or kept for inspection with the datedoctor --fixmay remove them.The screenshots show the real dashboard page, with its API answered from typed fixtures.
Type of Change
Behavior that changes:
hitl_required;prread on a step withoutdeliver: pris now rejected bypull.Test Plan
npm run typecheckpassesnpm run lintpasses (oxlint plusnode scripts/check-docs.mjs)npx vitest runpasses: the full suite was not run; only the tests the change reaches (below)Every behavior was written test-first, at the public seam: parse diagnostics, local-driver runs, conformance scenarios.
LC_ALL=C npx vitest run --changed <base of the review fixes>, at1e497ee3LC_ALL=C npx vitest run --changed HEAD^1(after merging main)npx vitest run src/__tests__/workflow-reconciliation.test.tsnpx vitest run src/__tests__/workflow-leftovers.test.ts src/__tests__/workflow-run-controls.test.ts(latest commits)scripts/check-docs.test.ts,docs,default-workflows,workflow-skill-literals,workflow-conformance,workflow-git-conformance,dashboard-uinpm run test:e2e -- <file>npx vitest run --changed HEADReal CLI, built
dist/, scratch repos with bare origins, fakeclaude/gh. Provider:git; agent: Claude. Other providers and agents are left to CI.1.
workspace: newheader: on its own, and insideship-issue's copy2. A runner takes a run, offers it back at a person step, a second runner leaves it, a person finishes it
3. Success cleanup, then a retry brings the branches back
4.
fix-ci:steps.fix.pr == nullpicks the endRelated Issues
Closes #1689
Notes for Reviewers
Decisions that go beyond the Resolution, or read it one way:
workflows.retention,doctor --fixalso deletes a succeeded run's final copy branch; PR branches stayretainedUntil, set once, published with the run)run_expiredbranches_not_restoredwhen one is at a different commitnextgets nobranchfield; drivers read the copy from the run filenextAfter merging #1700:
D30toD32, becauseD28andD29are now feat(scorers)!: judge every pass and session through teamai-score, a default workflow a team can override #1700's.Known limitation: a narrow race between two installs. Install A has just succeeded and its cleanup is deleting branches. In that same window, install B claims the run, retries it, and publishes the reopened run. A's deletion can then remove a branch B restored, and B's next end reports
commit_missing.teamai-reports, that claim and retry wait on. That is a distributed lock for a sub-second window, so I left it out. I'd like a maintainer's call.Accepted residual: a retry that starts before the deadline and is still running 7 days after it can lose branches to another install's sweep.