feat(kap-server): move compacting from session.state to agent.state turn - #3712
Conversation
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c6cf9e45c0
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if (this.status !== 'running') return false; | ||
| this.status = 'idle'; | ||
| this.turn = undefined; | ||
| this.compacting = false; |
There was a problem hiding this comment.
Preserve compaction state across turn boundaries
When background auto-compaction outlives the turn that started it—a supported scenario in fullCompaction.test.ts—this reset discards the active compaction before any compaction.completed or compaction.cancelled event. If another turn begins while that task is still running, recompute() consequently reports thinking or acting instead of compacting; clear only the turn display here and retain the lifecycle flag until its matching end event.
Useful? React with 👍 / 👎.
| private endedAt: string | undefined; | ||
| private status: AgentStatus = 'idle'; | ||
| private turn: AgentStateTurn | undefined; | ||
| private compacting = false; |
There was a problem hiding this comment.
Seed compacting when attaching to a live agent
ProjectionService.forSessionLive() creates projections lazily, so the first v3 subscriber can attach after compaction.started has already fired. Because this tracker always initializes the flag to false and only subsequent bus events update it, recovery and live state never expose compacting for that in-flight operation; the eventual completion merely recomputes an ordinary phase. Seed the flag, along with the current turn snapshot, from the live agent services when tracking an existing agent.
Useful? React with 👍 / 👎.
Related Issue
Follow-up to #3532 (flat entity message protocol). Internal protocol adjustment, no linked issue.
Problem
The v3 protocol carried a
compactingvalue onsession.state.statusthat the projection never produced (session state is derived purely from busy →idle | running). Meanwhile, full compaction is an agent-level activity that happens inside a running turn, and subscribers had no way to observe it in real time —compaction.started/compaction.completedbus events existed but were not surfaced on any state entity.What changed
session.state.statusnarrowed to'idle' | 'running': the never-produced'compacting'value is removed from the schema. No runtime behavior change — the projection only ever emitted the two remaining values, so this is backward compatible for consumers.agent.state.turn.statusgains'compacting'(now'thinking' | 'retrying' | 'acting' | 'aborting' | 'compacting'), an additive enum extension per the open-union evolution rule.AgentStateTrackerholds a compacting flag driven by the per-agentcompaction.started/compaction.completed/compaction.cancelledbus events (observable, already in the projection event union). While compacting, the flag takes precedence over the activity-snapshot phase mapping; when compaction ends the turn status recomputes back to the real phase.compaction.blockednever enters the compacting state. Compaction outside an active turn is not represented (theturnfield only exists while running).actingafterwards (test count unchanged).Checklist
/approve).gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.