Skip to content

fix(context): run the manual compaction in the background - #305

Merged
grinev merged 1 commit into
grinev:mainfrom
atn18:fix/compact-background
Nov 21, 2026
Merged

grinev merged 1 commit into
grinev:mainfrom
atn18:fix/compact-background

Conversation

@atn18

@atn18 atn18 commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Description of changes

  • The manual context compaction (Context menu -> Compact -> confirm) awaited opencodeClient.session.summarize(...) inside the grammY callback handler. grammY processes updates sequentially, so the whole update loop stayed blocked while the compaction ran (minutes on a large context): every command, /detach included, waited behind it, and queued messages older than 60 seconds were then dropped as stale with the "Telegram was unreachable" notice.
  • The compaction now runs in the background (safeBackgroundTask, like the start-only prompt path), and the progress message is updated from its hooks: context.success when it completes, context.error when it returns an error or throws. The handler answers the callback, cleans up the menu, sends the progress message and returns immediately, so commands keep working while the compaction runs.

Closes issue (optional)

  • None

How it was tested

  • npm run lint, npm run build, npm run typecheck, npm test - all green (3557 passed, 7 skipped).
  • New tests: the handler resolves while the summarize promise is still pending (the compaction does not block), and the progress message ends with context.success after it resolves; a second confirmation while a compaction is in flight is rejected with the existing "compacting" toast and starts no second summarize; a failed compaction (error object and thrown rejection) reports through context.error without failing the handler and releases the guard. The existing success case now waits for the asynchronous edit.

Checklist

  • PR title follows Conventional Commits: <type>(<scope>)?: <description>
  • This PR contains one logically complete change
  • Branch is rebased on the latest main
  • I ran npm run lint, npm run build, and npm test
  • If this PR is OS-sensitive, behavior/limitations for Linux/macOS/Windows are described

The Compact confirmation awaited session.summarize inside the callback
handler, so the sequential update loop was blocked for the whole
compaction (minutes on a large context): commands, /detach included,
waited behind it and were then dropped as stale. Start the compaction in
the background and report its result through the progress message.
@atn18
atn18 force-pushed the fix/compact-background branch from 9f8eccf to 9384940 Compare November 20, 2026 17:42
@atn18
atn18 marked this pull request as ready for review November 20, 2026 19:18
@grinev
grinev merged commit e624170 into grinev:main Nov 21, 2026
3 checks passed
@atn18
atn18 deleted the fix/compact-background branch November 21, 2026 10:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants