t3code icon indicating copy to clipboard operation
t3code copied to clipboard

[Bug]: Delegated OpenCode task reports its first assistant message as the summary

Open hinescreative opened this issue 1 month ago • 1 comments

Area

apps/server (packages/provider-core/src/server/subagentProjection.ts)

Steps to reproduce

  1. Delegate a multi-step task to an OpenCode child (delegate_task with providerInstanceId: "opencode", e.g. model kimi-pipe/k3), and let it write several assistant messages over a few minutes before it finishes.
  2. When it completes, read the result with task_status (or the completion notification).

Expected behavior

summary / latestTerminalSummary is the child's final assistant message (its report).

Actual behavior

summary is the child's first assistant message. In my run it was "Starting step 0: read docs and list test-runs.", while the run's last message was the full report ("MISSION COMPLETE — all steps PASS. …"). The task looked like it had stalled at step 0 even though it had finished.

Cause, as far as I can tell:

  • subagentResultForRun picks the assistant message with the greatest updatedAt and has no tiebreaker (subagentProjection.ts:177-180 on 98a6246d). toSorted is stable, so on a tie the earliest message in projection.messages wins.
  • OpenCode child runs give every assistant message the same updatedAt, the moment the turn ends. From orchestration_v2_projection_messages for that thread:
created 2026-10-13T12:27:19.553Z  updated 2026-10-13T12:31:40.610Z  | Starting step 0: read docs and list test-runs.
created 2026-10-13T12:27:56.592Z  updated 2026-10-13T12:31:40.610Z  | Grep complete. Now verify which cited paths exist:
...  (9 messages, all updated 12:31:40.610Z)
created 2026-10-13T12:31:40.505Z  updated 2026-10-13T12:31:40.610Z  | **MISSION COMPLETE — all steps PASS.** ...

A Codex child in the same session doesn't hit this. Each message's updatedAt is within milliseconds of its own createdAt, so the newest one wins correctly. Grok children also reported correctly.

Impact

Major degradation or frequent failure. A parent agent reading summary sees an interim message from a finished OpenCode child and can wrongly conclude the work wasn't done, or re-run it.

Version or commit

T3 Code (Nightly) desktop 0.0.46; code still present on main @ 98a6246d

Environment

Windows 11, T3 Code (Nightly) desktop app, OpenCode 1.19.0, parent thread on Claude Code (claude-opus-5-5), child on OpenCode kimi-pipe/k3.

Workaround

Read the child thread's last assistant_message turn item (e.g. t3_thread_read) instead of trusting summary.

Related, but a different trigger: #16739 (a cancelled background task reports an interim summary).


Investigated with Claude Code (claude-opus-5-5) running inside T3 Code.

hinescreative avatar Oct 13 '26 14:10 hinescreative

[!NOTE] Grok responding on behalf of Julius.

Confirmed on main. This is a bug in the projection, not the provider.

subagentResultForRun (packages/provider-core/src/server/subagentProjection.ts) sorts the run's assistant messages only by updatedAt, and text prefers that message over the turn item. When every message has the same updatedAt, the stable sort returns the first message. The turn-item lookup a few lines down already sorts by ordinal, which is the right ordering. So summary / latestTerminalSummary can name an interim message even though the run finished.

The OpenCode adapter giving every message the turn-end timestamp explains why only OpenCode children hit this. Codex and Grok stamp each message as it lands. We still shouldn't rely on timestamps to find the last message, so the fix belongs here: take the message for the newest assistant_message turn item by ordinal, or break ties on createdAt and then by array position.

Workaround: read the child thread's last assistant_message turn item (for example with t3_thread_read) instead of summary.

Related: #16739 has the same symptom from a different trigger (a cancelled task). Neither #18649 nor #15201 touches this sort.

juliusmarminge avatar Oct 13 '26 14:10 juliusmarminge