Skip to content

MiniMax sessions: totalTokens stays undefined when model does not return usage data #83177

@njuboy11

Description

@njuboy11

Describe the bug

When a model provider (e.g., MiniMax) does not return usage data in its API response, the session entry totalTokens stays undefined forever. This breaks the memory-flush path and causes redundant compaction loops.

Root Cause

The preflight compaction path in agent-runner-memory.ts already has a fallback (estimatePromptTokensFromSessionTranscript) for when freshPersistedTokens is unavailable. However, the memory-flush path in the same file does not have this fallback.

Proposed fix

Add the same estimatePromptTokensFromSessionTranscript fallback that the preflight compaction path already uses, into the memory-flush path.

See PR: to follow

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Normal backlog priority with limited blast radius.clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions