Skip to content

Lean sessions: where long-session requests go, and flag-gated prototypes - #50

Draft
solvyxtech wants to merge 3 commits into
claude/lean-guardsfrom
claude/lean-sessions
Draft

solvyxtech wants to merge 3 commits into
claude/lean-guardsfrom
claude/lean-sessions

Conversation

@solvyxtech

Copy link
Copy Markdown
Owner

Measurement study of where a long session's request characters go, plus prototypes behind MAAT_LEAN_* env flags. No default changes; every flag is off unless set. Full write-up: reports/lean-sessions-study.md (local reports dir).

Breakdown (flags off, scripted providers, no paid calls)

Scenarios: lean-budget d, plus two real Mistral Large 4 bench runs (80 and 93 requests) replayed call for call from their exuviae. The duration-bug replay sends 3.01M estimated tokens; the real run billed 3.06M.

d replay duration-bug replay perf-pairs
total chars 7,262,564 12,049,129 11,607,938
tool results 89.9% 76.3% 71.9%
results older than newest six 60.8% 67.8% 64.0%
tool calls 2.1% 13.0% 17.8%
system prompt + tool schemas 5.8% 5.3% 4.7%
cacheable prefix 94.2% 97.5% 97.6%

The system prompt and tool schemas are a small, cached cost, and nothing changing sits early in the prompt. The session's size is set by the 60k auto-shed threshold.

Prototypes (total chars / cache-weighted, vs baseline)

flag d duration-bug perf-pairs
MAAT_LEAN_SHED_AT=30000 −39% / −23% −44% / −34% −50% / −39%
MAAT_LEAN_SHED_AT=40000 −25% / −15% −32% / −27% −41% / −33%
MAAT_LEAN_AGE=1 + _ARGS=1 (batched ageing) −27% / +13% −30% / −17% −38% / −23%
MAAT_LEAN_AGE=at=30000,batch=0 + _ARGS=1 (soft shed) −31% / −9% −38% / −28% −48% / −35%
MAAT_LEAN_SHED_MINFREE=0.25 0 0 0 (fixes the shed defects below)
MAAT_LEAN_SUPERSEDE=1 0 0 0 (fixes the elision bug below)

Cache-weighted counts cached prefix chars at 10%.

Defects found

  • Wasted shed: Maat's own notes are user messages, so a shed can cut near the start of the session. The real run shed 60,788 → 60,387 tokens (0.7%), which threw away the whole cache, and then shed again one step later. With a tiny first exchange, planShed returns null and auto-shed never fires again. SHED_MINFREE fixes both.
  • Elision drops unrelated results: superseded reads are keyed by step, so writing dur.py also elided test_dur.py, which had been read in the same step. SUPERSEDE makes elision per call.

Checks

  • lean-budget passes 7/7 with each flag, except batched AGE. That fails only d's "the long session never shed" mechanism check: ageing keeps the history under 60k. Its numbers are well under the ceilings.
  • npm run check passes with each flag on. Batched AGE fails the same single test; e2e and self-check pass when run separately.

Tyler Skelton added 3 commits October 7, 2026 23:37
test/lean-breakdown.ts splits every request body into system prompt, pinned
note, digest, tool schemas, user/assistant/tool messages and envelope, and
measures old results, repeated lines, superseded output, the cacheable prefix
and a cache-weighted total. test/lean-sessions.test.ts runs lean-budget
scenario d and replays two real 80-93 step bench runs call for call from their
exuviae (fixtures plus scripts/lean-replay-extract.py). Scripted providers
only.
- MAAT_LEAN_SHED_AT: auto-shed threshold when none is configured
- MAAT_LEAN_SHED_MINFREE: a shed cut on user turns must free this share of the
  history, else it cuts on recent messages (fixes a shed that freed 0.7% and a
  plan that returned null and stopped auto-shed)
- MAAT_LEAN_AGE (+ _ARGS): older tool results and long arguments go on the
  wire as their ends plus a pointer to the full text in .maat/out; batched, or
  timed as a soft shed with at=
- MAAT_LEAN_SUPERSEDE: elide per call instead of per step (a write to one file
  elided every result of the step that read it), bash reruns with new output,
  plain cat/sed -n reads of a file written since

scripts/lean-sessions-measure.mjs runs every flag over every scenario.
A rerun with a longer timeout_s exists because of the earlier result (the
timeout and how to avoid it); eliding it lost the reason. harness.test.ts
caught it with MAAT_LEAN_SUPERSEDE=1.
@solvyxtech solvyxtech added the claude Owned by claude label Oct 8, 2026
solvyxtech pushed a commit that referenced this pull request Oct 8, 2026
…ighter supersede

- A shed that cuts on recent messages keeps the latest criteria note
  (now tagged molt.criteria) and the live bar refusal verbatim after the
  digest, instead of excerpting them to 300 chars.
- Min-free falls back only when the kept user turns are mostly Maat's
  notes; an interactive session is cut on user turns as before.
- A bash read answered with a same-call pointer is not noted as a read,
  so a later write still elides the full copy.
- The rerun key sorts its keys; background runs take no part in rerun
  supersession; commands:[...] calls stay out (noted in a comment).
- Docs and the test header cite PR #50 instead of a report not on this base.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

claude Owned by claude

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant