Watch
0
0
Fork
You've already forked hyperhive
0

hive-agent: keep the last turn's context size in the harness state file and drop the turn sqlite writes

This commit is contained in:
damocles 2026-11-18 02:24:13 +01:00
commit 5e5ff64b3c
3 changed files with 261 additions and 629 deletions

View file

@ -43,32 +43,19 @@ Retention:
### `/harness/hyperhive-turn-stats.sqlite` (per agent)
Per-turn analytics sink. One row per claude turn captures
identity (`model`, `wake_from`, `result_kind`), timing
(`started_at`, `ended_at`, `duration_ms`), cost (input / output /
cache_read / cache_creation token counts), behaviour
(`tool_call_count` + `tool_call_breakdown_json`), and post-turn
snapshot metrics (`open_threads_count`,
`open_reminders_count` — fetched via the same socket the harness
already uses for `GetOpenThreads` + `CountPendingReminders`).
Bin-loop helpers `build_row` + `record` land each row at
`turn_end`; writes are best-effort, a sqlite hiccup logs + lets
the turn loop continue.
The `hive-bash-daemon` (not the harness) writes a sibling
`bash_commands(ts INTEGER, head TEXT)` table in the same
file: one row per executed bash task recording the normalised command head -
The `hive-bash-daemon` writes a `bash_commands(ts INTEGER, head TEXT)`
table in it: one row per executed bash task recording the normalised command head -
the basename of the first real command, looking past `cd repo &&`
prefixes, env-assignments, and prefix-runners like `sudo`/`env`. It
feeds the bash-command counter in the agent's OTEL metrics. Best-effort and created on first write
(`CREATE TABLE IF NOT EXISTS`), so it's absent until a bash
task runs.
turn-stats.sqlite has **no vacuum** — it's one small row per turn
(~hundreds of KB even over months), so pruning it would only lose trend
history for no space gain. The agent has no page that charts it; the
The file has **no vacuum**. Older harnesses also wrote a per-turn `turn_stats`
table and a `sessions` table there; nothing writes them now and nothing in the
harness reads them, but they stay in existing files, where the
[legacy stats viewer](https://forge.constellation.darkest.space/hyperhive/legacy-stats-viewer)
turns the file into the old stats page.
can still turn them into the old stats page.
### `/state/hyperhive-harness.json` (per agent)
@ -77,7 +64,7 @@ Consolidated harness state file written atomically (`.tmp` + rename) by
Shape:
```json
{ "rate_limited": false, "needs_login": false }
{ "rate_limited": false, "needs_login": false, "context_tokens": 120000 }
```
- `rate_limited` — set when the harness detects a 429 from the Claude
@ -86,6 +73,12 @@ Shape:
- `needs_login` — set when a turn hits 401 (expired OAuth credentials);
cleared by `"online"` status (re-auth completed). Drives the
`needs_login` flag alongside the `claude_has_session` check.
- `context_tokens` — the context size the last turn left, which is what warming
the cache costs. The harness overwrites it after every turn and reads it at
boot (`Bus::seed_usage`), so the context gauge, the swarm state and the
autoreset check start from it instead of from nothing. Absent until a turn has
run, so the first boot after an upgrade starts with an empty gauge, as a new
agent does.
The turn loop is the only writer today, but it still goes
read-modify-write under a shared in-process lock and merges into the
@ -235,7 +228,7 @@ Under `/var/lib/hyperhive/agents/<name>/`:
swept — same "audit trail, not cache" treatment as the c0re-side
tables above.
- `hyperhive-turn-stats.sqlite` — per-turn timing stats.
- `hyperhive-turn-stats.sqlite` — the bash command heads the bash daemon records.
- `hyperhive-model` / `hyperhive-effort` — single-line model name and
effort level files, read-only fallbacks.
@ -457,7 +450,7 @@ This is the **only** cross-agent mount. An agent without that permission
sees its own dirs and nothing else.
**`harness` isn't mounted at all.** It holds that agent's own runtime
material - `bash-tasks/`, the turn-stats and event sqlite dbs - and
material - `bash-tasks/`, the sqlite dbs - and
nothing argues for anyone else reading it, let alone writing it.
hive-c0re reads a harness dir **directly on the host** when it wants
those stats, which needs no mount into another container.

View file

@ -140,7 +140,7 @@ check never reveals _which_ token matched, and a receiver reads request metadata
rather than the claims it authenticated with.
If you need per-agent numbers you can act on, take them from the agent's own
turn-stats rather than from a metric label.
harness metrics rather than from a metric label.
### Authenticated ingest

View file

@ -112,7 +112,7 @@ doc for the trait shape.
`HIVE_LABEL` (default `"hive"` for standalone runs; the meta
flake sets it unconditionally for any container-deployed agent;
see `docs/5-project/process/conventions.md::Hive identity` for the env stack),
opens turn-stats sqlite, prepares the on-boot files (see
opens the usage sqlite, prepares the on-boot files (see
[claude-invocation](claude-invocation.md#on-boot-files)),
installs claude plugins, spawns `web_ui::serve` + `vacuum::run`,
and either drops into `serve_loop` directly (`Online`) or parks on