Skip to content

feat(platform): pause issue desk on NEEDS_HUMAN with a shared workflow sandbox - #2542

Merged
yannickmonney merged 8 commits into
mainfrom
cursor/issue-desk-human-resume
Jul 7, 2026
Merged

yannickmonney merged 8 commits into
mainfrom
cursor/issue-desk-human-resume

Conversation

@larryro

@larryro larryro commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

What

The issue desk now runs its four phases — Advise → Execute → Grade → Dream — on one shared sandbox workspace per workflow execution (sessionScope: "workflow"), and an ambiguous plan (NEEDS_HUMAN) pauses the same run for a human plan review instead of dead-ending at In review. Approve resumes implementation on the same workspace; Request changes sends feedback back to the advisor (two bounded rounds, then park for manual takeover).

Mechanism

  • Shared session — sandbox agent steps opting into sessionScope: "workflow" reuse one deterministic session (wf-<exec>-…, owner <exec>:@workflow); per-step durable checkpoints (<session>::<step>); torn down by on_workflow_complete / user Stop (owner-range sweep).
  • Pause — the pre-existing request_review approval gate (idempotent per execution+step); the engine parks on awaitEvent with no timeout.
  • Hibernate on pause — a fresh review request flips the session row to stopped, freeing its per-org workflow slot for the whole wait (scheduled from createTaskReviewRequest, deliberately not a journaled engine step — that would break replay of in-flight paused executions).
  • Resume — re-admission goes back through the FIFO ticket queue (resumeWorkflowSessionSlot; a hibernated row must not jump to cap+1), then sessionIsAlive → sessionCreate re-attaches the preserved workspace when the spawner's idle/TTL sweep reclaimed the container mid-pause.
  • Loop hygiene — collect-dir pre-clean per fresh segment (a stale summary.md/grade.json would fake summaryWritten / feed the judge old data); step checkpoints dropped on every terminal path so rework/replan re-executions of the same slug never resume a dead exec; the judge's wrong_approach replan loop is bounded like the rework loop.

Notable review fixes folded in (the branch's original commit had these): variables.* is only populated by set_variables — the unguarded variables.planReviewRound == 0 gate meant the pause never fired (first NEEDS_HUMAN fell straight to the exhausted path); round-aware decide + approve-side round bump so a recorded approve can't replay into a later NEEDS_HUMAN cycle; budget-exhausted re-entry no longer destroys the shared workspace.

UI

  • The review gate mounts the interactive TaskReviewCard in the run view (pending) and renders the outcome + feedback once responded (was: raw JSON, then an empty body).
  • Branch variants sharing a ui.labelKey collapse into one spine lane (no more "Review the plan: Done" next to "Review the plan: Up next" + three "Capture lessons" twins).
  • Per-step stage chip dropped (the StageTimeline breadcrumb owns that dimension); the role chip gains a bot icon.
  • Tasks tables get a "Review" row action (when: "pendingReview", new effect-only action primitive) opening the task detail overlay — same column and pattern as Start / Merge pull request.

Verification

  • Unit/integration: new tests for session naming collision (:@workflow), the pause graph + replan bound + (… || 0) guards, dedupeSpineLanes, review-panel outcome states, collectPendingReviewsByTask, effect-action discrimination. Targeted suites green (server 2223 + tasks 1073 + UI 41/85); full server+pii run has 13 failures in known-flaky convexTest suites (SCIM/conversations/slack/cancel-codes) that pass in isolation and touch nothing in this branch.
  • Live E2E on the dev stack (real GitHub issue Bug: tale.dev contact form returns 503 — WEB_DISCORD_WEBHOOK_URL unset in the production web deployment #2389): NEEDS_HUMAN → paused at the review gate with the actionable card; session hibernated (slot freed); container reaped by the spawner TTL during the pause; Approve 27 min later → FIFO re-claim → container re-created against the preserved workspace (.git + .desk/plan.md intact) → implementer continued per the plan without re-cloning.

Notes for operators

Installed apps snapshot their bundle at install time — picking up the new workflow/view/agents requires an app Reinstall (env/secrets survive; per-agent runtime overrides currently don't — known gap, tracked separately).

Done checklist

  • Green gate — oxfmt / oxlint / tsc / targeted vitest suites green (flaky-suite caveat above)
  • Security gate — opengrep clean on every commit (pre-commit hook)
  • Tests — happy + edge + error paths for every new behaviour
  • Migration — N/A: sandbox layer unreleased; no schema change (pendingReview is computed)
  • Locales — en/de/fr for every new user-visible string
  • Docs — N/A: docs don't cover sandbox step config or the desk app (verified)
  • Accessibility — real controls, labelled buttons, aria-hidden icons, AA badges
  • Sweep — :workflow owner refs, resumeStoppedSession callers, action-spec consumers, stage-chip surfaces
  • Observed — full pause→hibernate→reap→approve→resume loop watched live end-to-end
  • Commits — 7 atomic conventional commits, no attribution lines

larryro added 8 commits July 7, 2026 15:12
Reuse one workflow-scoped sandbox across advise/execute/grade/dream and
resume the same run via TaskReviewCard instead of ending at In review.
Review fixes for the NEEDS_HUMAN pause + workflow-scoped sandbox:

- Seed-less variables namespace: config.variables lands under config.*,
  so `variables.planReviewRound == 0` was false on the FIRST
  NEEDS_HUMAN and the pause never fired (fell straight to the
  exhausted path). Guard every pre-bump read with `(… || 0)` and drop
  the misleading seeds.
- Resume a hibernated session: re-claim the per-org slot through the
  FIFO ticket queue (new resumeWorkflowSessionSlot; a stopped row must
  not jump to cap+1), probe sessionIsAlive, and re-create against the
  preserved workspace when the spawner idle/TTL sweep stopped the
  container — resuming after a >35 min pause previously died on
  SessionNotFound and rolled the task back.
- Hibernate on pause: a fresh task-review request stops the
  workflow-scoped session row so a paused run frees its org slot for
  the whole wait (scheduled from createTaskReviewRequest, not from the
  durable handler — a journaled step would break replay of in-flight
  paused executions).
- Bound the judge's wrong_approach replan loop (bump_replan +
  replan_gate on maxReworkLoops) — it previously looped
  Advise+Execute+Grade until the workflow timeout.
- Round-aware plan_review_decide + bump planReviewRound on approve so
  a stale approve can never auto-pass a later NEEDS_HUMAN cycle
  (request_review replays its recorded decision per (execution, step)).
- Pre-clean the shared collect dir each fresh segment: a stale
  summary.md faked summaryWritten (masking laundered API errors) and a
  stale grade.json fed the judge the previous round's grade.
- Keep the shared session alive through a step's budget-exhausted
  re-entry; drop the step checkpoint on the fail() and
  SessionNotFound-resume paths so same-slug re-executions start fresh.
- Schedule completion teardown outside the wasTerminal gate so a
  pre-failed execution still releases its shared session.
- advise_check/grade_check failure routes, execId-filtered
  getWorkflowSandboxOp (no cross-step op shadowing), `:@workflow`
  owner/hash suffix (a step slugged `workflow` collided), indexed
  checkpoint delete, gradeJson re-harvest after the summary re-entry,
  lint fixes, stale desk-implementer wording.
The `review` render kind mounts the interactive TaskReviewCard only
when the step output carries a `taskId`; request_review returned only
{approvalId, pending, responded}, so the desk's plan-review pause
rendered as a raw JSON dump under "Awaiting approval" instead of the
Approve / Request changes card. Ride the taskId along in the action
output.
The desk v2 workflow has mutually-exclusive variants of one concept —
two plan-review gates (round 0/1), one dream step per judge verdict —
and the run view rendered each as its own lane, so an execution showed
"Review the plan: Done" next to "Review the plan: Up next" plus three
"Capture lessons" twins for steps that will never run.

Steps sharing a ui.labelKey now collapse into a single lane
(dedupeSpineLanes in the shared step_display module): variants the run
actually touched all show (both review rounds when both happened), and
while none has run the first stands in as the lane's one upcoming
placeholder. Steps without a labelKey keep their own lane.
Every lane showed two same-looking chips ("work" + "implementer") with
no cue that one is the pipeline stage and the other the acting agent
role. The StageTimeline breadcrumb already owns the stage dimension, so
the per-step stage chip only duplicated it; the role chip now carries a
bot icon so it reads as the step's actor.
… body

After a human responds, the resumed step persists the recorded decision
and TaskReviewCard (which only shows PENDING reviews) rendered nothing —
an expanded "Review the plan: Done" lane showed an empty card. A
responded gate now shows an Approved / Changes requested badge plus the
reviewer's feedback; the pending path (interactive card / question
fallback) is unchanged.
A task waiting on a human review had no affordance in the app's task
table — the row where every other waiting state already gets its verb
(Start for todo, Merge pull request for in_review). Reviews are the
same kind of thing: a state with one obvious action.

- listTasksByProjectPaginated stamps each row with `pendingReview`
  (one bounded org-level pending scan, extracted from
  getTaskOpsIndicators into a shared collectPendingReviewsByTask).
- Connected tables learn effect-only actions (EffectActionSpec /
  EffectButton): a button that applies a declarative effect against
  the row instead of calling a function.
- The desk view gains a "Review" action (`when: "pendingReview"`)
  that opens the task's detail overlay — the embedded run view where
  the pending review card (Approve / Request changes) already lives.

Reaching the new view config in an installed org still requires an app
Reinstall (bundle files are install-time snapshots).
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.

2 participants