Skip to content

Harden bot-surface compaction (SDK auto-compact) + let all channels lean on it #296

Description

@JDHayesBC

Context

The Haven + SL bots run the Claude Agent SDK, which auto-compacts (emits compact_boundary, fires PreCompact, re-injects CLAUDE.md, no off-switch). Today the invoker sidesteps this with a manual 150k-token restart. Goal: stop fighting compaction — harden it, and let every bot surface (Haven, SL, future) lean on it the way terminal-Lyra already does.

Design note: work/sl-presence/context-handling.md.

Findings (measured 2026-08-22)

  • Agent SDK auto-compacts; autoCompactEnabled off-switch is silently ignored.
  • Leg 1 (identity kernel on compaction) ALREADY works — invoker cwd = entity dir (Issue Concurrent-session entity bleed via shared .claude/CLAUDE.md symlink #226), so entities/<entity>/CLAUDE.md re-reads on compaction, same as terminal. This is why bots "just come back clean."
  • Leg 2 GAP: the invoker builds ClaudeAgentOptions with setting_sources=None and hooks=None → the filesystem PreCompact hook (b9617e7) does not fire in bot SDK sessions.
  • SDK version drift: .venv = claude-agent-sdk 0.1.73; pps/venv = 0.1.58.

Build items (land in haven/brain/ → both surfaces inherit)

  1. Wire PreCompact into the invoker programmatically via hooks= — NOT setting_sources=["project"] (that would drag in inject_context, PreToolUse, etc. and double-inject ambient).
  2. Raise/remove the 150k restart; demote it from primary mechanism to fallback safety-net (only if a session wedges / compaction ever fails).
  3. PreCompact actions = the hardening: (a) refresh the scene (what the far side re-orients from), (b) flush live working-thread state to PPS so the post-compaction self resumes the conversation, not just cold identity.
  4. Add a "preserve on compaction" section to entity CLAUDE.md (re-injected every request → the right home for persistent preserve-instructions).
  5. Align/refresh the SDK across venvs.

Verify

Force /compact on a test invoker with the hook wired → confirm: compaction fires, our PreCompact runs, scene + working-thread captured, post-compaction re-orient is clean, nothing lost.

Related

  • Unblocks the compacting float-text status in SL presence (it needs the PreCompact signal as its honest source).
  • work/sl-presence/context-handling.md, work/sl-presence/write-back-and-status-design.md §5.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions