# fix\(opencode\): publish ordered pending-work snapshots · PR \#21460 · pingdotgg/t3code

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

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

Visibility: public

State: open

Source repository: pingdotgg/t3code

Source branch: takeover/opencode-pending-snapshots

Target branch: main

Head commit: 9b97de29a6bf8bbe3d10c29c6fb6eb80e129f37c

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

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

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

## Description

---

## Problem

Native nested background work can remain queued after a root turn ends, while ingestion sees only the adapter's newer idle state. Ordered pending-work state is needed to retain the queued continuation.

## Change

Publish optional pending-work snapshots in stream order and refresh ancestors after settlement, cancellation, reconciliation, and wake replay. Descendants refresh before ancestors. The consumer is [#21461](https://git.cafe/pingdotgg/t3code/pulls/21461).

## Scope and approval
Fixes #19228
GitCafe: https://git.cafe/pingdotgg/t3code/issues/19228
Triaged bug via the automated issue flow. Preserves the existing dependency layer of the maintainer takeover of [#19388](https://git.cafe/pingdotgg/t3code/pulls/19388). Main is merged into this branch; no history was rewritten.

## Verification

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.

## Evidence

> The earlier runtime and proof evidence above (captured at [1439b2b34e](https://git.cafe/pingdotgg/t3code/commit/1439b2b34e) and before) is **superseded** by this section. It predates [4cc74410d2](https://git.cafe/pingdotgg/t3code/commit/4cc74410d2) (ancestor refresh after wake replay).

Code under proof: [4cc74410d2](https://git.cafe/pingdotgg/t3code/commit/4cc74410d2). Before: merge-base [8d3b061121](https://git.cafe/pingdotgg/t3code/commit/8d3b061121). The driver is committed as [9b97de29a6](https://git.cafe/pingdotgg/t3code/commit/9b97de29a6) (`apps/server/src/orchestration-v2/testkit/OpenCode2PendingSnapshots.evidence.test.ts`, evidence only, no product code).

Mode: the real OrchestratorV2 (orchestrator, event sink, projections, effect worker; in-memory SQLite) replays **recorded** OpenCode 2 fixtures through the testkit fake. This is not a running `bin.ts` server and not live OpenCode: the local OpenCode is 1.18.18 with no credentials, and the v2 adapter needs 2.x. At this head the server drops the `pendingBackgroundWork` flag (`ProviderEventIngestor.ts:565`); its consumer is the stacked [#21461](https://git.cafe/pingdotgg/t3code/pulls/21461).

| row | stimulus | before (8d3b061121) | after (4cc74410d2) |
|---|---|---|---|
| R1 | `opencode2_nested_background`: root turn ends while a background grandchild's report is queued for the middle session | FAIL: no snapshot, and the middle session never lists the grandchild | PASS: `true` while the report is queued; the middle continuation runs; `false` only after the middle's turn 2 completes |
| R2 | held wake replayed after the session is called as a child (target of 4cc74410d2) | FAIL | PASS; with only the two `syncRosterAncestors` lines removed, it fails at `:1421` (the caller stays `true`) |
| R2b | nested report cancelled during a held wake | FAIL | PASS |
| R2c | `opencode2_resume_after_restart`, `opencode2_interrupt` (compatibility) | PASS | PASS |
| R3 | `opencode2_simple`, `opencode2_tool_call`: no pending work | PASS | PASS (unchanged) |

[Matrix](https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/4790029d14666224/matrix.md) · [Summary](https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/1f0387eeccc516d6/SUMMARY.md) · [Transcript before](https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/10cc417f28807641/transcript-before.txt) · [Transcript after](https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/4405876e5ff60be1/transcript-after.txt) · [Named tests: after](https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/31dcadcc91a0dd73/named-after.log) / [minus two lines](https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/af804e79da9d5dae/named-after-minus-2-lines.log) / [before](https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/4782b10fbdcf9e78/named-before-transplanted.log) · [Red diff](https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/22796f5dcb8bccad/red-minus-two-lines.diff) · [Audit](https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/844b616329b35f4a/audit2.md)

<details><summary>Verification log</summary>

- Environment: Linux VM fs-33, Node v24.21.0, OpenCode 1.18.18 (not used; recorded fixtures), driver run with `vp test run` from `apps/server`.
- What else changed between before and after: the adapter test file (`OpenCode2AdapterV2.test.ts`), one optional `pendingBackgroundWork` field in `provider-core/src/server/ProviderAdapter.ts`, and the evidence driver.
- Reviews of 4cc74410d2: Claude Sonnet 5.5: MERGE. Claude Opus 5.5: MERGE. Neither touches auth, permissions, modes, sandboxing, trust or MCP. Non-blocking notes: (1) the descendant loop follows insertion order, not depth, so a re-parented session can emit an ancestor update before a descendant's (values are still correct); (2) a previous caller is not refreshed when a session is called by a new caller. Both predate this commit.
- Proof audits: pass 1 derived the matrix; pass 2: SUFFICIENT, with an independent rebuild at 9b97de29a6 identical to the capture.
- Tests at 4cc74410d2: `OpenCode2AdapterV2.test.ts` 80/80; adapter + `OpenCodeReplayFixtures.integration.test.ts` 102/102 ([log](https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/de8da5bcc0cb506e/scoped-tests-after.log)); `packages/provider-opencode` 123/123. Driver lint and `apps/server` typecheck pass ([typecheck](https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/b1b2efe6ede1641f/typecheck-server-after.log), [lint](https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/3f5329899a6a54a8/lint-driver-after.log)).
- CI: green on 4cc74410d2; on 9b97de29a6 27/28 passed with `Build and Typecheck` still pending at the time of writing. Lands through its stack.
- Unverified: a live OpenCode 2 run (no 2.x or credentials on this machine); a running server observing the flag (dropped at this head; belongs to https://git.cafe/pingdotgg/t3code/pulls/21461); the `takeRunningWake` site (`adapter.ts:3287`) alone (only `runWake` has its own test; same one-line change); R2c reconcile and wake-discard updates (compatibility replays only).
- Models/harness: Claude Opus 5.5 (lead, capture, audits, review B) and Claude Sonnet 5.5 (review A), Claude Code through T3 Code.

</details>

