Repository navigation
Commit 4a281f2
feat(cli): report retained tool-result stats in /doctor memory (QwenLM#8875)
* feat(cli): report retained tool-result stats in /doctor memory
Add a tool-result retention section to /doctor memory (and --json) covering
the phase-1 diagnostics from QwenLM#4184: retained tool-result count/total/largest,
oversized flagging against the 30k widest legal per-tool budget, plus
duplication signals for UI history and compression input. Sizes and counts
only (never content); history is scanned by reference so the diagnostic adds
no memory pressure.
* docs(design): document tool-output offload/preview state transitions and privacy model
Satisfies acceptance criterion 2 of QwenLM#4184: state transitions of the layered
truncation/offload mitigation (implemented in QwenLM#4880) and its privacy model,
plus the tmux E2E report for the /doctor memory retention diagnostics.
* fix(cli): align retention diagnostics with per-tool budgets and raw-char sizes
Address review round 1: measure retained tool results with the compression
pipeline's estimatePartChars (raw chars for string outputs, image estimate
for nested media) instead of JSON.stringify, fixing false oversized flags on
newline-dense compliant outputs; compare each result against its own tool's
declared budget resolved from the tool registry instead of a fixed 30k
threshold, so compliant high-budget results (e.g. MCP) are never flagged;
scope the UI-history duplication scan to tool_group result displays so model
text is excluded and rendered tool outputs are actually detected; omit
toolResultRetention from --json when unavailable; log retention collection
failures via debug logger; fix the design note's IO-error persistence bullet;
re-verify the E2E report with the new measurement basis.
* fix(cli): calibrate oversized detection against truncation layers
- Canonicalize tool names before registry lookup (legacy aliases resolve)
- Skip sentinel-prefixed results and apply combined-pass 2x tolerance
- Fall back to configured global threshold for tools declaring no budget
- Compare UI history displays against per-tool budgets
- Document persistence gate in design note; re-verify e2e scenario 3
* fix(core): share tolerance constant and align imageTokenEstimate with compression pipeline
Review (round 4) fixes:
- R4-3: Extract COMBINED_PASS_TOLERANCE_FACTOR into truncation.ts and
share it between the scheduler's combined pass and the retention
diagnostics so both use the same tolerance factor.
- R4-4: Add imageTokenEstimate option to analyzeToolResultRetention
(defaults to DEFAULT_IMAGE_TOKEN_ESTIMATE); doctorCommand now resolves
it via resolveSlimmingConfig (env > settings > default), the same
source the compression pipeline uses. Export resolveSlimmingConfig from
the core barrel.
- R4-5/R4-6: Add tests for configurable imageTokenEstimate and Infinity
threshold guard.
- R4-7: Guard oversizedThresholdChars against Infinity — when truncation
is disabled (threshold <= 0 → Infinity), report 0 instead of Infinity
so JSON.stringify does not drop the key to null.
- R3-3: Fix UI history budget resolution — IndividualToolCallDisplay.name
stores the tool's displayName (e.g. 'Shell'), not the registry key (e.g.
'shell'), so getTool(displayName) returned undefined and budgets fell
back to the global threshold. Build a displayName → maxOutputChars map
from getAllTools() at scan time.
- R4-12: Declare string-only scope for UI history scanning in code
comment and design doc §5 — structured display objects (file diffs,
ANSI captures, agent result summaries) are out of scope for phase 1.
- 3750020138: Update design doc §5 to reflect resolveSlimmingConfig
alignment and display-name map.
* fix(doctor): align UI scan to 2x tolerance, fix threshold/error/sentinel gaps
R5-1: threshold uses config.getTruncateToolOutputThreshold() first so
disabled (Infinity) doesn't fall to 0
R5-3: UI scan uses budget * COMBINED_PASS_TOLERANCE_FACTOR to match
API-history 2x tolerance
R5-7: oversized check uses rawChars (output.length) instead of
estimatePartChars (which adds 64 wrapper floor)
R5-8: read output ?? error and check <persisted-output> sentinel
R5-12: UI lookup consults ToolDisplayNamesMigration for legacy names
Tests: 3 core + 1 CLI updated for rawChars/2x; 3 core + 2 CLI added
Doc: test counts (core 14→19, CLI 9→11), scenario 4 JSON, 2x wording
* docs: fix design note accuracy (R5-9/R5-15/R5-10)
R5-9: clarify shell/MCP truncate in-tool before gate; split recovery paths
R5-15: note sentinel skip in combined-pass re-check; fix mermaid routing
R5-10: describe two-stage persist failure (fallback saves full payload)
* fix(doctor): add envelope slack for token-aware truncation fallback
R6 review: truncateAndSaveToFile's token-aware fallback returns the
original content (sentinel-less) when the wrapped form would not be
smaller, so the diagnostic's oversized check must tolerate that band.
- Export TRUNCATION_FALLBACK_ENVELOPE_SLACK=500 from truncation.ts
- Apply slack to the rawChars > 2x budget comparison
- Adjust 4 test fixtures broken by the new threshold boundary
- Fix 7 factual errors in design/E2E docs (mermaid, project-hash,
web-search 102k, re-entrancy guard, shell/MCP bullet)
- Add JSDoc caveat for MCP-disconnect limitation (R6-16)
* docs: align §5 sentinel description with diagnostic code
Bot R6-10 re-report: design doc §5 claimed three markers are skipped
(prefix, in-body marker, <persisted-output> stub), but the diagnostic
only checks two (prefix and <persisted-output> stub). Aligned the doc
to match the code. The re-entrancy guard bullet still describes the
scheduler's three-marker isAlreadyTruncated check, which is accurate.
---------
Co-authored-by: 俊良 <[email protected]>
Co-authored-by: Shaojin Wen <[email protected]>1 parent 055b021 commit 4a281f2
9 files changed
Lines changed: 1280 additions & 4 deletions
File tree
- .qwen/e2e-tests
- docs/design
- packages
- cli/src/ui/commands
- core/src
- core
- utils
Lines changed: 139 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
0 commit comments