Skip to content

fix(cloud-agent-sdk): hold the context reading across a compaction - #6272

Merged
iscekic merged 1 commit into
mainfrom
kwf/in-a-remote-cli-session-the-context-window-163a
Sep 17, 2026
Merged

iscekic merged 1 commit into
mainfrom
kwf/in-a-remote-cli-session-the-context-window-163a

Conversation

@iscekic

@iscekic iscekic commented Sep 17, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog for users

  • After /compact, the context indicator no longer reverts to the pre-compaction percentage.
  • Between the compaction and the next turn, the indicator shows no percentage instead of the stale one.
  • The next turn on the compacted context sets the indicator to the compacted reading; later rises come only from new turns.
  • The compacted reading survives leaving the session and reopening it.
  • Messages the remote CLI removes no longer linger in the local transcript.

Changelog for maintainers

  • packages/cloud-agent-sdk/src/context-usage.ts: findLatestContextUsage walks messages newest-first and stops at a compaction boundary, reporting no reading past it instead of an older message's figure.
  • A boundary is a finished, error-free summary: true assistant message, or any message carrying a compaction part — the marker the mobile transcript renders as "Context compacted". A summary still running or failed is not a boundary.
  • The compaction summary's own token buckets belong to the compaction request, so the summary is never used as a reading; right after /compact the honest state is no figure until the next turn reports.
  • findLatestContextUsage now takes { info, parts? }; stored session messages already carry their parts, so no session-manager wiring changed for the boundary.
  • New message.removed chat event (messageRemovedDataSchema) normalizes to { sessionId, messageId }, joins CHAT_EVENT_TYPES, and resolves to its session through chatEventSessionId.
  • reduce maps message.removed to delete_message, and the chat processor deletes the message with its parts from session storage.
  • Review hint: the blank indicator between /compact and the next turn is intended; do not fill it from the summary's tokens. Start at the boundary checks in context-usage.ts.
  • Tests cover the compaction boundary (running, failed, repeated), event normalization, the reducer mutation, storage deletion, and the manager's usage atom.

E2E proof

[e1] Prove PR 6272 on android: the context indicator holds the compaction — pre-compaction figure, then no stale figure after /compact, then the compacted reading after one turn, and it survives leaving… — android emulator-5554, remote CLI session ses_f500fabc4ffe1uUhtoSTIKdXHQ (session.sh remote-enter + enter; 'link delivered on emulator-5554' in e1-reenter.log). Before /compact the header button read 'Context 17,820 of 1,310,720 tokens, 1% used' (e1-enter-digest.log); /compact was sent from the app's slash menu ('Use /compact' -> composer EditText '/compact' in e1-compact-send.log, pre-figure still present there), and immediately after sending, the indicator lost its figure and read 'cost 1 cent Tap to view context details.' with 'CONTEXT COMPACTED' in the transcript (e1-compact-sent.log)…

[e1] Prove PR 6272 on android: the context indicator holds the compaction — pre-compaction figure, then no stale figure after /compact, then the compacted reading after one turn, and it survives leaving… — e2e-mobile-app/e1-compact-go.png

[e1] Prove PR 6272 on android: the context indicator holds the compaction — pre-compaction figure, then no stale figure after /compact, then the compacted reading after one turn, and it survives leaving…

[e1] Prove PR 6272 on android: the context indicator holds the compaction — pre-compaction figure, then no stale figure after /compact, then the compacted reading after one turn, and it survives leaving… — e2e-mobile-app/e1-reopen.png

[e1] Prove PR 6272 on android: the context indicator holds the compaction — pre- -> pass :: android emulator-5554, remote CLI session ses_f500fabc4ffe1uUhtoSTIKdXHQ (session.sh remote-enter + enter; 'link delivered on emulator-5554' in e1-reenter.log). Before /compact the header button read 'Context 17,820 of 1,310,720 tokens, 1% used' (e1-enter-digest.log); /compact was sent from the app's slash menu ('Use /compact' -> composer EditText '/compact' in e1-compact-send.log, pre-figure still present there), and immediately after sending, the indicator lost its figure and read 'cost 1 cent Tap to view context details.' with 'CONTEXT COMPACTED' in the transcript (e1-compact-sent.log), and after the compaction summary landed it was still figureless, i.e. the pre-compaction figure did not
## Open findings (not fixed here) - [e1] Remote CLI session on device: drive context above ~90%, run /compact, and confirm the indicator shows the compacted percentage and does not return to the pre-compaction figure once the compaction summary lands. - [e1] Remote CLI session on device: drive context above ~90%, run /compact, confirm the indicator shows the compacted percentage and never returns to the pre-compaction figure: android emulator-5554: pre-compaction the indicator read 'Context 184,015 of 200,000 tokens, 92% used' (e1-precompact90.log) - not fully verified: some optional checks did not run

e1-post

e1-postturn

e1-pre

p1

e1-compact-go

e1-reopen

@iscekic
iscekic marked this pull request as draft September 17, 2026 13:02
Comment thread packages/cloud-agent-sdk/src/context-usage.ts Outdated
Comment thread packages/cloud-agent-sdk/src/context-usage.ts Outdated
@kilo-code-bot

kilo-code-bot Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Executive Summary

The incremental fix resolves both prior findings and introduces no new issues in the changed lines of the compaction-boundary walk.

Resolved Findings

  • packages/cloud-agent-sdk/src/context-usage.ts — hasError now treats error: null like undefined, so a finished compaction summary registers as a boundary.
  • packages/cloud-agent-sdk/src/context-usage.ts — a failed compaction summary marks its request's compaction part as non-terminal, so the still-valid pre-compaction reading is returned instead of blanking the indicator.
Files Reviewed (2 files)
  • packages/cloud-agent-sdk/src/context-usage.ts
  • packages/cloud-agent-sdk/src/context-usage.test.ts
Previous Review Summary (commit ec60cde)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit ec60cde)

Status: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 2
SUGGESTION 0
Issue Details (click to expand)

CRITICAL

None.

WARNING

File Line Issue
packages/cloud-agent-sdk/src/context-usage.ts 23 info['error'] === undefined misses error: null, so a completed compaction summary can be skipped and the pre-compaction reading can return
packages/cloud-agent-sdk/src/context-usage.ts 104 Unconditional compaction-part boundary blanks the indicator after a failed compaction instead of keeping the still-valid pre-compaction reading
Files Reviewed (11 files)
  • packages/cloud-agent-sdk/src/chat-processor.test.ts
  • packages/cloud-agent-sdk/src/chat-processor.ts - 0 issues
  • packages/cloud-agent-sdk/src/context-usage.test.ts
  • packages/cloud-agent-sdk/src/context-usage.ts - 2 issues
  • packages/cloud-agent-sdk/src/normalizer.test.ts
  • packages/cloud-agent-sdk/src/normalizer.ts - 0 issues
  • packages/cloud-agent-sdk/src/reducer.test.ts
  • packages/cloud-agent-sdk/src/reducer.ts - 0 issues
  • packages/cloud-agent-sdk/src/schemas.ts - 0 issues
  • packages/cloud-agent-sdk/src/session-manager.test.ts
  • packages/cloud-agent-sdk/src/session-manager.ts - 0 issues

Fix these issues in Kilo Cloud


Reviewed by deepseek-v4.1-flash · Input: 0 · Output: 0 · Cached: 0

Review guidance: REVIEW.md from base branch main

@iscekic
iscekic force-pushed the kwf/in-a-remote-cli-session-the-context-window-163a branch from 07dc11b to edd712c Compare September 17, 2026 13:57
@iscekic
iscekic marked this pull request as ready for review September 17, 2026 14:06
@iscekic iscekic added the human-ready The PR is ready for human review. label Sep 17, 2026
@iscekic iscekic self-assigned this Sep 17, 2026
@iscekic
iscekic enabled auto-merge (squash) September 17, 2026 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

human-ready The PR is ready for human review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants