mirror of
https://github.com/headroomlabs-ai/headroom.git
synced 2026-08-27 14:17:10 -04:00
## Description The CCR store default TTL is `DEFAULT_TTL = 1800s` (30 minutes — see `crates/headroom-core/src/ccr/mod.rs` and `config.py store_ttl_seconds=1800`), but several user-facing hints and docstrings still said "5 minutes", the old default. The opencode/openclaw retrieve tools surfaced `(default TTL: 5 minutes)` in their expiry hint — exactly the misleading message reported in #1023. (The CCR cache itself works; the row-drop store bridge that populates the retrieve store landed for #389.) This corrects the two plugin hints, the `InMemoryCcrStore` docstrings, the SQLite/backend default TTL comments, and the `smart_crusher` mirror comment. The `mod.rs` comment that references "the *old* 5-minute default" is intentionally left unchanged — it correctly describes history. ## Type of Change - [x] Documentation update ## Changes Made - `plugins/openclaw/src/tools/headroom-retrieve.ts` + `plugins/opencode/src/retrieve.ts`: retrieve-failure hint `5 minutes` → `30 minutes`. - `crates/headroom-core/src/ccr/backends/in_memory.rs`: two docstrings (`5 minutes by default`, `5-minute TTL`) → `30 minutes` / `30-minute`. - `crates/headroom-core/src/ccr/backends/mod.rs` + `sqlite.rs`: SQLite/default backend TTL comments `5-minute` → `30-minute`. - `headroom/transforms/smart_crusher.py`: mirror comment `defaults to 5 minutes` → `30 minutes`. ## Testing - [x] Linting passes (`ruff` / `cargo check`) - [x] Manual verification (see Real Behavior Proof) ### Test Output ```text $ ruff format --check headroom/transforms/smart_crusher.py # clean $ cargo check -p headroom-core # Finished, no errors ``` ## Real Behavior Proof - Environment: macOS (Darwin), branch `feat/ccr-ttl-hint-fix` off `main`. - Exact command / steps: grepped every `5 minutes` / `5-minute` TTL reference across the repo; confirmed the real default is `DEFAULT_TTL = Duration::from_secs(1800)` (`ccr/mod.rs:66`), that `InMemoryCcrStore::new()` uses `DEFAULT_TTL` (not a local 300s), and that `config.py` sets `store_ttl_seconds = 1800 # 30 minutes`. - Observed result: all stale CCR default-TTL "5 minutes" references now read "30 minutes"; the one historical reference (`mod.rs`: "the old 5-minute default") is left as-is because it is accurate. - Not tested: nothing runtime changed — these are docstring/comment/hint string edits only, so there is no behavior to exercise. ## Review Readiness - [x] I have performed a self-review - [x] This PR is ready for human review ## Checklist - [x] My code follows the project's style guidelines - [x] I have performed a self-review of my code - [ ] I have commented my code — N/A (this PR is comments/strings) - [x] I have made corresponding changes to the documentation (this *is* the doc change) - [x] My changes generate no new warnings - [ ] I have added tests — N/A (no behavior change) - [x] New and existing unit tests pass locally with my changes - [ ] I have updated the CHANGELOG.md — N/A: user-facing hint/docstring correction, no functional change ## Additional Notes - Surfaced while root-causing #1023: the "cache permanently empty / TTL: 5 minutes" report is resolved on `main` (the store-bridge for #389 populates the retrieve store), but the stale "5 minutes" strings the reporter actually saw were still in the tree. This PR fixes those. --------- Co-authored-by: JerrettDavis <mxjerrett@gmail.com>
88 lines
2.5 KiB
TypeScript
88 lines
2.5 KiB
TypeScript
import type { CompressResult } from "headroom-ai";
|
|
import { compress } from "headroom-ai";
|
|
|
|
let _proxyUrlCache: string | null = null;
|
|
|
|
export function setDefaultProxyUrl(url: string): void {
|
|
_proxyUrlCache = url;
|
|
}
|
|
|
|
export function getDefaultProxyUrl(): string {
|
|
return _proxyUrlCache ?? process.env.HEADROOM_BASE_URL ?? "http://localhost:8787";
|
|
}
|
|
|
|
export interface RetrieveToolConfig {
|
|
proxyBaseUrl: string;
|
|
}
|
|
|
|
export function createHeadroomRetrieveTool(config: RetrieveToolConfig) {
|
|
const origin = config.proxyBaseUrl.replace(/\/+$/, "");
|
|
|
|
return {
|
|
name: "headroom_retrieve",
|
|
description:
|
|
"Retrieve original uncompressed content from Headroom's compression store. " +
|
|
"Use when compressed context mentions a hash and you need the full details. " +
|
|
"Pass the hash from the compression marker (24 hex characters). " +
|
|
"Retrieval is by hash and always returns the full original content.",
|
|
parameters: {
|
|
type: "object" as const,
|
|
properties: {
|
|
hash: {
|
|
type: "string",
|
|
description: "The 24-character hex hash from the compression marker",
|
|
},
|
|
},
|
|
required: ["hash"],
|
|
},
|
|
execute: async (args: { hash: string }): Promise<string> => {
|
|
const { hash } = args;
|
|
|
|
if (!/^[a-f0-9]{24}$/i.test(hash)) {
|
|
return JSON.stringify({
|
|
error: "Invalid hash format. Expected 24 hex characters.",
|
|
});
|
|
}
|
|
|
|
try {
|
|
const url = `${origin}/v1/retrieve/${hash}`;
|
|
|
|
const resp = await fetch(url, {
|
|
signal: AbortSignal.timeout(10_000),
|
|
});
|
|
|
|
if (!resp.ok) {
|
|
const body = await resp.text().catch(() => "");
|
|
return JSON.stringify({
|
|
error: `Retrieval failed: HTTP ${resp.status}`,
|
|
details: body,
|
|
});
|
|
}
|
|
|
|
const data = await resp.json();
|
|
return typeof data === "string" ? data : JSON.stringify(data);
|
|
} catch (error) {
|
|
return JSON.stringify({
|
|
error: `Retrieval failed: ${error}`,
|
|
hint: "The compressed content may have expired (default TTL: 30 minutes)",
|
|
});
|
|
}
|
|
},
|
|
};
|
|
}
|
|
|
|
export async function compressWithHeadroom(
|
|
messages: unknown[],
|
|
options: {
|
|
model?: string;
|
|
tokenBudget?: number;
|
|
proxyUrl?: string;
|
|
} = {},
|
|
): Promise<CompressResult> {
|
|
return compress(messages, {
|
|
baseUrl: options.proxyUrl ?? getDefaultProxyUrl(),
|
|
model: options.model ?? "gpt-4o",
|
|
tokenBudget: options.tokenBudget,
|
|
stack: "opencode",
|
|
});
|
|
}
|