Repository navigation
serve: a manual compact no longer blocks the session loop - #270
Merged
Merged
Conversation
`do_compact!` selected only the checkpoint channel and the compaction, so `abort`, `get_state` and SIGTERM all waited for the summary call (up to the 600 s stream idle timeout). It now runs inside a select shaped like the host-bash loop: `abort` cancels the compaction (acked after the `compact` response), shutdown and EOF cancel it and end the session, `get_state` (`is_compacting: true`), `get_session_stats` and `get_messages` are answered from a pre-compaction snapshot, MCP Events injections are deferred, and anything else is refused as busy. The macro moved below the shutdown/deferred-events declarations it now uses, and evaluates to whether the session goes on. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JimHGjsfk2Ktm5GxyZJKKk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes serve audit defect #4 (HANG).
do_compact!selected only on the checkpoint channel and the compaction future.compaction_cancelwas never cancelled, andinput_rxandshutdownwere never polled. Soabort,get_stateand SIGTERM all waited for the summary call, which can take up to the 600 s stream idle timeout. In the audit's repro,get_stateandabortsent 700 ms in were answered only after the compact response, SIGTERM was honoured 7 s later, andget_statereportedis_compacting:falsethroughout. A deferredcompact(one that runs after the prompt it arrived during) behaved the same way.Change. The compaction now runs inside a select shaped like the host-bash loop:
abortcancelscompaction_cancel. The compaction ends unapplied and nothing on disk changes. Theabortack is sent after thecompactresponse, the way a mid-run abort is acknowledged.get_state(is_compacting: true,message_countas it stands until the compaction lands),get_session_statsandget_messagesare answered from a snapshot taken before the compaction starts.mcp_events_*commands are dispatched, and every other command is refused as busy.The macro moved below the
shutdown/deferred_events/dispatch_eventsdeclarations it now uses. It keeps #265'sBusyGuard: now that EOF cancels a compaction, the guard is what stops a reap or drain from cutting one short. Docs are updated in serve.rs's module doc andARCHITECTURE.md(theis_compactingpassage and the MCP Events deferral note).Tests.
crates/agent/tests/serve_compact_cancellable.rs(new). The summary call stalls 20 s:abort_cancels_a_manual_compact_and_reads_are_answered_meanwhile:get_stateis answered beforecompactwithis_compacting:true.set_session_namegets a busy refusal.abortcancels the compaction in well under 5 s, and the transcript on disk is unchanged.sigterm_ends_a_manual_compact_promptly: the process exits within 3 s of SIGTERM.Both tests fail on the old code. #265's
reaper_spares_a_detached_compactstill passes. The agent and agent-core suites, clippy-D warnings, fmt and dprint all pass.Side note, not changed here: the busy prompt loop's
get_messagesarm readssincefrom the prompt'scmdinstead of the incomingc.🤖 Generated with Claude Code
https://claude.ai/code/session_01JimHGjsfk2Ktm5GxyZJKKk