fix(core): publish compaction lifecycle state#16397
fix(core): publish compaction lifecycle state#16397neriousy wants to merge 2 commits intoanomalyco:devfrom
Conversation
Set and clear session compaction timestamps so the TUI can surface its compacting status and regressions stay covered.
There was a problem hiding this comment.
Pull request overview
This PR fixes a long-standing UX gap where running /compact in an OpenCode session never displayed a distinct "compacting" state in the TUI session list — instead only showing generic busy/working behavior. The fix adds a Session.setCompacting function to persist the compacting timestamp into the database and publishes a Session.Updated bus event, then hooks it into SessionCompaction.process so the state is set at the start of compaction and reliably cleared afterward (via async resource disposal), even on failure.
Changes:
- New
Session.setCompactingfunction that persists the compacting start time to the DB and publishes anUpdatedevent on the bus SessionCompaction.processnow sets the compacting state at entry and usesawait using deferto clear it on both success and failure paths- Tests added for the new
setCompactingAPI (lifecycle events) and for the compaction process state transitions (success and failure)
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
packages/opencode/src/session/index.ts |
Adds setCompacting function following the same setArchived/setTitle pattern, updating time_compacting in the DB and publishing a Session.Updated event |
packages/opencode/src/session/compaction.ts |
Calls setCompacting at the start of process() and uses await using defer to guarantee the state is cleared when the function exits (normally or via exception) |
packages/opencode/test/session/session.test.ts |
Adds a test verifying that setCompacting publishes correct bus events and that the state is cleared afterward |
packages/opencode/test/session/compaction.test.ts |
Adds tests verifying the compacting lifecycle state during process() on success and on error; adds afterEach(() => mock.restore()) and related imports |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Adjust the compaction processor test stub so package typecheck passes without changing runtime behavior.
Issue for this PR
Closes #16395
Type of change
What does this PR do?
The TUI has logic for a compacting session state, but the compaction flow never sets session.time.compacting.
As a result, running /compact only shows generic busy/working behavior and never a distinct compacting state.
This PR makes the 'compacting' status work.
Also added tests
If you paste a large clearly AI generated description here your PR may be IGNORED or CLOSED!
How did you verify your code works?
Screenshots / recordings
If this is a UI change, please include a screenshot or recording.
Checklist
If you do not follow this template your PR will be automatically rejected.