Skip to content

fix(server): treat remote delegated tasks as app-owned on stop and restart - #42069

Merged
juliusmarminge merged 3 commits into
pingdotgg:mainfrom
lryoooow:fix/remote-delegated-task-guards
Nov 24, 2026
Merged

juliusmarminge merged 3 commits into
pingdotgg:mainfrom
lryoooow:fix/remote-delegated-task-guards

Conversation

@lryoooow

Copy link
Copy Markdown
Contributor

Remote tasks delegated to a linked environment (origin: "app_owned", childThreadId: null, remoteChild: { ... }) were missed by two server guards that only checked childThreadId !== null:

  1. Orchestrator.dispatchThreadStop: skipped enqueuing delegated-tasks.stop when a parent thread only had remote delegated tasks, leaving remote tasks running on the linked environment after Stop—even though ThreadManagementService.stopDelegatedTasks already stops remote tasks (the existing test in RemoteDelegation.test.ts called stopDelegatedTasks directly instead of dispatching thread.stop).
  2. RestartContinuation.hasOpenAwaitedWork: treated an open remote delegated task turn item as cancelled provider background work on server restart, causing restartContinuationRun to wake an already-settled (completed / waiting) parent run—even though ProviderRuntimeRecoveryService.isAppOwnedDelegation (updated in feat(server): delegate_task to a linked environment #16719) intentionally keeps remote delegated tasks open to report back via RemoteDelegation.

Fix

  • Include remoteChild !== undefined alongside childThreadId !== null in Orchestrator.ts (dispatchThreadStop) and RestartContinuation.ts (hasOpenAwaitedWork), matching ProviderRuntimeRecoveryService.ts.
  • Left hasRunningDelegatedTasks (thread.archive) unchanged, since RemoteDelegatedTask.test.ts explicitly requires remote tasks not to block local archiving.
  • Added regression tests in RemoteDelegation.test.ts and RestartContinuation.test.ts.

Verification

Reproduced on unmodified origin/main (fc91bfdf6c) before applying the fix:

  • vp test run apps/server/src/peer/RemoteDelegation.test.ts -t "thread.stop enqueues delegated-tasks.stop for remote-only delegated tasks" failed with AssertionError: expected false to be true (orchestration_v2_effect_outbox contained no delegated-tasks.stop effect).
  • vp test run apps/server/src/orchestration-v2/RestartContinuation.test.ts -t "does not continue a settled run whose only open subagent is a remote delegated task" failed with AssertionError: completed: expected { id: 'run:restart', ... } to equal undefined.

After applying the fix:

  • vp test run apps/server/src/peer/RemoteDelegation.test.ts — 53/53 passed.
  • vp test run apps/server/src/orchestration-v2/RemoteDelegatedTask.test.ts — 4/4 passed.
  • vp test run apps/server/src/orchestration-v2/RestartContinuation.test.ts — 55/55 passed.
  • vp run check:changed — format, lint (0 warnings / 0 errors), graphql (apps/server), and typecheck (3 packages) all passed.

Gemini 4 Neon in Antigravity

@github-actions github-actions Bot added vouch:unvouched Author is not yet trusted in the VOUCHED list. size:S 10-29 changed lines (additions + deletions). labels Nov 24, 2026
@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Restart continuation checks and parent-thread stop dispatch now account for remote-child metadata on app-owned delegated tasks. Tests cover completed and waiting runs and verify that stopping a parent thread adds a delegated-task stop effect to the outbox.

Changes: Remote delegated-task lifecycle

Layer / File(s) Summary
Restart continuation checks
apps/server/src/orchestration-v2/RestartContinuation.ts, apps/server/src/orchestration-v2/RestartContinuation.test.ts
hasOpenAwaitedWork accounts for remote-child metadata when evaluating app-owned subagent items. Tests check that completed and waiting runs are not selected for restart continuation in the described case.
Parent-thread stop dispatch
apps/server/src/orchestration-v2/Orchestrator.ts, apps/server/src/peer/RemoteDelegation.test.ts
dispatchThreadStop schedules delegated-task stopping for app-owned tasks with a defined remoteChild. A test checks for the resulting stop effect in the orchestration effect outbox.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: juliusmarminge, maria-rcks

Merge Risk: Minimal · up to 08fa0

This change makes stopping a parent thread also stop its remote delegated tasks, and keeps a settled run from resuming after a restart because of an open remote task. The change is small and has regression tests. No merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the fix and its scope: remote delegated tasks treated as app-owned on stop and restart. The changeset matches it: Orchestrator.dispatchThreadStop and RestartContinuation.hasOpenAwaited…
Description check Passed The description follows the template. It gives the problem (two server guards missed remote delegated tasks), the change (adding remoteChild checks in Orchestrator.ts and RestartContinuation.ts, with …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the fix and its scope: remote delegated tasks treated as app-owned on stop and restart. The changeset matches it: Orchestrator.dispatchThreadStop and RestartContinuation.hasOpenAwaitedWork both now check remoteChild alongside childThreadId. The title is specific and follows conventional commit style, though it does not mention the tests.

Full details: Description check

Explanation

The description follows the template. It gives the problem (two server guards missed remote delegated tasks), the change (adding remoteChild checks in Orchestrator.ts and RestartContinuation.ts, with rationale for leaving hasRunningDelegatedTasks unchanged), and scope (regression tests added, linked to PR #16719 and the related test files). Verification lists reproduced failures before the fix, the passing test runs after it, and the checks run. The template's Scope section asks for a linked issue that shows the bug. The description references no issue number, and it does not say why an issue is unnecessary, so this section is incomplete. The description also does not say whether the changes are a bug fix or a feature, which the template asks the author to address.

Resolution

Optionally, link the issue that shows the bug in the Scope section, or explain why no issue is needed for this small fix. The description already covers the other sections.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 19c129c and 08fa0d9.

Files selected for processing: 1

  • apps/server/src/peer/RemoteDelegation.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

@juliusmarminge juliusmarminge added the takeover:in-progress A takeover lead is working on this PR label Nov 24, 2026
@juliusmarminge

Copy link
Copy Markdown
Member

Evidence

Both real-app scenarios failed on base and passed on head. Environment: Linux, Chromium, 1280×800, light theme, fresh linked servers and synthetic projects, replay agents.

Steps: launch an async remote question task through the parent's MCP session, press Stop, and inspect the remote child. Separately, let a parent settle with an open remote task, SIGTERM and restart its server, then inspect the parent, child, and continuation outbox.

Before 47329274bc After 08fa0d92d6
Stop result Remote child still running after 30 seconds Remote child interrupted
Child after Stop Before: remote child remains working After: remote child interrupted
Stop recording Before After
Restart continuation effects One unnecessary provider-runtime.continue effect, consumed after restart None queued
Parent after restart Before: settled parent with running remote task After: settled parent with running remote task
Restart recording Before After

Both restart runs retained one completed parent run and a running remote child. Neither produced an extra visible parent turn; the reproduced difference is the unnecessary internal continuation effect. Captured runtime observations.

Stop scenario · Restart scenario.

Recordings are trimmed around the actions and finish with the corresponding captured result held for three seconds; teardown disconnection screens are excluded.

Not shown:

  • Remote task completion and report-back after restart were not verified: the final comparison leaves the child awaiting its replay question; an optional answer attempt could not enable Submit.

@juliusmarminge juliusmarminge added takeover:ready Takeover done; auto-lands when gates pass and removed takeover:in-progress A takeover lead is working on this PR labels Nov 24, 2026
@juliusmarminge
juliusmarminge merged commit 15afd7f into pingdotgg:main Nov 24, 2026
18 checks passed
@juliusmarminge juliusmarminge removed the takeover:ready Takeover done; auto-lands when gates pass label Nov 24, 2026
AIdoesmyjob pushed a commit to AIdoesmyjob/t3code that referenced this pull request Nov 24, 2026
…start (pingdotgg#42069)

Co-authored-by: Julius Marminge <julius0216@outlook.com>
(cherry picked from commit 15afd7f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S 10-29 changed lines (additions + deletions). vouch:unvouched Author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants