Context compression: aux model summarization pipeline #822

Closed
opened 2026-10-27 13:37:53 +00:00 by sam · 0 comments
Owner

Remaining: wire an automatic context-compression trigger on the messaging path. Compression runs on that path but only when the user asks - /compress and /compact route into it (internal/gateway/gateway.go:411) while the only production callers are internal/gateway/session_commands.go:667 and :780. Nothing watches session size. Fire compression when a session context crosses the configured threshold (CompressionConfig.Threshold, default 0.5, budget derived from the selected model context window by CompressionConfigForModel) so the channel path does not depend on a user typing the command.

The compressor is done and must not be rebuilt: internal/gateway/compression.go holds CompressionConfig, CompressionConfigForModel and CompressHistory (inserting a bot-attributed summary). The work is the trigger, plus verifying that the Telegram-to-gateway path reaches it.

Migration state, corrected 2026-09-22. An earlier revision of this description claimed docs/architecture/migration-decisions.md:24 and internal/domain/messaging/message.go:9-12 were STALE in describing the gateway-to-messaging migration as pending. They are not stale. Section 2 of that register is actively maintained (amended 2026-08-31, 2026-09-15 and 2026-09-19) and its work under the messaging-migration label is 3 of 6 closed - closed: d9dv (gateway session storage onto messaging types), 9g5e (Router and ChatContract signature flip), o4e4 (dashboard chat); open: 4hof (Telegram behavioural verification), h3w2 (email/webhook verification), b6ks (Conversation-keying gateway session records). The migration is partially complete, not done, and both records are accurate as written. Do not edit them as part of this bead.

Split out 2026-09-22: summary curator is archie-core-22ed, iterative merging is archie-core-qjbk. Templates dropped by maintainer decision.

Notes

docs/prds/hermes-gap-analysis.md (referenced above) was intentionally deleted in commit 65aa5b4 ('chore: cleanup', 2026-07-28) after it had already spawned this and ~14 sibling beads issues from its 60 identified gaps — it is not a broken link to restore. This issue's description is the surviving record of its slice of that analysis.
Maintainer 2026-09-22: STILL REQUIRED - summarisation, templates, merging, and possibly implemented as custom curators. Source doc lists 'Context compression pipeline' and 'Session splitting on compression' (:79, :92, both P2). internal/domain/curator and internal/domain/sampling are the likely homes for a curator-shaped implementation. Next: reword against that shape.
Trace 2026-09-22 (read-only, file:line): compressor internal/gateway/compression.go:13 CompressionConfig, :21 Threshold (default 0.5 at :51), :63 CompressionConfigForModel, :148 CompressHistory, :159 threshold = ContextWindow*Threshold; command routing internal/gateway/gateway.go:411 case "/compress","/compact"; only production callers internal/gateway/session_commands.go:606,651,667,780; tests compression_test.go and compress_identity_test.go. No automatic caller found. messaging/message.go:9 records that migrating the gateway session, compression, approval and branch logic onto messaging types is deliberate out-of-scope there, tracked as follow-up.
Correction 2026-09-22: an earlier version of this description called the move into internal/domain/messaging "a separate, already-recorded migration decision". The maintainer corrected that - the migration is DONE and the messaging path is the required path. The two records quoted above still say otherwise and need fixing.
IMPLEMENTED 2026-09-22 in 2da570b9 (cp-compress lane). The trigger lives at TurnRunner.prepareTurn (internal/gateway/turn.go:365) - after the model-derived budget is built and the inbound message persisted, before the request is assembled. /compress and the trigger share one implementation, Router.compressSessionHistory (session_commands.go:792), differing only in the budget passed (command: DefaultCompressionConfig; trigger: CompressionConfigForModel). Unknown budget is a no-op covering a non-DetailedModelManager, a details miss and a zero window. Once-per-crossing follows from the compressor landing the history at or below threshold, asserted over three further turns.

Residuals the lane declared, none of which justify a follow-up on their own but which should be known before anyone changes this: (1) the trigger persists a compression BEFORE the model runs, so a turn that then fails still leaves the session compressed - the same durability /compress has, idempotent under retry, but it is a new write on the turn path; (2) once-per-crossing is derived, not a state machine, so a pathologically tight MaxPromptTokens can make consecutive turns genuine new crossings - strict hysteresis would be a CompressionConfig change, not a trigger change; (3) /retry replays through r.LLM (session_commands.go:428) so it now also passes through the trigger; (4) redelivery of a very old message after compression finds its prior reply only via TurnReplayStore.FindPriorReply, never in the summarised history - pre-existing with /compress, now unattended.

Close reason

Landed on main (1222ca3b, re-gated as ecf42c8c). The automatic compression trigger fires on the messaging path at TurnRunner.prepareTurn, before the request is assembled and after the inbound message is persisted, reusing the single compression implementation that /compress uses; an unknown model budget is a no-op rather than a guess. Residuals (pre-model write, /retry passing through, derived once-per-crossing) are recorded in the bead notes.


Imported from beads archie-core-1786637497421-290-7ec1407d · GitHub #311 · type feature · priority P2 · created 2026-08-08 · closed 2026-09-21

Remaining: wire an automatic context-compression trigger on the messaging path. Compression runs on that path but only when the user asks - /compress and /compact route into it (internal/gateway/gateway.go:411) while the only production callers are internal/gateway/session_commands.go:667 and :780. Nothing watches session size. Fire compression when a session context crosses the configured threshold (CompressionConfig.Threshold, default 0.5, budget derived from the selected model context window by CompressionConfigForModel) so the channel path does not depend on a user typing the command. The compressor is done and must not be rebuilt: internal/gateway/compression.go holds CompressionConfig, CompressionConfigForModel and CompressHistory (inserting a bot-attributed summary). The work is the trigger, plus verifying that the Telegram-to-gateway path reaches it. Migration state, corrected 2026-09-22. An earlier revision of this description claimed docs/architecture/migration-decisions.md:24 and internal/domain/messaging/message.go:9-12 were STALE in describing the gateway-to-messaging migration as pending. They are not stale. Section 2 of that register is actively maintained (amended 2026-08-31, 2026-09-15 and 2026-09-19) and its work under the messaging-migration label is 3 of 6 closed - closed: d9dv (gateway session storage onto messaging types), 9g5e (Router and ChatContract signature flip), o4e4 (dashboard chat); open: 4hof (Telegram behavioural verification), h3w2 (email/webhook verification), b6ks (Conversation-keying gateway session records). The migration is partially complete, not done, and both records are accurate as written. Do not edit them as part of this bead. Split out 2026-09-22: summary curator is archie-core-22ed, iterative merging is archie-core-qjbk. Templates dropped by maintainer decision. ### Notes docs/prds/hermes-gap-analysis.md (referenced above) was intentionally deleted in commit 65aa5b4 ('chore: cleanup', 2026-07-28) after it had already spawned this and ~14 sibling beads issues from its 60 identified gaps — it is not a broken link to restore. This issue's description is the surviving record of its slice of that analysis. Maintainer 2026-09-22: STILL REQUIRED - summarisation, templates, merging, and possibly implemented as custom curators. Source doc lists 'Context compression pipeline' and 'Session splitting on compression' (:79, :92, both P2). internal/domain/curator and internal/domain/sampling are the likely homes for a curator-shaped implementation. Next: reword against that shape. Trace 2026-09-22 (read-only, file:line): compressor internal/gateway/compression.go:13 CompressionConfig, :21 Threshold (default 0.5 at :51), :63 CompressionConfigForModel, :148 CompressHistory, :159 threshold = ContextWindow*Threshold; command routing internal/gateway/gateway.go:411 case "/compress","/compact"; only production callers internal/gateway/session_commands.go:606,651,667,780; tests compression_test.go and compress_identity_test.go. No automatic caller found. messaging/message.go:9 records that migrating the gateway session, compression, approval and branch logic onto messaging types is deliberate out-of-scope there, tracked as follow-up. Correction 2026-09-22: an earlier version of this description called the move into internal/domain/messaging "a separate, already-recorded migration decision". The maintainer corrected that - the migration is DONE and the messaging path is the required path. The two records quoted above still say otherwise and need fixing. IMPLEMENTED 2026-09-22 in 2da570b9 (cp-compress lane). The trigger lives at TurnRunner.prepareTurn (internal/gateway/turn.go:365) - after the model-derived budget is built and the inbound message persisted, before the request is assembled. /compress and the trigger share one implementation, Router.compressSessionHistory (session_commands.go:792), differing only in the budget passed (command: DefaultCompressionConfig; trigger: CompressionConfigForModel). Unknown budget is a no-op covering a non-DetailedModelManager, a details miss and a zero window. Once-per-crossing follows from the compressor landing the history at or below threshold, asserted over three further turns. Residuals the lane declared, none of which justify a follow-up on their own but which should be known before anyone changes this: (1) the trigger persists a compression BEFORE the model runs, so a turn that then fails still leaves the session compressed - the same durability /compress has, idempotent under retry, but it is a new write on the turn path; (2) once-per-crossing is derived, not a state machine, so a pathologically tight MaxPromptTokens can make consecutive turns genuine new crossings - strict hysteresis would be a CompressionConfig change, not a trigger change; (3) /retry replays through r.LLM (session_commands.go:428) so it now also passes through the trigger; (4) redelivery of a very old message after compression finds its prior reply only via TurnReplayStore.FindPriorReply, never in the summarised history - pre-existing with /compress, now unattended. ### Close reason Landed on main (1222ca3b, re-gated as ecf42c8c). The automatic compression trigger fires on the messaging path at TurnRunner.prepareTurn, before the request is assembled and after the inbound message is persisted, reusing the single compression implementation that /compress uses; an unknown model budget is a no-op rather than a guess. Residuals (pre-model write, /retry passing through, derived once-per-crossing) are recorded in the bead notes. --- _Imported from beads `archie-core-1786637497421-290-7ec1407d` · GitHub #311 · type feature · priority P2 · created 2026-08-08 · closed 2026-09-21_
sam added the mediumfeature labels 2026-10-27 13:37:53 +00:00
sam self-assigned this 2026-10-27 13:37:53 +00:00
sam closed this issue 2026-10-27 13:37:53 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sam/archie#822