Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): keep the authoritative subagent model when snapshots race task_started #7583

Mergedspiky02plateau(GitHub profile, opens in a new tab)merged 1 commit intomain fromrefs/pull/7583/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHub

The agents panel sometimes labels a spawned subagent with the session's model instead of the one it actually ran on, and which label you get is a coin flip: in one session two Explore children launched the same way showed different models, one right, one wrong.

The seed and the correction can both lose a race. task_started seeds the task's model from the launching Agent tool's parsed input, but that lookup goes through inFlightTools, which is keyed by content-block index shared across the parent and every concurrently streaming subagent, and the tool's input only exists once its streamed JSON has fully parsed. When either fails, the seed falls back to context.session.model. That would be fine because subagent assistant snapshots carry the authoritative API model, except the refinement path silently no-ops when the snapshot arrives before its task_started has registered the task. The wrong seed then sticks for the task's lifetime, since taskLinkageFor repeats agent.model on every later row and clients fold it last-write-wins.

The fix makes the refinement robust to ordering instead of best-effort: a snapshot whose parent_tool_use_id does not resolve yet is buffered in a small per-session map (capped at 64, oldest evicted, consumed and deleted when task_started registers that tool_use_id). A buffered authoritative model outranks the launch-input seed; later snapshots still refine the record in place. Seed order is otherwise unchanged, and the inFlightTools keying itself is untouched here, as that is a separate concern. Known remainder: effort and owningAgentId come from the same lookup and have no authoritative correction source in the stream, so they are not covered by this change.

Verification

In apps/server:

  • vp test run src/provider/Layers/ClaudeAdapter.test.ts: 71 passed (71). The new test "a subagent snapshot that beats task_started still wins over the seed" fails on the unmodified adapter with expected 'claude-opus-4-6' to equal 'claude-sonnet-5[1m]', i.e. exactly the bug's signature.
  • tsgo --noEmit: no errors.
  • vp lint on both files: one pre-existing warning elsewhere in the file, nothing new. vp fmt --check: clean.

Change made by Claude Opus via Claude Code.


Note

Low Risk Scoped to subagent model resolution in ClaudeAdapter stream ordering; no auth or data-path changes, with explicit test coverage for the race.

Overview Fixes wrong subagent model labels in the agents panel when a subagent’s assistant snapshot arrives before task_started registers the task. Previously that refinement was skipped, so task.started / task.progress could stick with the session model seed.

ClaudeAdapter now keeps a per-session pendingTaskModels map (cap 64, FIFO eviction) keyed by parent_tool_use_id. Early snapshots call rememberPendingTaskModel; when task_started runs, a buffered model outranks launch-input and session fallbacks, then the entry is removed. Snapshots after registration still update taskAgents in place.

Adds a regression test that emits snapshot → task_started → task_progress and asserts claude-sonnet-5[1m] on both task events.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 1f89f52c1d40d51d44ff7df7d62f179fc923e67c. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Fix subagent model priority when assistant snapshots arrive before task_started

  • Adds a pendingTaskModels map to ClaudeSessionContext that buffers the authoritative model from an assistant snapshot (keyed by parent_tool_use_id) when the owning agent is not yet registered.
  • When task_started is later processed, the buffered model is consumed from pendingTaskModels and used to seed the agent record, taking priority over launch input and session defaults.
  • Introduces a PENDING_TASK_MODEL_CAP=64 to bound the map size, evicting the oldest entry when exceeded.
  • Risk: the buffered model now outranks all other seed values for subagent tasks, which changes the resolution order compared to previous behavior.
Macroscope summarized 1f89f52.
    1. Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro Plus

      Run ID: f7bd05bb-6c93-40bb-8ff8-a4e932bfee85

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review

      Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

      ❤️ Share
      Comment `@coderabbitai help` to get the list of available commands.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    3. Approvability

      Verdict: Approved at 1f89f52

      Macroscope's review found this PR approvable — Straightforward bug fix for a race condition where subagent snapshots can arrive before task_started events. The fix adds bounded buffering to preserve model information, with a comprehensive test covering the scenario. Limited scope with clear intent and resolution.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).

Sign in to join this conversation.