Skip to content

feat(session): compaction at task boundaries — in-flight gate, reasons, idle sweep, /compact (CLEAN-155) - #29

Merged
maksymhryzodub-prog merged 1 commit into
feat/CLEAN-154-teachable-memoryfrom
feat/CLEAN-155-boundary-compaction
Oct 26, 2026
Merged

maksymhryzodub-prog merged 1 commit into
feat/CLEAN-154-teachable-memoryfrom
feat/CLEAN-155-boundary-compaction

Conversation

@maksymhryzodub-prog

Copy link
Copy Markdown
Contributor

Stacked on #28 → #27 → #26 → #25 → #24. US4 of specs/001-ecc-agent-principles, tasks T063–T070, plus three security-review fixes for US3.

What

  • Boundary gate — compact(sessionId, llm, { reason, inFlight, force, pending }). With a task of the session still running, size-triggered compaction waits; once the history passes session.hardLimitPct of contextBudgetChars it proceeds as hard-limit. force (operator) ignores thresholds; the recentKeep floor always holds.
  • Reason + in-flight note — every archive summary event carries reason (boundary | idle | hard-limit | operator) and inFlight: { goal, done, pending } (last user message, last three tool calls, owed work), also folded into the summary text so the model sees what was mid-flight. lastCompaction(sessionId) feeds agent_status.
  • Triggers — post-turn flush passes tasks.inFlight(sessionId) (a sibling task may still run); the heartbeat runs compactIdle over sessions idle ≥ idleCompactMin and over threshold, skipping in-flight ones; /compact (admin) with before/after counts.
  • SessionConfig gains contextBudgetChars, hardLimitPct, idleCompactMin; config reload refreshes them.

Security-review fixes (US3)

  • No escalation by chat: only an admin's session teaches behaviours (reviewMemory(..., { isAdmin }) → visitor sessions use the facts-only curator and never reach the instinct store), so "from now on always …" from a visitor installs nothing.
  • Prompt-injection surface: learned trigger/action text is flattened to one bounded plain line (no headings, fences, brackets) before it is rendered back into any prompt.
  • Information disclosure: the learned-behaviour section and skill (unavailable: missing env X) reasons are rendered for admin sessions only; visitors do not see unloadable skills at all.

Tests

  • bun test: 288 pass (+9: compaction gate 6, idle sweep 2, visitor-teaches-nothing 1), 1 pre-existing Windows-only failure.
  • tsc --noEmit: clean apart from the pre-existing bridleAttachments.spec.ts.

Jira: https://dreamvention.atlassian.net/browse/CLEAN-155

🤖 Generated with Claude Code

…s, idle sweep, /compact (CLEAN-155)

US4 of the ECC harness principles (specs/001-ecc-agent-principles, T063-T070),
plus three security-review fixes for US3.

- CompactionService.compact takes { reason, inFlight, force, pending }:
  with a task of the session still running it defers until the history
  passes session.hardLimitPct of contextBudgetChars, then proceeds as
  "hard-limit"; an operator request bypasses thresholds. Every archive
  summary records its reason and an in-flight note (goal from the last
  user message, last three tool calls, pending work) so the next phase
  can pick up; the last compaction per session is kept for agent_status.
- Post-turn flush passes whether a sibling task is still in flight; the
  heartbeat sweeps sessions idle for session.idleCompactMin and over
  threshold, skipping in-flight ones; /compact (admin) compacts now and
  reports before/after counts.
- Security review (US3): only an admin's session can teach behaviours —
  a visitor phrasing a message as a standing rule installs nothing;
  learned text is flattened to one bounded plain line before it is
  rendered back into prompts; the learned-behaviour section and skill
  unavailability reasons (env/binary names) are shown to admins only.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@maksymhryzodub-prog
maksymhryzodub-prog force-pushed the feat/CLEAN-155-boundary-compaction branch from 5bdd882 to 32c9795 Compare October 26, 2026 14:26
@maksymhryzodub-prog
maksymhryzodub-prog merged commit 7183040 into main Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant