0ef5fcb1c5
Security / Dependency audit (pip-audit) (push) Has been cancelled
Security / CodeQL (javascript-typescript) (push) Has been cancelled
Security / CodeQL (python) (push) Has been cancelled
Security / Secret scan (gitleaks) (push) Has been cancelled
rust / test (ubuntu) (push) Has been cancelled
rust / simulator e2e (macos-latest) (push) Has been cancelled
rust / simulator e2e (ubuntu-latest) (push) Has been cancelled
rust / simulator e2e (windows-latest) (push) Has been cancelled
rust / wheels (aarch64-apple-darwin) (push) Has been cancelled
rust / wheels (x86_64-unknown-linux-gnu) (push) Has been cancelled
rust / wheels (x86_64-apple-darwin) (push) Has been cancelled
rust / audit (push) Has been cancelled
rust / parity (nightly, allowed to fail during Phase 0) (push) Has been cancelled
CI / commitlint (push) Has been skipped
Dev Containers / validate (.devcontainer/devcontainer.json, default) (push) Failing after 0s
Dev Containers / validate (.devcontainer/memory-stack/devcontainer.json, memory-stack) (push) Failing after 0s
Dev Containers / validate-worktree (push) Failing after 0s
CI / changes (push) Failing after 4s
Deploy Documentation / validate (push) Has been skipped
Deploy Documentation / deploy (push) Failing after 1s
Init Native E2E / init-native (ubuntu-latest, claude) (push) Failing after 1s
Init Native E2E / init-native (ubuntu-latest, codex) (push) Failing after 1s
Install Native E2E / install-native (ubuntu-latest) (push) Failing after 1s
OpenCode Plugin / typecheck + build + test (push) Failing after 1s
Init Native E2E / init-native (ubuntu-latest, copilot) (push) Failing after 1s
Release Please / release-please (push) Failing after 1s
Wrap E2E / docker-wrap-e2e (push) Failing after 1s
Wrap Native E2E / wrap-native (ubuntu-latest) (push) Failing after 1s
Init E2E / docker-init-e2e (push) Failing after 4s
Merge Conflicts / merge-conflicts (push) Failing after 4s
CI / lint (push) Has been cancelled
CI / build-wheel (push) Has been cancelled
CI / build-wheel-windows (push) Has been cancelled
CI / prefetch-model (push) Has been cancelled
CI / test-dashboard-ui (push) Has been cancelled
CI / test (1) (push) Has been cancelled
CI / test (2) (push) Has been cancelled
CI / test (3) (push) Has been cancelled
CI / test (4) (push) Has been cancelled
CI / test-extras (push) Has been cancelled
CI / test-agno (push) Has been cancelled
CI / build (push) Has been cancelled
CI / workflow-validation (push) Has been cancelled
CI / docker-native-e2e (push) Has been cancelled
CI / windows-native-wrapper (push) Has been cancelled
CI / macos-native-wrapper (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-code-nonroot name:code-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-code-slim name:code-slim]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-code-slim-nonroot name:code-slim-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-nonroot name:nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-slim name:slim]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-slim-nonroot name:slim-nonroot]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime name:]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-code name:code]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-code-nonroot name:code-nonroot]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-code-slim name:code-slim]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-code-slim-nonroot name:code-slim-nonroot]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-nonroot name:nonroot]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-slim name:slim]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-slim-nonroot name:slim-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime name:]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-code name:code]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-code-nonroot name:code-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-code-slim name:code-slim]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-code-slim-nonroot name:code-slim-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-nonroot name:nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-slim name:slim]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-slim-nonroot name:slim-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime name:]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-code name:code]) (push) Has been cancelled
Docker / promote-latest (push) Has been cancelled
Init Native E2E / init-native (macos-latest, claude) (push) Has been cancelled
Init Native E2E / init-native (macos-latest, codex) (push) Has been cancelled
Init Native E2E / init-native (macos-latest, copilot) (push) Has been cancelled
Install Native E2E / install-native (macos-latest) (push) Has been cancelled
Wrap Native E2E / wrap-native (macos-latest) (push) Has been cancelled
100 lines
3.3 KiB
Python
100 lines
3.3 KiB
Python
"""Strategy outcome accounting for local compression feedback."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass, field
|
|
|
|
|
|
@dataclass
|
|
class CompressionStrategyOutcomes:
|
|
"""Track compression and retrieval outcomes by compression strategy."""
|
|
|
|
compressions: dict[str, int] = field(default_factory=dict)
|
|
retrievals: dict[str, int] = field(default_factory=dict)
|
|
max_strategies: int = 50
|
|
top_strategies_per_counter: int = 40
|
|
minimum_samples_for_recommendation: int = 3
|
|
|
|
def record_compression(self, strategy: str) -> None:
|
|
"""Record one compression for a strategy."""
|
|
self.compressions[strategy] = self.compressions.get(strategy, 0) + 1
|
|
self.prune()
|
|
|
|
def record_retrieval(self, strategy: str) -> None:
|
|
"""Record one retrieval for a strategy."""
|
|
self.retrievals[strategy] = self.retrievals.get(strategy, 0) + 1
|
|
self.prune()
|
|
|
|
def retrieval_rate(self, strategy: str) -> float:
|
|
"""Return the retrievals-per-compression rate for one strategy."""
|
|
compressions = self.compressions.get(strategy, 0)
|
|
if compressions == 0:
|
|
return 0.0
|
|
return self.retrievals.get(strategy, 0) / compressions
|
|
|
|
def best_strategy(self) -> str | None:
|
|
"""Return the sampled strategy with the lowest retrieval rate."""
|
|
best = None
|
|
best_rate = 1.0
|
|
|
|
for strategy, compression_count in self.compressions.items():
|
|
if compression_count < self.minimum_samples_for_recommendation:
|
|
continue
|
|
|
|
rate = self.retrieval_rate(strategy)
|
|
if rate < best_rate:
|
|
best = strategy
|
|
best_rate = rate
|
|
|
|
return best
|
|
|
|
def prune(self) -> None:
|
|
"""Bound counters while preserving the highest-signal strategies."""
|
|
if (
|
|
len(self.compressions) <= self.max_strategies
|
|
and len(self.retrievals) <= self.max_strategies
|
|
):
|
|
return
|
|
|
|
keys_to_keep = self._keys_to_keep()
|
|
self.compressions = {
|
|
strategy: count
|
|
for strategy, count in self.compressions.items()
|
|
if strategy in keys_to_keep
|
|
}
|
|
self.retrievals = {
|
|
strategy: count
|
|
for strategy, count in self.retrievals.items()
|
|
if strategy in keys_to_keep
|
|
}
|
|
|
|
def _keys_to_keep(self) -> set[str]:
|
|
top_compressions = self._top_keys(self.compressions)
|
|
top_retrievals = self._top_keys(self.retrievals)
|
|
candidate_keys = top_compressions | top_retrievals
|
|
|
|
if len(candidate_keys) <= self.max_strategies:
|
|
return candidate_keys
|
|
|
|
ranked_keys = sorted(
|
|
candidate_keys,
|
|
key=lambda strategy: (
|
|
self.compressions.get(strategy, 0) + self.retrievals.get(strategy, 0),
|
|
self.compressions.get(strategy, 0),
|
|
self.retrievals.get(strategy, 0),
|
|
strategy,
|
|
),
|
|
reverse=True,
|
|
)
|
|
return set(ranked_keys[: self.max_strategies])
|
|
|
|
def _top_keys(self, counts: dict[str, int]) -> set[str]:
|
|
return {
|
|
strategy
|
|
for strategy, _ in sorted(
|
|
counts.items(),
|
|
key=lambda item: (item[1], item[0]),
|
|
reverse=True,
|
|
)[: self.top_strategies_per_counter]
|
|
}
|