# fix\(server\): drain queued native child continuations · PR \#21461 · pingdotgg/t3code

[View on GitCafe](https://git.cafe/pingdotgg/t3code/pull/21461)

Repository: [pingdotgg/t3code](https://git.cafe/pingdotgg/t3code)

Visibility: public

State: open

Source repository: pingdotgg/t3code

Source branch: takeover/opencode-continuation-ingestion

Target branch: takeover/opencode-pending-snapshots

Head commit: 1b052a2d9df4a7c4772ec5c690c67c234d9fa008

[Discussion and reviews](https://git.cafe/pingdotgg/t3code/pull/21461)

[Commits](https://git.cafe/pingdotgg/t3code/pull/21461/commits?format=markdown)

[Files changed](https://git.cafe/pingdotgg/t3code/pull/21461/diffs?format=markdown)

## Description

---

## Problem

A root turn can complete while native child continuation events remain queued. Consulting live adapter state then closes ingestion early and drops that continuation's output.

## Change

Consume ordered pending-work snapshots from the OpenCode adapter and keep ingestion open until owned child work drains. Remove snapshots when a child transfers to another run, so stale state cannot retain the old subscription. Other adapters retain the existing thread-scoped probe.

## Scope and approval
Fixes #19228

Triaged bug via the automated issue flow. Preserves the existing maintainer takeover of [#19388](https://git.cafe/pingdotgg/t3code/pulls/19388), stacked on [#21460](https://git.cafe/pingdotgg/t3code/pulls/21460). Main is merged into the preserved branches; no history was rewritten.

## Verification

The test-only follow-up [1b052a2d9d](https://git.cafe/pingdotgg/t3code/commit/1b052a2d9df4a7c4772ec5c690c67c234d9fa008) adds retained-descendant drain coverage. The service file passes 49/49 tests ([log](https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/58a846f7a626dedd/retained-descendant-final.log)); on the earlier test-fixture revision, clearing all descendant pending entries fails the pending-work case ([mutation proof](https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/4665a3b6f4bbe26d/nested-pending-mutation.log)). Production files are identical to the previously verified publication head, so the runtime evidence below still applies. This coverage establishes retention and release; it does not assert exclusive ownership during session reuse.

Independent follow-up proof audit: SUFFICIENT; publication and tested trees match.

- Baseline main [8d3b061121](https://git.cafe/pingdotgg/t3code/commit/8d3b061121): both ownership variants drop all queued child events. [Original red proof](https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/5d5743bf3f75fdae/19228-current-main-red.log).
- Wake-replay regression: a session holds a wake while top-level, becomes another session's child, and consumes the wake. Without ancestor refresh, its caller remains pending (`expected true to be false`); with the fix, both snapshots clear. [Red](https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/545d9cc00a16511b/red-unfixed.log) | [Green](https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/ae63eb4288c808a2/green-fixed.log).
- Final code passes 250 tests across the service, adapter, and OpenCode package suites, plus all 22 replay fixtures. The focused service/adapter/replay subset is 149 tests. [Scoped log](https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/a89d9428aa85893d/scoped-tests.log) | [Replay log](https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/c1a80e8d8028bf8a/replay-final.log). Server and OpenCode package typechecks and targeted lint pass.
- Two fresh independent reviewers, GPT-6.1 Sol and Claude Opus 5.5, returned MERGE for the ancestor correction. The earlier transfer cleanup remains covered, including independent pending siblings and subscription release after drain.
- Real isolated web dev app on Linux fs-05, OpenCode 2.0.32, `opencode/deepseek-v4.1-flash-free`, `subagent_depth=2`, committed nested-background fixture prompt: root completes at 10:47:30.082, grandchild output persists at 10:47:59.653, middle continuation runs at 10:47:59.743 and completes at 10:48:02.173. Final thread snapshots are idle with empty pending tasks. [Ordered final-code runtime](https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/4dec0d65394d58cf/runtime-followup.txt).
- Tested [587227c136](https://git.cafe/pingdotgg/t3code/commit/587227c136) and published top [31b509cecc](https://git.cafe/pingdotgg/t3code/commit/31b509cecc) have identical trees, including dependency [4cc74410d2](https://git.cafe/pingdotgg/t3code/commit/4cc74410d2). [Revision and scope manifest](https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/bb0a7b2a396d7fb8/followup-manifest.txt).
- Baseline live runs also succeeded: runtime evidence establishes compatibility; deterministic tests establish the races. Live ownership-loss, restart, and the reused-root held-wake edge were not exercised. The latter is covered by the adapter regression. The direct `takeRunningWake` counterpart lacks its own test; both replay sites use the same correction. Service tests, rather than UI idle state, prove subscription release and exclude an `after-drain` sentinel.
- Server-only change: visual fixture matrix is empty; no rendered UI changed.

Models: GPT-6.1 Sol and Claude Opus 5.5, Codex/Claude harnesses through T3 Code.

