Skip to content

fix(platform): recheck queued retries and move live workflow parents - #3908

Merged
yannickmonney merged 7 commits into
mainfrom
fix/task-run-retry-archived-project-and-parent-moves
Sep 29, 2026
Merged

yannickmonney merged 7 commits into
mainfrom
fix/task-run-retry-archived-project-and-parent-moves

Conversation

@yannickmonney

@yannickmonney yannickmonney commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Two fixes for how task runs start and stop. Both reuse the task domain's existing admission and status choreography.

A queued retry rechecks the project before it starts work (#3737)

A task agent's automatic retry is a task.agent_retry job queued when a run fails. The handler (backend/jobs/task-list.ts) checked the task again under a lock (archived task, status, assignee, newest run, budget, agent), but never looked at the project or at who started the run. So a retry delivered after the project was archived still committed a queued auto_retry run and its task.agent_turn job, while the manual Start on the same task answered 403 PROJECT_ARCHIVED. The same held for a starter who had been removed from the organization, disabled, or dropped from the project's team, or who could no longer work the task.

  • New deferredAgentKickRefusal in backend/domains/tasks/service.ts, next to the manual Start. It is the manual Start's work gate from feat(platform): let members create tasks and work their own #3810 (mayWorkTask: an editor of the project, or a member whose own task it is), run now for the person whose kick the retry continues, on an active project. The member lookup and auth context use the canonical findOrganizationMember + getProjectAuthContext. A trigger-started run names no person, so the project alone decides; a starter that names nobody is refused.
  • It holds the project row FOR SHARE until the caller commits. An archive, a sharing change or a delete then orders around the admission, the same way lockRestProjectForWrite and thread creation order theirs.
  • The retry handler calls it inside its own transaction, just before kickAgentRun, and keeps every existing guard. A refusal (project_archived, project_unavailable, not_permitted) is a logged skip, never a thrown job, so pg-boss never retries a refusal that is final.
  • The other deferred kick, the steer that misses its run and starts a fresh mention run (kickMentionRunAfterSteerMiss), already checked its author's work rights after feat(platform): let members create tasks and work their own #3810, but outside the kick's transaction. It now runs the same helper inside that transaction, so an archive can't land between the check and the run. An archived project also answers project_archived there now; not_permitted keeps its meaning.
  • This PR covers admission only. It does not change a run that was already queued before the project was archived.

A live workflow parent moves to To do (#3738)

Moving an automation-owned task out of In progress while its run was live went through POST /api/app/tasks/:taskId/workflow/cancel. That door parks the task at Cancelled, and the choreography hook made the plain move only afterwards. Cancelled is a close, so a parent with an open subtask was refused on its way to To do with the generic error. When there were no subtasks, the move recorded two status changes and fired two task.status_changed events (to Cancelled, then to To do).

  • The door takes an optional {status, beforeTaskId, afterTaskId} body (the move door's own fields). The destination can be anything but in_progress, and it defaults to cancelled, so a stop with no body behaves as before. In its one serializable transaction the door cancels the run (cancelRunInTx) and moves the task with the board's own moveTask, at the drop position. Only Done and Cancelled meet the open-subtask guard, and a refused move rolls the stop back with it: the run, its question, its approval, the task and its history stay as they were. taskCancelled now says whether the task sits at Cancelled.
  • useTaskStatusChoreography sends the target (and the board drop's placement) with the stop, and returns handled: the stop already moved the card, so no second write follows. The cancel plan no longer carries alsoMove.
  • A refused close shows its reason, Finish all subtasks before closing this task., instead of "Something went wrong". So does the automation panel's Cancel run, which still parks at Cancelled and so is still refused while subtasks are open. The check lives in one helper (parentCloseRefusal), which the task dialog's existing guard now uses too.

Docs (EN/DE/FR): tasks.md says only Done and Cancelled wait for open subtasks. task-automation.md says an automatic retry, or a late mention, starts only while the project is active and the starter may still change the task, and that moving an automation's task stops its run and moves it in one step. The manual suite gains TASK-B29, plus two rows in reference/automation.md. No UI strings were added: the copy reuses tasks.detail.parentCloseGuard, tasks.run.cancelled and common.errors.generic.

How I verified it

  • Native Postgres lanes (backend:integration, a filtered run; the harness is not a CI job). The queue and the engine are inert: every job these lanes cause is held a day inside the writing transaction and delivered by hand, runs are rows parked on a question, egress is blocked, and nothing executes.
    • checkTaskRetryProjectEligibility drives the production failure mark, retry handler, archive/restore service and steer-miss kick. It covers:
      • an eligible project, including a duplicate delivery;
      • archived after queuing (next to the manual Start's 403 PROJECT_ARCHIVED), then restored before a later delivery;
      • a starter removed from the organization, demoted to read-only on a task that isn't theirs, disabled, or moved out of the project's team;
      • a read-only member on a task of their own (retried, per feat(platform): let members create tasks and work their own #3810's rule), a team member of a team project, and one who left the team;
      • an archived task;
      • an archive racing a retry that already passed the check: the archive waits on the lock;
      • a retry delivered while an archive is in flight: it waits, then refuses;
      • the steer-miss kick.
    • checkTaskWorkflowParentMoves drives the door over HTTP. It covers open, finished and no subtasks; To do, Backlog, In review, Done, Cancelled and a stop with no body; the drop position; In progress as a destination; a read-only member; and a run that already ended. For refusals it checks that task, run, question, approval, history and audit rows stay identical. Since the review round it also covers a stop that finds the task already moved to its column by another session (the P3 finding, fixed in 7424481e0): the drop's place still applies, as a reorder with no status change. That check passes with the fix and fails with the previous condition, where the card kept its end-of-column rank (the lane is 29/29 against 28/29).
    • On this branch: 68/68 checks across checkTasks, checkTasksOrgIsolation, checkTaskRunStartFence and the two new lanes, rerun on the head e632755b8. With the implementation reverted to main and the lanes kept: 25/41. 16 of the lanes' 24 checks fail, every one a case of the two bugs; the 8 that pass are the controls (an eligible retry, a member's own task, an archived task, the three closing-move refusals, the default stop, the refused requests). After feat(platform): let members create tasks and work their own #3810, main's steer-miss already refuses an archived project, but as not_permitted and outside its transaction; the lane pins the share-locked check and its reason.
  • Unit and component tests: task-list.agent-retry.test.ts (+12 cases), agent-turn-shim.steer-fallback.test.ts (+1, and its fake now answers the kick's transaction), new routes.workflow-stop.test.ts (11), new use-task-status-choreography.stop.test.tsx (10), plus cases in use-task-status-choreography.test.ts, use-task-board-dnd.test.tsx and task-subject-panel.test.tsx. With the fix reverted and the tests kept, 20 of 33 backend cases and 11 of 33 UI cases fail.
  • Local sweep of everything that imports the changed files: backend/domains/tasks + the job tests (50 files, 537 tests) and app/features/tasks (58 files, 424 tests), the error-message and single-toast guards (61), the docs suite (36 files, 200 tests), oxlint --type-aware and oxfmt on every changed file, and a scoped tsc over the changed app files, the changed backend files and integration-check.ts. Also bun run lint:manual and check-guide.ts on the tasks suite. The host was shared and loaded (load average 40–150): a handful of jsdom cases hit the 5 s timeout and one vitest worker failed to start. Each of those files passed when re-run alone with --maxWorkers=1 --testTimeout=120000.
  • Observed in Chromium on a local stack: the API role, so no job worker ran; a deployed automation with a task contract; parents whose runs wait on a question; open subtasks.
    • Base code: dragging the parent to To do shows "Something went wrong — try again, or reload the page if it keeps happening.", the card snaps back, and the run keeps waiting.
    • This branch: the confirm, then "The run was cancelled."; after a reload the card sits in To do where it was dropped, with its subtask open and one In progress → To do history line. Dragging to Done shows "Finish all subtasks before closing this task.", the card stays in In progress, and the run keeps waiting. Through the status picker in German, the Done refusal reads "Schließe alle Teilaufgaben ab, bevor du diese Aufgabe abschließt."; in French, the To do move reads "L'exécution a été annulée." and lands the task in À faire.
    • The automation panel's Cancel run on a parent with an open subtask shows "Finish all subtasks before closing this task.", and the run keeps waiting with its question open.
    • bug(platform): a queued task retry creates new agent work after its project is archived #3737: on an archived project, the task shows its failed run and no automatic retry. After a restore, delivering the same job shows "Queued · Auto-retry 1 of 3".
    • The P3 race, with two signed-in sessions on c9a04259a:
      1. Session A drags a parent onto the top edge of a To do card and leaves the confirm open.
      2. Session B stops the same run from the status picker. That stop names no place, so the task goes to the end of To do.
      3. A's confirm stays open over a board that already shows B's move. A confirms: 200, nothing left to cancel. The card lands between the two cards A's drop named, with no second status change. After a reload both sessions show the same order.
      4. With only 7424481e0's condition reverted, the same flow shows the same toast, but the card stays at the end of the column.
  • Visual gate (visual-aspect-analyzer, signed in, the production bundle, the To do and Done drags). In its full mode the instrumented board page stalled on this shared host, even for a screenshot, while the log-in page scored 100. With pixel capture off it completed: 99 for both drags on this branch, against 98 and 79 on main's bundle. The defects left are the same page-load layout shifts in both runs (the board's "Loading content" skeleton, the Automations and Environment tabs, an icon), plus a 0.002 shift of the neighbouring card while a refused drag snaps back. main's run showed jank on that same snap-back.

The workspace-wide gates (full tsc, the full suites, knip, the e2e shards) are left to CI.

Not changed here

  • An agent-owned task (not an automation's) still cancels its run in its own request before the move. The status door would cancel it in the same transaction anyway, but the separate call reaps the sandbox exec at once. So an agent-owned parent moved to Done with open subtasks still loses its run before the close is refused. Making it atomic means moving that immediate reap into the status doors, so it deserves its own change.
  • The assignee hand-off still stops an automation's run through the default stop, which parks at Cancelled, so reassigning such a parent with open subtasks is still refused, with the server's sentence under the default error toast. Where a handed-off task should land is a product decision.
  • Archiving a project does not stop runs that were already admitted. This PR covers admission only, as bug(platform): a queued task retry creates new agent work after its project is archived #3737 does.

Merge order

This is meant to land after #3881. Both change task-subject-panel.tsx and its test, the harness lane table, and the manual readme and register. #3881 wraps TaskSubjectPanel in a component keyed by task id; this PR's two handler edits then move into its body. The rest is keeping both sides. The two PRs' new manual boxes have distinct IDs (TASK-B28 there, TASK-B29 here).

Closes #3737
Closes #3738

yannickmonney added a commit that referenced this pull request Sep 29, 2026
…ed-search-recovery

The manual readme counts main's boxes plus this branch's six (989). Three of this branch's new boxes collided with IDs other open PRs add — TASK-F51 (#3813), TASK-B28 (#3881), TASK-B29 (#3908) — so they move to TASK-F52, TASK-B32 and TASK-B33, in the suite, pins.md and the automation register.
A task agent's automatic retry is a job queued when a run fails, and it
admitted a new queued run and its turn job without looking at the project
or at the person whose kick it continues. Archiving the project, or taking
that person's access away, after the failure did not stop it, while the
manual Start on the same task answers 403 PROJECT_ARCHIVED.

The retry now passes deferredAgentKickRefusal inside its own transaction
before it creates anything. It is the manual Start's work gate
(mayWorkTask) run for the run's starter as things stand now, on a project
row held FOR SHARE, so an archive, a sharing change or a delete orders
around the admission instead of landing between the check and the run. A
refusal is a logged skip, never a thrown job, because a retried job would
only meet it again. The steer that misses its run and starts a fresh one
checked its author outside its kick's transaction; it now runs the same
helper inside it.

The native lane checkTaskRetryProjectEligibility drives the production
failure mark, retry handler, archive service and steer-miss kick on real
Postgres with an inert queue, including duplicate delivery and an archive
racing the retry.
Moving an automation-owned task out of In progress while its run was live
went through the workflow cancel door, which parks the task at Cancelled,
and only then made the move. Cancelled is a close, so a parent with an open
subtask was refused on its way to To do with a generic error, and every
move that did succeed recorded two status changes and fired two status
events.

The door now takes the destination and the drop position, and runs the run
cancel and the board's own move (moveTask) in its one transaction. Without
a body it still parks the task at Cancelled. Only Done and Cancelled meet
the open-subtask guard, and a refused move takes the stop down with it, so
the run, its question and its approval stay as they were. The choreography
hook hands its target and placement to the door and shows the parent close
guard's own sentence for that refusal, as the automation panel's Cancel
run now does too.

The native lane checkTaskWorkflowParentMoves drives the door over HTTP on
real Postgres with parked runs, for open, finished and no subtasks and for
open and closing moves. The guides say that only a close waits for
subtasks, and the manual suite gains TASK-B29.
@yannickmonney
yannickmonney force-pushed the fix/task-run-retry-archived-project-and-parent-moves branch from b66ced4 to faeafc5 Compare September 29, 2026 14:33
…chived-project-and-parent-moves

The task suite keeps main's new boxes (#3906) and this branch's TASK-B29 after them; its Cost is 99.

@yannickmonney yannickmonney left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent review at 38cd26a22d2c8e5d85943b4252a0f4358b0e370f: one non-blocking P3 placement finding below. No additional admission/security defect confirmed within the reviewed scope. Parent replay: 28 inert native-handler and 11 Chromium hook cases passed. The specialist also ran 61 exact-source unit cases. No merge/deployment or whole-application acceptance is implied.

yannickmonney and others added 4 commits September 29, 2026 17:41
…hed its column

When another session moved the task into the target column while the stop dialog was open, the workflow-stop door skipped moveTask and with it the drop's beforeTaskId/afterTaskId, so the card stayed at its old rank. A default stop on a task already there still writes nothing; a drop that names a place now applies it.
The review fix makes the workflow stop door apply a drop's place when the
task already sits in the target column. The native lane now drives that
race: a first stop moves the parent to To do, then a second stop naming the
drop's neighbours re-ranks it between them and records no status change.
The check passes with the fix and fails with the previous condition, where
the card kept its rank at the end of the column.
…chived-project-and-parent-moves

The manual readme is recounted on the merged tree (1003 boxes), and the task suite's Cost is 100: main's TASK-F51 (#3813) and this branch's TASK-B29 each merged into a header both sides had set to 99.
A11Y-A19 (#3853) and A11Y-A20 (#3895) each raised the header from 26 to 27 on their own branch; with both merged the suite holds 28 boxes.
@yannickmonney
yannickmonney merged commit bda0e89 into main Sep 29, 2026
50 checks passed
@yannickmonney
yannickmonney deleted the fix/task-run-retry-archived-project-and-parent-moves branch September 29, 2026 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant