BOHICA-LABS / BOHICA-LABS/vsdd-factory

feat(observability): emit compaction events (context.compaction / context.reanchor) via OTEL into the obs stack

Open
#317 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
2
Forks
1
Avg merge
6h 43m
Merged PRs (30d)
29

Description

## Summary

E-18's compaction hooks (`precompact-flush` PreCompact WASM, `postcompact-reanchor.sh` PostCompact) fire on every context compaction and write **timestamped** local log records — but neither emits anything into the factory's **OTEL/observability** pipeline. So compaction events are invisible in Loki/Prometheus/Grafana: they can't be charted, correlated with the existing token/cost dashboards, or alerted on. This requests emitting a compaction event through the sink that already carries `agent.*` / `pr.*` / `story.*`.

## What exists today

- The dispatcher emits factory events (`agent.start/stop`, `pr.*`, `story.*`) via the OTLP-gRPC + file sinks (`sink-otel-grpc`, `sink-core`).
- `claude-telemetry` wires Claude Code's native OTel (token-usage counters) into the same Loki/Prometheus.
- **No `context.*` event type exists.** `precompact-flush` appends ` / commit` to `.factory/hooks/precompact-flush-log`; `postcompact-reanchor.sh` writes a 6-field timestamped JSONL to `.factory/logs/postcompact-reanchor-.jsonl`. Both are **local files only** — the flush log's only consumer is the prune script.

## Feasibility — this is wireable today

`host::emit_event` is available to WASM hook plugins (HOST_ABI.md §`emit_event`; resolvers are excluded, but hook plugins are not). `precompact-flush` already runs synchronously on every PreCompact and holds the timestamp, cycle/step, and post-commit SHA — it currently declares only `read_file` / `write_file` / `exec_subprocess` capabilities and emits nothing.

## Proposed change

- **`context.compaction`** — emitted by `precompact-flush` (PreCompact) via `host::emit_event`. Fields: `timestamp`, `cycle`, `step`, `sha_b`, and `seconds_since_prev` (computed from the last flush-log line, when present).
- **`context.reanchor`** — emitted by `postcompact-reanchor.sh` (PostCompact) via `bin/emit-event` (silent no-op if the binary is absent, per HOST_ABI).

Result: compaction lands in the obs stack tagged like other factory events — chartable on the existing Grafana boards, correlatable with cost/token panels, and alertable (e.g. a Prometheus alert on compaction-event rate per session).

## Constraints (SOUL.md alignment)

- **Non-blocking, fail-open.** Keep `on_error=continue`; emission must never block, slow, or fail a compaction. A dropped emit is an advisory loss, nothing more.
- **No phone-home.** Emission targets the user's own local collector (`factory-obs up`), same as every other factory event.

## Relationship

- Prerequisite/enabler for the compaction-cadence advisory (sibling issue — link added below) which can then alert directly off the emitted event rate.
- Same pathology as #306 (a backgrounded reviewer thrashing through 5 compactions in ~13 min with no operator-visible signal); emitting the event is what makes that visible in Grafana.

## Environment

- vsdd-factory develop tip (E-18: S-18.04a/05). Sinks: `sink-otel-grpc` + file via `factory-obs` collector. Local telemetry: `.factory/hooks/precompact-flush-log`, `.factory/logs/postcompact-reanchor-.jsonl`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.