Commit Graph

6084 Commits

Author SHA1 Message Date
kshitijk4poor
52adc43ca0 fix(providers): never reclaim an unproven root; keep live snapshots through data-only uninstall
Review fold on 37f19c9572 (round-2 gate and second-model findings):

- The sweep reclaimed any `owned-*` directory with no owner.lock, so a
  directory a user made with that name was deleted. It now reclaims an owned
  root only when its owner.lock exists and nobody holds it. A process that
  dies between creating its root and locking it now leaks that empty root
  instead.
- `hermes uninstall` (data-only) removed runtime/provider-plugins, including
  the copies live processes import from, because the removal plan protected
  only some runtime files. The snapshot directory is now in the plan's
  protected set; dead roots there are still reclaimed by the next process.
- A claim another sweeper is still deleting can be taken again and deleted
  twice. That costs only the duplicated work, since both deletes ignore
  errors, but the docstring and the previous commit said it could not
  happen; the docstring now says what does.
- The module docstring and _new_root now describe the unswept fallback
  instead of saying every process holds an owner lock, and the plugin-testing
  guide names the Hermes root (not the profile home) as where the copies live.

Part of #156493.
2026-11-19 03:31:38 -08:00
kshitijk4poor
b3a7957ce9 fix(providers): reclaim snapshots of exited processes; keep live ones out of transfers
Follow-up on the salvaged move of provider-plugin snapshots to
<home>/runtime/provider-plugins (#156209 by @akinduroifedayo). That keeps the
copies away from the age-based temp cleaners that broke long-running gateways
(#156493). Two gaps remained once the copies no longer live in a cleaned dir:

Crashed and killed processes left their root behind forever, so the directory
grew with every unclean exit. Each process now holds an OS lock on owner.lock
in its own root while it runs (pm.filesystem.lock_path). The next process to
create a root reclaims the ones nobody holds, under one setup lock so a sweep
never sees a root whose owner has made it but not locked it yet. Only
hermes-provider-plugins-* roots are touched. Dead roots are renamed out of the
way under the lock and deleted after it is released, so a large one never
holds up other processes starting; a sweeper killed mid-delete leaves only
.reaping-* names, which the next sweep finishes. A lock file this user cannot
open (a home shared across UIDs) only skips the reclaim, with a warning; the
process still gets a root of its own.

The exit hook now removes the root only in the process that created it. A
forked child inherits the hook and shares the flock, so a normal exit there
deleted its live parent's copy and dropped its lock.

A live root is also process state, not home data: `hermes backup` and
`hermes profile create --clone-all` now leave runtime/provider-plugins out
(PROVIDER_PLUGIN_SNAPSHOT_PARTS in hermes_cli.home_data_layout).

The plugin-testing guide suggested a HERMES_HOME inside ~/.hermes/cache/scratch,
which the scratch pruner cleans by age; it now uses a directory outside it and
says why.

Part of #156493.
2026-11-19 03:31:38 -08:00
kshitijk4poor
beabd04e63 fix(compression): sandboxed backends archive pruned results where the sandbox can read them
On docker, modal, ssh, daytona and vercel_sandbox the cold prune and the compaction
offload kept every result whole (no saving) or dropped it without an archive, because
cache/pruned was not published into the sandbox and the stub named a host-only path.

cache/pruned now joins the cache dirs docker bind-mounts and the synced backends push,
the stub names the path the sandbox reads (to_agent_visible_cache_path), and read_file
forces a sync before opening an archive on a file-synced backend. Plugin backends and a
hosted scope still keep results whole.
2026-11-19 03:15:20 -08:00
Teknium
8dbe7ec0a4 fix(gateway): a gateway service declined in setup stays declined through the installer
install.sh and install.ps1 run `hermes gateway install --if-missing` right
after `hermes setup`. That path only checked whether a service was already
installed, then took the explicit-install route: it asked start-now and
start-on-login (both default Yes), wrote the unit whatever the answers, and
overwrote the recorded `gateway.service_install_choice: decline` with
`install`. A user who said No in setup got a service anyway.

`--if-missing` now goes through setup's own consent seam: an installed
service is a no-op, a recorded decline prints how to opt in later, and an
unanswered question is asked once via ensure_gateway_service. Plain
`hermes gateway install` stays the explicit opt-in.

Fixes #157677
2026-11-19 01:53:36 -08:00
Teknium
27d203be8c fix(bot-mode): teammate-wait reads go through the storage interface main now uses
Rebasing onto main: the old session store (hermes_state_runtime, SessionDB's
admission helper) was removed, so bot_delivery.list failed at import and the
gateway handler table could not load. The owner join now reads the target's
admission from its authority's persistence handle, the sidecar's stored state
from a read-only persistence reader, and the sender's home from the authority's
profile_id. bot_mode_probe._handle now takes the roster's names (a real
profiles/hermes keeps @hermes), so the strip and the sidecar resolve handles
the way the rest of Bot Mode does. Regenerated the serve handler ledger.
2026-11-19 00:41:03 -08:00
BearHuddleston
ca8e736130 docs: describe the diagnostic Linux AppImage builds
The workflow README, platform support page, bundle and stable release
guides, desktop README/BUILDING and the install smoke README said the Linux
desktop legs were disabled. They now say what the workflow does: canary
tags build Linux AppImages as diagnostic artifacts that stage to the tag
archive, gate nothing, have no smoke or feed, and are offered by no
release; commit builds skip them. The PM Bundle Linux legs stay listed as
disabled.
2026-11-19 02:35:54 -06:00
Electric Sheep
e7e66a1120 fix(compression): read every archive reference row, without the 20,000 cap
referenced_archive_refs read at most 20,001 rows and answered "unknown"
past 20,000, and the sweep then kept every file in cache/pruned and
cache/spillover. Every prune stub row counts toward that number, so a
busy home passed it and was never swept again.

Rows are now read one at a time with no cap; memory is bounded by the
reference set. Any database error still answers "unknown", so the sweep
still fails closed. Below the old cap the cost is unchanged (the filter
has no index, so the whole table was already scanned). Past it the read
used to stop at the 20,001st match and now runs to the end, so on a
large home it stays open longer. The docs sentence about the cap is
removed.

(cherry picked from commit a5bed1d2d9fb436f6129388b237330a509abb6aa)
2026-11-18 20:36:07 -08:00
Teknium
b1db37d2b9 fix(compat): carry only the turn helpers pinned catalog plugins import, until v0.27.0
Some checks failed
Skills Index Freshness Check / check-freshness (push) Has been cancelled
Skills Index Freshness Check / check-catalog-cors (push) Has been cancelled
auto-fix lint issues & formatting / Generate eslint --fix patch (push) Has been cancelled
auto-fix lint issues & formatting / Apply patch (push) Has been cancelled
Deploy Site / deploy-vercel (push) Has been cancelled
Deploy Site / deploy-docs (push) Has been cancelled
Review follow-up. The compat layer now keeps exactly the old imports the
catalog's OpenViking 2.1.2 and Honcho 1.2.0 pins make at load time, and
says so:

- agent.context_compressor_retry is no longer aliased (no catalog plugin
  imports it), and agent.skill_commands re-exports only
  extract_user_instruction_from_skill_message (neither pin imports
  register_auto_load_scaffold).
- moves.py admits a folded module only when a catalog-pinned plugin
  imports it.
- plugins/AGENTS.md and the plugin guide record the exception: which
  names, where they live now, and that they follow the hermes_state
  stand-in's window (removed no earlier than v0.27.0).
2026-11-18 11:31:39 -08:00
Teknium
5d88f6eaad docs(skills): address review: case-safe patterns, newest log hits, escaped table pipe 2026-11-18 09:36:27 -08:00
Teknium
928c718089 docs(website): file-tool instructions in developer guide; regenerate skill pages 2026-11-18 09:36:27 -08:00
Teknium
fc085c44a3 fix(cache): a retried keep-alive miss waits a full window; report summarized results left without an archive
Greptile on 2a51baab:
- An automatic-cache miss reports no write, so the clock did not move and the retry was scheduled off the
  old deadline (about 8 min after the miss on a 30m window, at once near its end). The retry now waits a
  full window from the miss it follows.
- A summarized tool result whose archive write fails (disk full, read-only home) is now logged at WARNING;
  the compaction still commits (refusing would re-pay the summary every turn while the disk stays full).
  Docs say where the bytes remain (summary + state.db).
- The claim-race barrier waits up to 5 s (tests/AGENTS.md wall-clock floor).
2026-11-18 03:40:34 -08:00
Teknium
0cf82ca702 fix(cache): review round 2 — managed local unload expiry, malformed route store, CLI dead hook, scan/release handoff
alt-glitch's review of 893b54f9:
- Hermes' own managed llama-server unloads an idle model (and its prompt cache) after 15 min (+ two
  120 s sweeps): its clock now ends there, so /context and the cold offload see it; a user's own local
  server still never expires on the clock. The guarantee is capped at the estimated end.
- A malformed entry in cache/prompt_cache_routes.json (non-numeric timestamp, counters or gap lists) is
  dropped instead of raising into agent build and usage accounting.
- The route key keeps the port (normalized base URL): two local servers on one host learn apart.
- The classic CLI's idle cache hook never ran: `hermes chat --cli` drives a GatewayAgent and the gateway
  owns the warmer and its housekeeping. The hook, its test and its helper are removed (the two CLI
  files are main's again).
- A due-scan's claimed action is handed to a release job that registered for the same chat while the
  scan ran, instead of being dropped.
- Keep-alive log lines carry the chat's session tag (set on the timer thread).
- Tests that could not fail now can: the claim race pauses after the decision, the late-miss branch with
  no successor, and the compaction hand-off through carry_compression_automation (each red when its fix
  is reverted).
- Follow-ups folded in: a finite admission arms no idle keep-alive; delegate cost folding takes the
  session-totals lock; the docs say the gateway offload lands on its 5-minute tick.
2026-11-18 03:40:34 -08:00
Teknium
df702cab6b feat(cache): backtest rulings — upstream-aware misses, 5m->1h tier at the first pause, learning-store guards
Teknium approved every improvement the usage backtest found:

- A keep-alive miss served by another upstream than the reply that cached the prefix (Nous serves one
  Claude model from chatcmpl-* and gen-* upstreams; 70 switches broke a warm cache in the window), or
  one that still read the stable system prefix, is routing, not lifetime. Real misses end warming only
  on the second in a row (three misses of any kind end it too). The upstream key is data
  (prompt_cache_clock.response_upstream: a gateway's upstream field, else the response id family),
  stored on the clock event; a retried miss's rewrite is not charged to the money limit.
- cache_ttl auto: a person's chat starts on 5m and asks for 1h from the first message after an idle gap
  past five minutes, for the rest of the session (kept per session id, carried to the compaction child,
  re-derived from a stored clock that asked for 1h). The upgrade fires only when the clock holds no
  guarantee and the last cache touch is over 300 s old, so markers never change on a warm prefix. No
  idle keep-alives before the upgrade. /context names the pending tier. Explicit pins and machine
  sessions unchanged. Wire snapshot regenerated: fresh cli agents now send 5m markers.
- Route store: a downgrade needs samples from two different sessions, an upstream switch is never a
  sample, and a learned lifetime never undercuts the longest hit ever seen (kept outside the trimmed
  recent gaps).

Tests pinning the single-miss stop and the 1h start are rewritten to the new ruling (assertions only).
2026-11-18 03:40:34 -08:00
Teknium
6feb69b405 fix(gateway): shutdown drain is a module function, so partial runners keep stopping
Runner doubles built on GatewayShutdownMixin without the watcher mixin raised on the method
call; the drain reads only the runner's own pending-release map.
2026-11-18 03:40:34 -08:00
Teknium
58d6946da5 refactor(caching): prompt_cache_lifecycle becomes a package
agent/prompt_cache_lifecycle.py (1,200 lines) splits along its topics, per root AGENTS.md
§ Packages and Python shape: replay.py (which requests replay, with which output cap, through
which client), economics.py (a keep-alive's cost against the rewrite it prevents), edge.py (the
cache-edge gates claim_edge asks), warmer.py (PromptCacheWarmer and the agent-facing seams).
__init__ is the facade (__all__, no behaviour); topic modules import one another, never the
facade. Callers keep importing the public names from agent.prompt_cache_lifecycle; tests mirror
the folder under tests/agent/prompt_cache_lifecycle/ and patch where each name is looked up.

Co-authored-by: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com>
2026-11-18 03:40:34 -08:00
Teknium
94e0252d2c docs(caching): claim_edge, package layout, 24h/local-endpoint rule, migration outcome, sandboxed offload caveat
Co-authored-by: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com>
2026-11-18 03:40:34 -08:00
Teknium
3fd2797a53 fix(caching): a 24h-retention request and a local endpoint are never cold-pruned on the clock
After the API-spec refactor, classify_route/_rule_openai_spec stopped reading the request's
prompt_cache_retention, so estimated_until equalled the 30-minute warming deadline on every
OpenAI-spec route. prompt_cache_is_cold() then turned True at 31 minutes, and turn-start prune,
owner offload and route-change offload rewrote history on routes whose cache was still warm:
api.meta.ai and Bedrock Mantle GPT-5.x/4.1 (Hermes asks those for 24h retention), and local
llama.cpp / vLLM / Ollama boxes, which evict on memory pressure, not on a clock. Each needless
rewrite costs a full prefix re-process.

Only the expiry estimate changes (_estimated_end). The 30m stays the guarantee and warming
deadline for every OpenAI-spec route, a 24h request included (warm at 25 min, first miss
disables). A request that asked for 24h is estimated to live read + 24h, and the estimate
survives a read renewal. An is_local_endpoint host has no estimated end (estimated_until None
with a known confidence), so it is never certainly cold on the clock, while route_changed and
compaction still invalidate the window and offload. chatgpt.com Codex gets no retention from
Hermes, so its 30m stands.

Co-authored-by: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com>
2026-11-18 03:40:34 -08:00
Teknium
579e25e022 feat(caching): learn how each route really caches, across sessions, from usage already received
agent/prompt_cache_routes.py: a per-profile store (<HERMES_HOME>/cache/prompt_cache_routes.json, atomic,
<= 500 routes, 7-day expiry) keyed by provider, host, model and marker use, fed by the clock from every
folded response (normal replies and keep-alives; no probes). After two consistent samples: never reads
back -> no keep-alives and no markers; re-writes the prefix on every hit -> no keep-alives; early misses
-> keep-alives on the learned lifetime (never past the tier) or none under a minute; an automatic cache
that dies early while the explicit one reads -> markers. /context shows 'Learned: <rule>.'
2026-11-18 03:40:34 -08:00
Teknium
8116fa3e90 feat(caching): Nous models get cache markers when the catalog prices a cache write; 1h writes billed at the catalog rate
Nous Portal's /v1/models lists input_cache_write for every model that takes explicit cache_control
(Claude, Qwen 3.7/4, Gemini, GPT-6, ...). The nous profile declares prompt_cache_markers_from_catalog,
so the marker policy reads that rate: priced -> markers at the tier asked (Anthropic spec, declared),
unpriced -> no markers (OpenAI spec, 30m). Measured on qwen/qwen3.7-max: without markers its automatic
cache missed at 4 min; with a 1h marker it still hit after 13 idle minutes, the write billed at 1.25x.
Pricing now takes a catalog's input_cache_write_1h (Claude: 2x) or its single write rate for 1h writes
instead of a fixed 2x.
2026-11-18 03:40:34 -08:00
Teknium
3a4fe9c53c feat(caching): cache rules follow the API spec; first keep-alive miss ends warming for the session; keep warming while a tool runs
Teknium's rulings on PR #156455:
1. A request with cache_control markers is Anthropic spec on any wire or gateway: the 5m/1h it asks
   for is declared and trusted (route ceilings still clamp); 'gateway_1h_untrusted' is gone. Every
   unmarked request is OpenAI spec (30m, renewed by a read), Nous non-Claude models included.
2. The first keep-alive that misses disables warming for the rest of the session on that route (new
   user messages and compactions do not re-arm it; a model/provider switch or a fresh session does).
   The compact/offload fallthrough still runs; /context appends 'Keep-alives: off (one missed).'
3. While a tool call executes, keep-alives continue until it returns, uncounted against the idle
   budget of 3 and bounded only by one rewrite's cost for that tool wait.
2026-11-18 03:40:34 -08:00
Teknium
b83fa4ace9 fix(caching): bound every replay per client, keep the budget per user turn, offload on a mid-turn fallback
- A keep-alive only goes through a client that honours its cap: the OpenAI and Anthropic SDKs as
  they are, any other client through effective_output_cap. Native Gemini lifts a thinking request
  to 65,535 tokens, so it is not warmed; the long-decode extra_body.max_output_tokens is dropped
  from the replay. ACP / unknown clients are not warmed.
- The budget is one _Budget per user turn that every run shares: each keep-alive is reserved at
  admission and reconciled with its billed cost even if its run was replaced, and an ended budget is
  carried to the turn's final prompt so a spent tool run still compacts or offloads.
- route_change_offload runs before every request assembly, so a mid-turn fallback restart offloads
  old tool output before the first request on the new route.
2026-11-18 03:40:34 -08:00
Teknium
3ecdf9db07 docs(caching): spell out the economics bounds (MDX read >= as JSX) 2026-11-18 03:40:34 -08:00
Teknium
5c8e2bfedf feat(caching): apply the lifecycle rulings: no post-compaction warming, 5/6 timing, two cache specs, offload at expiry
- A: no priming and no keep-alives after a cache-edge compaction; the next user message starts the
  budget. The budget is keyed on the user message, so tool rounds inside one turn share 3 keep-alives.
- B: a missed keep-alive still stops warming, and now ends the budget so step 2 (compact) or step 3
  (expire + offload) is decided at once.
- C: no $0.05 floor; a keep-alive is sent when its read is cheaper than the rewrite, within one
  rewrite per budget, with known prices and a prefix of at least 1,024 tokens.
- D: keep-alives fire at 5/6 of the TTL (250 s / 25 min / 50 min), >= 10 s margin; compaction decides
  at the same moment.
- E: compaction no longer requires a still-warm cache (the summary is a fresh aux request).
- F: an idle chat past its window is offloaded by its owner (CLI tick, TUI ticker, gateway watcher)
  and on release, not only on return.
- G: two specs: cache_control markers (Anthropic, 5m/1h) or OpenAI-spec automatic caching for every
  other model, declared 30 min renewed by a read; OpenAI-spec routes get the full loop, replayed with
  the smallest accepted output cap (16 for GPT-5/o-series).
- H2: a route switch (/model, fallback) reads as cold, so the first request on the new route offloads.

Removed tests pinning ruled-out behaviour: priming (test_cli_cache_expiry_prime.py, the priming and
prime-billing lifecycle tests, the TUI no-prime test), the $0.05 floor, 90% timing, the still-warm
gate (TUI window-closed test, already_cold), OpenAI pre-5.6 assumed / implicit unknown clock tests.
2026-11-18 03:40:34 -08:00
Teknium
bf6a59f336 feat(caching): Nous Portal gets the full prompt-cache lifecycle (1h declared)
The Portal now keeps Claude's 1h tier: a raw probe read a 13.2k-token 1h prefix back from
cache after 7 and after 25 idle minutes, with its write billed at 2x (the 5m control rewrote).
The Nous profile drops its 5m ceiling and declares prompt_cache_max_ttl="1h" instead, so the
wire asks for 1h under cache_ttl auto and the clock declares it (route_ceiling_1h): human chats
on Nous now warm x3 on the 1h schedule, compact at the budget's end/release, and offload on a
cold return like Anthropic and OpenRouter. Without a declared ceiling a 1h ask on an
Anthropic-wire gateway stays unproven (gateway_1h_untrusted), which would leave Nous with no
lifecycle at all.

route_ttl_ceilings stays: tests that exercised the clamp now set {nous: 5m} in their temp config.
Docs drop every 'Nous is 5m' sentence; the Nous wire snapshot gains ttl 1h on its markers.
2026-11-18 03:40:34 -08:00
Teknium
bb377e8e98 refactor(caching): the archive writer lives in tool_result_storage, the TUI ticker in session_reaper
Main's root AGENTS.md adds no new flat <stem>_<topic> siblings unless an area AGENTS.md prescribes
one. The compaction/prune archive helpers (archive_pruned_originals, archive_compaction_drops,
pointer parsing, the summary's archive list) move into tools/tool_result_storage.py, which already
owns spilled and pruned tool-output files and their sweeper; the TUI cache-expiry ticker and
release-time compaction move into tui_gateway/session_reaper.py, which owns idle/LRU reaping and
already calls them. No shims; imports, docs and tests follow.
2026-11-18 03:40:34 -08:00
Teknium
57df5a2bd9 fix(caching): a release ends the warm budget, compaction archives once, and failed compactions buy nothing
Review fixes for the prompt-cache lifecycle (Greptile on 8f99ba52):

- Compact at release: a warm budget ends at whichever comes first, its 3 keep-alives or the owner
  releasing the agent. On a 1h route the gateway evicts an idle agent after an hour, before 3
  keep-alives at ~54 min run out, so step 2 never fired. The gateway idle/LRU evictions and the TUI
  idle/LRU reapers now ask claim_compaction_at_release (same gates, decided at the release, warming
  cancelled) and compact first through the same claim-gated job, then release. No keep-alive after.
- Planning is write-free: _plan_compaction_window no longer archives. compress() archives once after
  admission; a prepared pass archives its own window after taking its slot and the splice skips those
  rows, so no result is written twice and refused passes write nothing.
- The committed summary lists every archived file the generated text omits ("Archived tool output"),
  so the model keeps the path and the retention sweep keeps the file.
- A queued TUI cache-expiry job whose chat closed meanwhile is refused at the busy claim (_closing).
- A no-op, aborted or refused compaction no longer primes or grants a fresh budget (TUI and CLI).
- Keep-alive and priming writes are priced at the tier their request declared (1h = 2x input), as
  loop responses are.
- Docs: keep-alives (and so step 2) are Claude-only; OpenAI routes are never warmed.
- The reset race test proves the reset reached the contested lock with a trace barrier (2 s bound).
2026-11-18 03:40:34 -08:00
Teknium
bda0543e85 docs(caching): say which surfaces prime the compacted chat 2026-11-18 03:40:34 -08:00
Teknium
16099a4dbb feat(caching): one prompt-cache lifecycle controller: warm x3, compact, warm x3, expire
agent/prompt_cache_lifecycle.py owns the per-chat decision at each pre-expiry point,
replacing agent/prompt_cache_warmer.py's scheduler and agent/cache_expiry_compaction.py's
decision (both deleted). A real request opens a budget of 3 keep-alives; chats a person
types into keep warming while idle, machine sessions (subagents, side agents, forks,
machine-paced sources) only while a tool runs. A spent budget on a proven/declared
window >= 30m with context >= half the compaction threshold and growth since the last
compaction is claimed once by the surface owner (CLI idle tick, TUI ticker, gateway
watcher); CLI and TUI then prime the compacted chat for one fresh budget. Any miss ends
warming; an unknown clock arms nothing. Every #122094 guard (witness, single admission
under lock, reset epoch, aux hooks, unknown-price refusal, spend cap, $0.05 floor) and
every #156253 owner guard (claim_gate, profile scope, bounded jobs, detached chats) is
kept. The one-hour age cap is replaced by the budget.
2026-11-18 03:40:34 -08:00
Teknium
d23dc1a507 fix(compression): cache-expiry compaction fires once per window, at the window
Live Nous run (route ceiling lifted to 1h): the idle prefilter keyed on the
response-time activity stamp blocked the fire point, and an attempt that
committed nothing (summary would grow) stayed due every tick. The prefilter
now sits at 0.75 of the window and a claimed window is latched. Docs.
2026-11-18 03:40:34 -08:00
100yenadmin
fd55a0be49 fix(caching): a routed background-review or /btw fork never keeps the 1h tier
The fork inherits the parent's interactive platform, so under the auto default
it resolved to 1h. Routed to a different model its cache is cold and it calls
back-to-back until done, so it is clamped to 5m like a delegated child (#104168).
Docs say the side-agent rule applies under auto.
2026-11-18 03:40:34 -08:00
100yenadmin
79eaa2a822 fix(caching): side agents stay on 5m under auto; config failure follows the auto default
A side agent (CLI/TUI /background, /btw, /refine) runs one finite task under its
parent's cli/tui label, so `auto` keeps it on the 5m tier. An unreadable config
now resolves to the shipped `auto` default like every other section, and the
template's schema stamp moves to 53 with the new migration.
2026-11-18 03:40:34 -08:00
100yenadmin
8ef538374a feat(caching): prompt_caching.cache_ttl defaults to auto
Sessions a person types into (CLI, TUI, Desktop, messaging) now request the 1h
Anthropic cache tier by default and machine-paced ones stay on 5m, using the
existing `auto` policy. Migration 53 drops the old seeded `cache_ttl: "5m"` so
installs seeded from the template follow the new default; 1h, auto and off are
kept. The API server (`api_server`) and the skill curator (`curator`) platform
labels join the machine-paced set, matching the documented auto policy.
2026-11-18 03:40:34 -08:00
Teknium
fe55d8f341 feat(agent): the cache warmer reads the shared prompt-cache clock
The warmer computed its own entry lifetime (the configured tier on native
Anthropic, 5 min on any gateway) and its own send-time anchor. Both now come
from agent/prompt_cache_clock.py: a refresh is due shortly before the clock's
guaranteed-warm deadline, and a window the clock does not call certainly warm
(unknown, assumed gateway 1h, cache moved, already past) arms nothing. Each
refresh is folded back into the clock (record_cache_response gains an
attempt= override so a keep-alive never clobbers the loop's stamped attempt),
its token row carries the clock column, and the next refresh is scheduled from
the deadline the refresh bought. warm_ttl_seconds, the warmer-local
TTL_SECONDS and _last_api_attempt_sent_at are gone: one lifetime source.
2026-11-18 03:40:34 -08:00
Teknium
f13b4e9751 fix(agent): keep-alives price the uncached tail and book usage on the session that sent them
A refresh re-sends the tail past the last cache marker at the full input rate, but the savings
check and the remaining-budget reservation priced the whole prompt as a cache read, so a request
with a small cached prefix could be approved for refreshes costing more than the miss. The prefix
(cache read + write of the arming response) and the tail (its uncached input) are now priced
separately, and each refresh is reserved at no less than what the last one was billed.

A refresh in flight when compression rotated agent.session_id was booked on the new session. The
run now snapshots its session, source and billing route when it arms and books there; the new
session's in-memory totals are left alone.
2026-11-18 03:40:34 -08:00
Teknium
6897eb6b42 fix(agent): a cache keep-alive that misses stops warming; the cap counts what refreshes were billed
A refresh whose usage shows no cache read or any cache write (the entry was already gone, or the
replay re-wrote it) used to be booked and then re-armed as if it were a cheap read, so a run could
keep paying write prices every TTL. Now the run stops on that refresh and says why.

The spend cap compared (n+1) * an assumed read cost against the miss. It now sums the estimated
billed cost of the refreshes actually sent (estimate_usage_cost on each refresh's own usage) and
stops before one more refresh would pass the miss; a refresh with unknown cost also stops.

Every stop reason is logged at INFO, once per change of reason (routine turn-end/new-request
stops of a run that sent nothing stay at DEBUG). warm_ttl_seconds is documented as the warmer's
only lifetime source so the shared cache clock (#156101) replaces it in one place.
2026-11-18 03:40:34 -08:00
Teknium
d8315dec32 feat(agent): cache warming is always on during long tool runs; idle mode and config knob removed
Streaming warming (a keep-alive while a tool call is still running) has no
real tradeoff: the next request is certain, one keep-alive is a cache read
(~1/12 of the write it prevents), and the economics gate already refuses
cheap, unpriced and subscription-included routes. So it is always on and
prompt_caching.cache_warming is gone: warming follows prompt caching itself
(no cache_control markers -> nothing to warm).

Idle warming (keep-alives after the turn settled, betting p=0.15 that the
user replies within the TTL) was speculative spend, so the mode is deleted
rather than kept behind a knob: every turn exit now cancels the warmer.

One guard is new: a run's refreshes together may never cost more than the
single cache miss they prevent. On a 5-minute gateway route a one-hour tool
call would otherwise pay ~13 reads (> one 1.25x write); the run now stops
at floor(miss / warm) refreshes. Cache-parity forks opt out through
_skip_prompt_cache_warming instead of the removed mode.
2026-11-18 03:40:34 -08:00
teknium1
d838613c5f feat(agent): opt-in prompt-cache warming keeps the prefix alive through long tool runs (port of earendil-works/pi#9668)
With prompt_caching.cache_warming: "streaming", a tool round that outlives the cache
lifetime no longer turns the next request into a full-price cache write: the agent replays
the last request with max_tokens 1 at 90% of the lifetime, and one cache read keeps the
whole prefix alive.

Warms Claude on the Anthropic Messages wire AND on Chat Completions gateways (Nous Portal,
OpenRouter), where most Claude traffic runs. Off native Anthropic the refresh is timed on
the 5-minute schedule whatever cache_ttl asks for: a live probe on Nous Portal showed a
ttl "1h" entry fully re-written after 7 minutes, and the request then pays the full write.
2026-11-18 03:40:34 -08:00
Teknium
f5b3c3a2c6 fix(prune): never prune on an assumed cache window; correct prune config example
A pre-clock session's window is rebuilt from today's TTL and route (confidence
assumed), so a session cached for 1h and resumed after 10 min under a 5m setting
read cold and was pruned while warm. The prune now acts only on a proven or
declared window; /context keeps the estimate.

The configuration.md example enabled the warm prune (64000/1000/64000); it now
shows the defaults (0/8000/4096). The parallel-step wording now says what the
code does: the protected tail never starts mid-step, results are chosen one by one.
2026-11-18 03:40:34 -08:00
Teknium
02aa62d326 fix(compression): read "cache already cold" from the shared prompt-cache clock
The cold-cache prune kept its own clock: last-response wall time plus the
configured TTL. That called a cache cold that may still be warm (OpenAI
retention outlives a minimum, an Anthropic-wire gateway asked for 1h) and
knew nothing about route switches or a rewrite since the last response.

Both call sites now ask cache_certainly_cold(cache_window(agent)): cold
only past the window's estimated end; an unknown or maybe-warm window
stands down. A committed prune archives rows, which moves the session's
context generation, so the clock reads unknown until a fresh response
re-anchors it. The private TTL logic, the per-response wall stamp and
the store's latest_assistant_timestamp reader go: the clock restores a
resumed session's window itself.
2026-11-18 03:40:34 -08:00
Teknium
11c2db7ea1 fix(compression): cold-cache prune only by default; fail-closed guards
Review round on #156081 (100yenadmin's review + /review):

- Sandbox guard decides on the terminal backend: archive-and-prune only on
  `local` outside a hosted scope; every other backend (docker, modal, ssh,
  daytona, vercel_sandbox, plugin or unknown names) and a refusal scope keep
  the result whole. The old path-translation check never fired because
  cache/pruned is mounted nowhere. The mocked test is replaced by
  100yenadmin's real-resolver test (cherry-picked) plus unknown backends.
- Warm proactive pruning is back to main's defaults (0 / 8000 / 4096: off).
  The cold path (provider cache already expired) needs no trigger and stays
  on by default with its 16K reclaim gate; a warm gate only lowers it when
  the warm prune is switched on. The two skill-safety fixtures and the
  other prune test files are byte-identical to main again.
- The running-turn guard fails closed: a turn index that names no user row
  (-1 after a compaction, or any other row) skips the round instead of
  falling back to the count-only tail.
- The protected-tail boundary is aligned with _align_boundary_backward, so
  one assistant step's parallel results are pruned all-or-none.
- read_file pages every cache/pruned archive (.json and .txt) and wraps a
  line longer than the per-line cap, so a one-line 300,000-char archive
  reads back completely.
- Archive writes are read back and compared byte-for-byte, not size-checked.
- Docs: what is on by default, the backend rule, that a referenced archive
  stays until its session is deleted (sessions.auto_prune is off by
  default), and that the sweep keeps everything past 20,000 referencing rows.
2026-11-18 03:40:34 -08:00
Teknium
5ffd3e5830 fix(compression): address review on the prune archive
- Plugin engines: the call site's store-row gate is the built-in compressor's
  own (it opts in via prune_needs_session_store), so a plugin engine that
  implements prune_tool_results_only without the built-in's private
  _session_db/_session_id is called again.
- Archives never overwrite: resumed histories can repeat a tool_call_id, so
  the name gets a numeric suffix until free and the file is created
  exclusively.
- Sandboxed backends: the prune holds no environment to sync and probe a
  remote copy, so a stub could name a file the model cannot open yet. On those
  backends the result is kept whole (no information loss) and cache/pruned is
  not mounted.
- Full in-place compaction clears the cold-prune credit with the runway, so a
  stale credit cannot lower the next warm gate.
2026-11-18 03:40:34 -08:00
Teknium
ebbaa5288e fix(compression): archive every pruned tool result to disk; never prune the running turn
Salvage of #136488 (kshitijk4poor), review findings from 100yenadmin and kvnloo.

- No information loss: before the proactive prune shortens a tool result, its
  full original is written byte-verified to
  $HERMES_HOME/cache/pruned/<session>_<UTC>_<tool>_<id>.<json|txt> and the stub
  ends with " — full result: <path>", so read_file returns the exact output.
  A result whose write fails stays whole and the reclaim gate is re-checked on
  what is left (no commit -> the written files are removed).
- This also closes kvnloo's unflushed-original case without deferring the
  prune: the original no longer depends on the store having seen the row.
- The running turn is never shortened: the post-tool site passes the turn's
  user-row index (turn_start), and every row from it on is kept whole. Before,
  the count-only tail let a long tool loop stub its own earlier calls.
- One sweeper: the spillover reference/retention machinery now covers
  cache/pruned too (archive_refs_in_text / referenced_archive_refs; session
  delete retires both). Pruned files follow sessions.retention_days and are
  never deleted while state.db references them. cache/pruned is mounted for
  sandboxed backends like cache/spillover, and the stub names the path the
  backend sees.
- Cold-cache reading isolated in turn_proactive_prune.prompt_cache_is_cold so
  the shared cache clock can replace it in one line.
- Two skill-safety fixtures pin the old 4096 reclaim gate (the shipped 64K
  default made their ~7K-token transcripts no-ops).
2026-11-18 03:40:34 -08:00
kshitijk4poor
6fa82ec035 fix(compression): close review gaps in the proactive prune
Review follow-ups for the default-on prune and the cold-cache prune.

- Turn start: skip the cold prune when this turn's user row (or anything
  after it) is already durable. TUI/Desktop write the row at submit; a
  prefix-only archive_and_compact would clone it under a new id while the
  live dict kept the old _row_id, so later api_content / multimodal
  stamps would miss it.
- Engine invariant, not only the call site: a store with no bound session
  row cannot archive the originals, so prune_tool_results_only refuses
  instead of returning stubs the store never saw. The call-site helper
  checks the same.
- The cold-prune credit is persisted in the same model_config patch as the
  regrowth runway, restored on bind, cleared on a runtime change and kept
  by the failed-attempt restore. Agents rebuilt per request (api_server)
  or on resume no longer lose it.
- TUI/Desktop live config reload now updates
  compression.checkpoint_required, so turning it on mid-session stops the
  prune (which bypasses the checkpoint hook) without a rebuild.
- Docs: a committed prune keeps only the one-line notes in the live
  transcript, so a later compaction summary cannot contain details the
  prune removed; originals stay archived and searchable.
2026-11-18 03:40:34 -08:00
kshitijk4poor
4845516813 perf(compression): prune on an already-expired prompt cache too
The proactive prune now knows when the provider prompt cache has already
expired. In that case a rewrite breaks nothing that is still paid for, so
the prune can run more often and at a smaller size.

- prompt_caching.provider_cache_expired(): checks prompt caching is on and
  more than the route's effective TTL (5m or 1h, plus 30s slack) has passed
  since the last provider response. turn_usage stamps that time on every
  response; a resumed session reads the newest assistant row timestamp.
- prune_tool_results_only(cold_cache=True): commits from 16K reclaimable
  tokens (or the configured gate if lower). It neither checks nor moves the
  64K regrowth runway, and what it frees is credited against the next warm
  64K gate. Warm behaviour is unchanged.
- New turn_proactive_prune module: shared call-site helper (same gates as
  before: a session store, no checkpoint_required) plus a turn-start cold
  prune. The turn-start prune runs on the history before this turn's
  unpersisted user row, so the turn-start persist and api_content stamp
  are untouched.
- Plugin engines whose prune_tool_results_only lacks cold_cache keep their
  signature.

Replay of 80 real sessions at 1M, compared with the warm-only prune:
-11.5% / -9.5% with 5m caching, -2.2% / -1.9% with 1h caching, and no
session worse in any of the four cells. Most cache expiries come right
after a user message (209 of 343), which is why the turn-start site is
needed.
2026-11-18 03:40:34 -08:00
kshitijk4poor
31c8fe2040 perf(compression): turn the proactive tool-result prune on by default
On large-window models the ratio threshold (50% of the window) rarely
fires, so old terminal dumps, file reads and web extracts are re-sent
on every call. The deterministic, no-LLM proactive prune already
handles this but shipped off (0 / 8000 / 4096).

New defaults:
  proactive_prune_tokens             0    -> 64000
  proactive_prune_min_result_chars   8000 -> 1000
  proactive_prune_min_reclaim_tokens 4096 -> 64000

How they were chosen: a replay of 80 real never-compacted sessions
(40 dev / 40 holdout, ~6,100 main-model calls on dev) through the real
ContextCompressor with the summary call stubbed, priced with prompt
caching (cached prefix 0.1x, new tokens 1.25x, any history rewrite
re-billed in full). 18 settings were swept on dev at 1M; the best was
confirmed on holdout. A higher min_reclaim beat a lower one at every
trigger size, because each committed prune breaks the prompt cache.

Modeled input cost, default (prune off) vs new defaults:
  window   dev      holdout
  128K     -3.8%    -6.8%
  200K     -0.7%    -3.2%
  272K     -8.0%    -6.9%
  400K     -23.7%   -26.2%
  1M       -24.1%   -27.0%
No errors and no new context overflows in any run. With 1h-TTL cache
pricing (2.0x writes) the 1M saving is -20.3% dev / -23.5% holdout.

Trade-off: roughly half of old tool-output text stays verbatim (about
54% at 1M, against 100% today); demoted results keep a one-line summary
and stay recoverable through session_search. Answer quality was not
measured.

Also: a YAML boolean is never a token count. `proactive_prune_tokens:
false` now turns the prune off and `true` keeps the default, both at
agent build and on TUI/desktop live config reload. Before, reload turned
`true` into a 1-token trigger that pruned every turn.

Tests that exercise prune mechanics on ~5-7K-token fixtures now pin
min_reclaim=4096, since the 64K default would make them no-ops.
2026-11-18 03:40:34 -08:00
Vortex Openclaw
444a6b8644 fix(models): require verified Codex discovery for GPT-6.2 choices 2026-11-17 21:42:04 -06:00
Vortex Openclaw
1a83150682 fix(models): honor GPT-6.2 Fast rates and Codex eligibility 2026-11-17 21:42:04 -06:00
Vortex Openclaw
a312aea1ce fix(models): keep the Codex fallback available on free plans
Credit BearHuddleston for identifying the plan eligibility regression and suggesting the catalog reorder.
2026-11-17 21:42:04 -06:00
Vortex Openclaw
f19ef0b58b docs: clarify GPT-6.2 Codex app-server compatibility 2026-11-17 21:42:04 -06:00
Vortex Openclaw
786314cef1 feat(models): support GPT-6.2 Astra and Sol 2026-11-17 21:42:04 -06:00