#1924·cc-connect

Compress turns (/compress, /compact) never emit the "turn complete" log line — result events look orphaned to log-based monitoring

Author: EnomineraCreated Sep 28, 2026Updated Sep 28, 2026

AI disclosure: This issue was drafted and filed by an AI agent (Claude Code) on behalf of the reporter, based on a real production incident. The investigation and proposed fix below were agent-produced and operator-reviewed.

Summary

/compress (alias /compact) runs through a dedicated event loop (cmdCompress → runCompress → processCompressEvents), which consumes the turn's final type=result event and returns without ever logging msg="turn complete" — that line is emitted only by processInteractiveEvents (sole occurrence of "turn complete" in core/engine.go). The compress flow contains no other completion log either: zero slog.Info/slog.Warn between runCompress and the end of processCompressEvents.

Why it matters

turn complete is the engine's own vocabulary for "a turn finished and was consumed". Log-based monitors that pair the adapter's claudeSession: event type=result line with a subsequent turn complete (the natural pairing for turn-finality tracking) will treat every finished compress turn as an orphaned result:

  • a healthy /compress completes (~1 min on a large session), type=result is logged, turn complete never comes
  • if the instance stays quiet afterwards (no other chats active), the "orphan result" age grows without bound
  • we hit exactly this in production today: a health monitor false-positived and restarted a healthy gateway ~26 min after a successful manual /compact (result delivered, context compacted, session lock released — everything verified healthy after the fact)

Auto-triggered compaction (runCompress(..., auto=true)) has the same shape.

Reproduction

  1. Start a session with some history, send /compact (or /compress)
  2. In the log, claudeSession: event ... type=result appears when the CLI finishes compacting (DEBUG level, agent/claudecode/session.go handleReadLoopLine)
  3. No msg="turn complete" is ever emitted for that turn
  4. Any result-pairing monitor now sees an orphan that never resolves

Suggested fix

Log a turn complete line from processCompressEvents on every exit path — a defer at the top of the function survives future edits:

go
defer func() {
    slog.Info("turn complete",
        "session", session.ID,
        "agent_session", session.GetAgentSessionID(),
        "compress", true,
        "auto", auto,
        "turn_duration", time.Since(started),
    )
}()

Properties that make this safe:

  • an "early" complete line is harmless to result-pairing monitors: it only clears results logged before it
  • the compress=true field gives monitors/metrics an explicit filter hook
  • one defer covers manual and auto compaction and every terminal path (result / error / EOF / idle-timeout / stop / shutdown)
  • log volume: one INFO line per compress

We have been running this in production since today, with tests pinning the result / error / idle-timeout exit paths (plus a mutation check that removing the defer fails all three), and verified the completion line lands ~0.6s after the result event on a real /compact.

Happy to send a PR if this approach sounds right.