Skip to content

feat(compression): make proactive context-compression threshold a live setting - #11564

Merged
diegosouzapw merged 5 commits into
diegosouzapw:release/v3.8.51from
ragnar-claude:feat/proactive-compression-threshold-knob
Sep 2, 2026
Merged

diegosouzapw merged 5 commits into
diegosouzapw:release/v3.8.51from
ragnar-claude:feat/proactive-compression-threshold-knob

Conversation

@ragnar-claude

Copy link
Copy Markdown
Contributor

The proactive compression trigger ratio is a hardcoded COMPRESSION_THRESHOLD = 0.7 in chatCore. Operators cannot move compression relative to a client's own compaction point — e.g. Codex Desktop self-compacts at ~0.85 of its window, so the 0.7 proxy threshold always preempts the client's compaction with the proxy's lossier one (see #8932 for what that produced before 3.8.50).

This PR makes the ratio a live setting: key_value namespace compression, key proactiveConfig, {"thresholdRatio": 0.7}. Clamped [0.1, 0.99], 30s TTL cache, follows the ipFilter persistence pattern (#6131) — synchronous read stays in the sync hot path. Default unchanged; missing/invalid rows fall back to 0.7.

Tested: compression suite green including the #8932 regression; verified live on a production deployment (385k-token Responses request with a custom_tool_call pair compressed 385,056 → 188,039 and accepted upstream, zero orphaned calls).

@ragnar-claude
ragnar-claude force-pushed the feat/proactive-compression-threshold-knob branch from f836006 to af38cb0 Compare August 26, 2026 05:57
…e setting

The proactive compression trigger ratio was a hardcoded COMPRESSION_THRESHOLD =
0.7 in chatCore. Operators could not move compression relative to a client's own
compaction point (e.g. Codex Desktop self-compacts at ~0.85 of its window, so
the 0.7 proxy threshold always preempts the client's compaction with the
proxy's lossier one — see #8932 for what that produced before 3.8.50).

New: key_value namespace 'compression', key 'proactiveConfig',
{"thresholdRatio": 0.7}. Clamped [0.1, 0.99], 30s TTL cache, ipFilter
persistence pattern (#6131), synchronous read stays in the hot path. Default
unchanged; missing/invalid rows fall back to 0.7.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@ragnar-claude
ragnar-claude force-pushed the feat/proactive-compression-threshold-knob branch from af38cb0 to 2a9c7ac Compare August 26, 2026 06:02
@diegosouzapw

Copy link
Copy Markdown
Owner

Diffstat muito grande/desalinhado com o escopo do título para validação segura no fluxo de lote atual (mesmo padrão já aplicado a #11390, #11461, #11392). Adiando para uma sessão dedicada de análise no ciclo v3.8.52 — sem prejuízo do trabalho, só precisa de atenção isolada em vez de ser boarded junto com dezenas de outras PRs pequenas.

…ad, validity bounds, fallback, TTL)

Locks in getProactiveCompressionRatio() (src/lib/db/compression.ts), the
key_value-backed replacement for chatCore's hardcoded 0.7:

  - shipped default 0.7 when no compression/proactiveConfig row exists
  - 30s TTL cache: a fresh DB write stays invisible until the TTL lapses
    (clock mocked via node:test mock timers, Date API — the module keeps
    its cache private with no reset hook)
  - valid override read from key_value, boundary values 0.1/0.99 included
  - out-of-range ratios fall back to the DEFAULT (a validity window, not
    clamping to the nearest bound — matching the shipped comment)
  - broken JSON / non-numeric thresholdRatio: 0.7, without throwing

Guard verified by mutation: switching the window to clamping fails the
out-of-range case.
@diegosouzapw
diegosouzapw merged commit 9682428 into diegosouzapw:release/v3.8.51 Sep 2, 2026
3 checks passed
patrykkopycinski added a commit to patrykkopycinski/OmniRoute that referenced this pull request Sep 6, 2026
diegosouzapw#12151 landed with a never-called collectSSE helper in
stream-passthrough-usage-estimation.test.ts; its three unused
identifiers (collectSSE / stream / writable) fail
'npm run lint:json -- --max-warnings 0', so the 'No new ESLint
warnings' job reds every PR merge-ref cut from the current tip
(first seen on PR diegosouzapw#11564's post-sync run). createSSEStream and
parseSSEUsage are actually used and stay; only the dead closure
goes. File suite still passes 6/6.

(cherry picked from commit 3b1520b)

Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
@ragnar-claude
ragnar-claude deleted the feat/proactive-compression-threshold-knob branch September 24, 2026 22:35
muhamadgalihsaputra pushed a commit to niyatna/NiyatnaRoute that referenced this pull request Sep 27, 2026
…e setting (diegosouzapw#11564)

* feat(compression): make proactive context-compression threshold a live setting

The proactive compression trigger ratio was a hardcoded COMPRESSION_THRESHOLD =
0.7 in chatCore. Operators could not move compression relative to a client's own
compaction point (e.g. Codex Desktop self-compacts at ~0.85 of its window, so
the 0.7 proxy threshold always preempts the client's compaction with the
proxy's lossier one — see diegosouzapw#8932 for what that produced before 3.8.50).

New: key_value namespace 'compression', key 'proactiveConfig',
{"thresholdRatio": 0.7}. Clamped [0.1, 0.99], 30s TTL cache, ipFilter
persistence pattern (diegosouzapw#6131), synchronous read stays in the hot path. Default
unchanged; missing/invalid rows fall back to 0.7.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* test(compression): cover the live proactive-compression threshold (read, validity bounds, fallback, TTL)

Locks in getProactiveCompressionRatio() (src/lib/db/compression.ts), the
key_value-backed replacement for chatCore's hardcoded 0.7:

  - shipped default 0.7 when no compression/proactiveConfig row exists
  - 30s TTL cache: a fresh DB write stays invisible until the TTL lapses
    (clock mocked via node:test mock timers, Date API — the module keeps
    its cache private with no reset hook)
  - valid override read from key_value, boundary values 0.1/0.99 included
  - out-of-range ratios fall back to the DEFAULT (a validity window, not
    clamping to the nearest bound — matching the shipped comment)
  - broken JSON / non-numeric thresholdRatio: 0.7, without throwing

Guard verified by mutation: switching the window to clamping fails the
out-of-range case.

---------

Co-authored-by: root-cli (Hermes ops) <info@livewellwith.us>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
Co-authored-by: Diego Rodrigues de Sa e Souza <diegosouza.pw@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deferred-v3.8.52 Grande demais / suspeito para o lote atual; precisa de sessão dedicada no ciclo v3.8.52

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants