← Back to Kontasks
Compaction Duration Fix Explained
Found and fixed edge case where compaction duration wasn't captured
Output
Compaction Data Analysis
What You're Seeing
| 2 COMPACTION TURNS | We detected hadCompaction: true in 2 records |
| — DURATION | All 4 records have compactionDurationMs: null |
| 10% OF RECENT | Correct: 2 compactions out of ~20 recent turns |
Root Cause Found
The auto_compact_end event (with duration) is only sent when a non-system event arrives after compaction.
Edge case: If Claude compacts and then immediately exits (no more tool calls), there's no non-system event to trigger auto_compact_end!
Fix Applied
Added check in konsole/src/stream.ts before sending kontext:
// If we were still compacting when stream ended, send the end event now if (compactionStartedAt > 0) { const durationMs = Date.now() - compactionStartedAt; sendEvent(controller, encoder, { type: "auto_compact_end", durationMs }); }
Next Steps
Restart konsole to pick up the fix. Future compactions will record duration.
Quick Actions
Original Request
No layout configured
Details
Type
General
Status
Completed
Scope
vibetools
Tags
telemetrycompactionbugfix
Created
4 Jan 2026, 10:51 am
Updated
4 Jan 2026, 10:51 am
Created By
claude
Raw Data
{
"id": "6b037afe-47f8-48ed-8686-db97bc7c127c",
"type": "general",
"status": "completed",
"title": "Compaction Duration Fix Explained",
"description": "Found and fixed edge case where compaction duration wasn't captured",
"context": {
"output": "<div style=\"background:#1e1e1e;color:#e0e0e0;padding:20px;border-radius:8px;font-family:system-ui,sans-serif;\"><h2 style=\"color:#fff;margin:0 0 16px 0;\">Compaction Data Analysis</h2><div style=\"background:#2d2d2d;padding:16px;border-radius:6px;margin-bottom:16px;\"><h3 style=\"color:#61afef;margin:0 0 12px 0;\">What You're Seeing</h3><table style=\"width:100%;border-collapse:collapse;\"><tr style=\"border-bottom:1px solid #444;\"><td style=\"padding:8px 0;color:#e5c07b;width:40%;\">2 COMPACTION TURNS</td><td style=\"padding:8px 0;\">We detected <code>hadCompaction: true</code> in 2 records</td></tr><tr style=\"border-bottom:1px solid #444;\"><td style=\"padding:8px 0;color:#e5c07b;\">— DURATION</td><td style=\"padding:8px 0;\">All 4 records have <code>compactionDurationMs: null</code></td></tr><tr><td style=\"padding:8px 0;color:#e5c07b;\">10% OF RECENT</td><td style=\"padding:8px 0;\">Correct: 2 compactions out of ~20 recent turns</td></tr></table></div><div style=\"background:#2d2d2d;padding:16px;border-radius:6px;margin-bottom:16px;\"><h3 style=\"color:#c678dd;margin:0 0 12px 0;\">Root Cause Found</h3><p style=\"margin:0 0 12px 0;\">The <code>auto_compact_end</code> event (with duration) is only sent when a <strong>non-system event</strong> arrives after compaction.</p><p style=\"margin:0;color:#f87171;\"><strong>Edge case:</strong> If Claude compacts and then immediately exits (no more tool calls), there's no non-system event to trigger <code>auto_compact_end</code>!</p></div><div style=\"background:#2d2d2d;padding:16px;border-radius:6px;margin-bottom:16px;\"><h3 style=\"color:#98c379;margin:0 0 12px 0;\">Fix Applied</h3><p style=\"margin:0 0 8px 0;\">Added check in <code>konsole/src/stream.ts</code> before sending kontext:</p><pre style=\"background:#1e1e1e;padding:12px;border-radius:4px;margin:8px 0 0 0;font-size:0.85rem;overflow-x:auto;\"><span style=\"color:#7f848e;\">// If we were still compacting when stream ended, send the end event now</span>\n<span style=\"color:#c678dd;\">if</span> (compactionStartedAt > <span style=\"color:#d19a66;\">0</span>) {\n <span style=\"color:#c678dd;\">const</span> durationMs = Date.<span style=\"color:#61afef;\">now</span>() - compactionStartedAt;\n <span style=\"color:#61afef;\">sendEvent</span>(controller, encoder, { type: <span style=\"color:#98c379;\">\"auto_compact_end\"</span>, durationMs });\n}</pre></div><div style=\"background:#2d2d2d;padding:16px;border-radius:6px;\"><h4 style=\"margin:0 0 8px 0;color:#fff;\">Next Steps</h4><p style=\"color:#9ca3af;margin:0;\">Restart konsole to pick up the fix. Future compactions will record duration.</p></div></div>",
"requestId": "82adcdba-b69e-4544-aa49-0b50892ccfd2",
"choices": [
{
"label": "Restart konsole",
"value": "Restart konsole service to pick up the compaction duration fix",
"primary": true
},
{
"label": "Commit fix",
"value": "Commit and push the compaction duration fix"
},
{
"label": "View code",
"value": "Show the full context of the fix in stream.ts"
}
]
},
"createdBy": "claude",
"createdAt": "2026-01-04T00:51:25.617Z",
"updatedAt": "2026-01-04T00:51:25.786Z",
"requestId": "82adcdba-b69e-4544-aa49-0b50892ccfd2",
"scope": "vibetools",
"tags": [
"telemetry",
"compaction",
"bugfix"
],
"targetUser": "claude"
}