compaction: the service — settle kick, turn-start gate, registry mutex (round 14 slice 2)

- src/server/compaction.ts: ensureCompacted (the turn-start gate — awaits
  in-flight compaction, compacts synchronously when still over threshold),
  kickCompaction (the settle kick — summary starts inside the learner's
  reading/answering pause; question/problem poses end runs so the pause is
  always a between-runs window), registry mutex on globalThis, anti-churn
  guard (empty-span skip), summary via the zero-tool one-shot sub-agent
  seam on the session's OWN engine (owner ruling), usage to the turns log
  keyed by the marker, record-changed + compaction-changed events
- chat-handler: the gate rides with the BYOK/key gates (before appends,
  beginTurn; record re-read after); the kick at the onFinish tail
  (re-resolves engine fresh; silent no-op when engineless)
- events: compaction-changed {chatId, running} — running=true is the
  client send-gate signal
- settings: compaction.thresholdTokens (factory 150k, floor 32k,
  clamp-never-reject) resolved concrete in EffectiveSettings
- effective threshold = min(setting, contextWindow − 16k) over the live
  catalog index
- overflow recovery needs no special path: the next turn's gate compacts
- 8 service pins (mutex, events order, chained spans, failure re-arm)
This commit is contained in:
amosblomqvist
2026-10-05 22:17:33 +03:00
parent 7e9597d969
commit dd159cc8fb
6 changed files with 612 additions and 2 deletions
+7
View File
@@ -35,6 +35,7 @@ import {
type BackgroundModelRole,
type FactorySettings,
type GeneralSettings,
type CompactionSettings,
type GraphSettings,
type ModelSlot,
type ModelSlotName,
@@ -89,6 +90,9 @@ export interface EffectiveSettings {
models: Record<ModelSlotName, EffectiveSlot | null>;
appearance: EffectiveAppearance;
graph: Required<GraphSettings>;
/** Compaction (owner round 14): resolved concrete — absent record
* section resolves to the factory 150k. */
compaction: Required<CompactionSettings>;
}
/** The conversation pair's chain (BYOK, owner 2026-09-22): the chat's own
@@ -206,6 +210,9 @@ export function resolveSettings(record: UserSettings | null): EffectiveSettings
// 4096; the sanitizer has already clamped/floored any stored value.
extractionChunkTokens: graph.extractionChunkTokens ?? FACTORY_SETTINGS.graph.extractionChunkTokens,
},
compaction: {
thresholdTokens: record?.compaction?.thresholdTokens ?? FACTORY_SETTINGS.compaction.thresholdTokens,
},
};
}