Skip to content

🤖 Costs tab: follow-ups for open sub-agent spend #7862

Closed

Description

@ThomasK33

Follow-ups from #7861, which adds open sub-agent spend to the Costs tab. Each item below shows less than the real spend, never more.

  1. Live updates while a sub-agent streams. The parent's projection refreshes when a sub-agent's stream ends, not during it. A long sub-agent turn makes the parent total jump at the end. (Codex review on 🤖 fix: include open sub-agent spend in the Costs tab #7861.)
  2. Prompt cache section and footer token count. Both read only the parent's own ledger, so open sub-agents are left out, and the numbers jump when a sub-agent is deleted. The overview tokens already include open sub-agents.
  3. Headless spend of a sub-agent after its last stream. For example, a status title generated for a sub-agent does not refresh the ancestors' projection until the next trigger, such as activating the parent.
  4. Lost roll-up delta. The backend sends session-usage-delta only when the parent has a live session, and the store gets it only while it is subscribed to the parent's chat. The parent ledger then stays stale until the next activation.

Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: high

Activity

  1. ThomasK33 commented on Nov 1, 2026

    @ThomasK33
    MemberAuthor

    More follow-ups found by independent verifiers of #7861. All need corrupt or unusual persisted state, and none was seen in 6,715 real ledgers.

    1. Built-in model keys. A model key named toString, constructor, valueOf or hasOwnProperty makes addModelUsage read the inherited function as existing usage and throw. recordUsage on main has the same path. Fix: Object.hasOwn or a null-prototype accumulator.
    2. Unusable ledger, empty history, running stream. The projection shows nothing for that sub-agent until its stream settles. This is likely unreachable, because a sub-agent's prompt is in history before its stream starts (not verified).
    3. Unusable ledger while a stream is ending. The in-memory rebuild marks only orphaned in-flight files as counted. A stream whose final message is already in history but whose key is not yet settled could count once twice for a few milliseconds, until the next refresh (not reproduced).
  2. ThomasK33 commented on Nov 1, 2026

    @ThomasK33
    MemberAuthor

    One more follow-up, found by the corrupt-shape sweep for #7866 (items 5 to 7):

    1. A workspace's own ledger in a wrong shape. getSessionUsage and recordUsage read session-usage.json with JSON.parse and a cast. Valid JSON in a wrong shape (for example byModel: null, byModel: "x", a null model entry, settledInFlightKeys: {}, rolledUpFrom: null, version: 2) makes them throw, or return a value that fails the getSessionUsage IPC output schema. The Costs tab then shows nothing for that workspace, and every later recordUsage of it throws, so its spend is never recorded. A parse error rebuilds from history, but a shape error does not. Fix: parse the locked read with the same self-healing parser as the lock-free reads (parseLedgerKeepingValidModels), and treat an unusable ledger like a corrupt one (rebuild from history). This existed before 🤖 fix: include open sub-agent spend in the Costs tab #7861.

    Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: high

  3. ThomasK33 commented on Nov 1, 2026

    @ThomasK33
    MemberAuthor

    One more follow-up, deferred from #7868 (Codex review, round 5). It needs an unusable ledger, so it is rare:

    1. A locked read repairs the ledger between a stream's history commit and its settle, and the stream has no in-flight key. The stream has no key only when every one of its in-flight writes failed. Then getSessionUsage (or a token-stats cache update) can rebuild an unusable ledger from history, which already holds the final message, and the later settle adds that message again. 🤖 fix: show and record spend when a workspace's own usage ledger has a wrong shape #7868 covers this window when recordUsage does the repair itself (its messageId option) and when the stream has an in-flight key (settledInFlightKeys). A fix for this case must persist which messages the repair counted, so it needs a new ledger field.

    Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: high

  4. ThomasK33 commented on Nov 1, 2026

    @ThomasK33
    MemberAuthor

    Follow-up from #7867 (deferred, not fixed there):

    • When a usage-changed refetch fails (a transient getSessionUsage or ancestor getSubagentUsage error), the store logs it and does not retry. The Costs tab stays stale until the next usage change of that workspace or a descendant, an activation, a Costs tab open, or an activity resubscribe. A fix would retry a failed usage-change refetch (bounded backoff), or keep a per-workspace "refresh pending" flag until a fetch succeeds. Source: Codex review thread on 🤖 fix: refresh the parent's Costs tab when a sub-agent's usage changes #7867, src/browser/stores/WorkspaceStore.ts refreshUsageAfterChange.
    • refreshSessionUsage is latest-wins, not single flight: a burst of usage writes on one shown workspace whose chat is not subscribed (for example headless records) costs one getSessionUsage each. Trigger: a profile that shows getSessionUsage bursts.

    Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: xhigh • Cost: $51.03

  5. ThomasK33 commented on Nov 2, 2026

    @ThomasK33
    MemberAuthor

    All eight items are fixed on main:

    Items PR Merge commit
    2 #7865 a16a0cd
    5, 6, 7 #7866 9e9e77c
    1, 3, 4 #7867 96a0916
    8 #7868 9caba3e

    Item 9 and the two follow-ups deferred from #7867 moved to #7886. Other follow-ups found during this work: #7870, #7883, #7884. Closing.


    Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: high

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions