Skip to content

Add structured /doctor memory output and safe session-scale stats #4182

@qqqys

Description

@qqqys

Parent

Part of #3000 and follows #4179.

Goal

Add structured /doctor memory output and session-scale counters so memory reports can distinguish V8 pressure from large conversation/tool-result retention.

Motivation

A single process/V8 snapshot is useful, but Qwen Code OOMs are often caused or amplified by agent-specific state: long chat history, large tool results, UI history, or compression-time duplication. /doctor memory should expose safe aggregate counters before asking users for heavier heap snapshots.

Proposed solution

  • Add a structured output path for /doctor memory, e.g. /doctor memory --json in non-interactive and interactive command paths.
  • Extend diagnostics with safe aggregate session stats when available:
    • conversation/history item count
    • approximate total chars/tokens if an estimator is available
    • largest tool result size and total tool result size, without content
    • UI history item count, if accessible
    • current model/context window metadata when safe
  • Gracefully report unavailable when the command context does not expose a counter.
  • Keep all stats content-free: counts and sizes only.

Non-goals

  • Do not serialize full conversation messages.
  • Do not include tool result contents.
  • Do not implement tool-result offload in this issue.
  • Do not add heap snapshot generation here.

Acceptance criteria

  • /doctor memory --json returns valid JSON in non-interactive mode.
  • Human-readable output includes a Session scale or equivalent section when stats are available.
  • Tests verify that session stats are aggregate-only and do not include message/tool content.
  • The command still works in contexts without session/UI stats.

Metadata

Metadata

Assignees

Labels

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