Skip to content

feat(segments): observation and findings logs of segments - #170

Open
karauda wants to merge 21 commits into
mainfrom
feat/s29-segment-logs
Open

karauda wants to merge 21 commits into
mainfrom
feat/s29-segment-logs

Conversation

@karauda

@karauda karauda commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

What changed, and why

observe import --log <dir> and supervise --findings <dir> use segmented logs like the evidence trail. Each log has segments.json, live.jsonl, sealed segment-NNNNNNNN.jsonl files and segments.lock. The guardana.control.segments manifest is 0.2 and requires log_id and kind (observations or findings).

Segments seal past 64 MiB. Appends beyond 1 GiB of unpruned segments are refused without pruning. Prune explicitly with guardana-gateway prune, as for trails.

Import and supervise reject directories containing their legacy files (observations.jsonl or findings.jsonl), exit 2 and name the new directory option. The CLI only reads or exports legacy files. Each log is bound to its original tenant and project. A tenant or project mismatch exits 2. A mismatched record is damage. Missing log directories are created with mode 0700 after parent owner and sticky-bit checks.

Both exports use format 0.2, with pruned_before in the header and cursors bound to a segment and log ID. Exports reject pruned-segment cursors as expired and other logs' cursors as belonging to another file. An export stops before a record from another tenant or project, exits 2 and omits the trailer.

  • After pruning, coverage reports the source's log as incomplete and exits 1.
  • After pruning, supervise holds the source in doubt, leaves its two dependent rules unchecked and exits 1.
  • Notify saves the last sealed segment it read through in log-read-through. It exits 1 if a later segment was pruned and rejects a mark past the log.
  • React keeps no state and exits 1 whenever its log has pruned segments.

Readers reject logs of the wrong kind, directories with segment files no manifest names, including beside a legacy file, and directories holding both forms. observe export judges a file named by its path by its directory: a segment file is refused, naming the log's directory to export, as trail export does. Notify refuses a single-file log under a state that marks a log of segments as another log. trail and trail export reject both kinds. trail segments and prune accept both.

Invariant or record

This implements ADR-0092 and builds on ADR-0091, which moved the record log port to its consumers. The accepted ADR-0092 now specifies manifest kind, incomplete-log and exit rules per reader, and export binding. Its backup and restore work follows in the next change.

Readers report gaps after pruning and fail closed on damage.

How it was tested

  • Tests failed on the base before fixes in all five rounds. Coverage exited 0 for segments without a manifest. React exited 0 on a pruned log. Notify exited 0 despite unread pruned segments. A findings writer opened an observation log. An export exited 0 on a live segment containing a record from another project. Beside an orphan live.jsonl, a findings reader read only the header and exported a whole, empty log. A trail export wrote a gap for a findings log and exited 1. observe export <log>/live.jsonl exported a segment as a whole single file, without the log's tenant and project binding, and exited 0.
  • Mutation testing ran in all five rounds. Tests caught 33 of 33 mutations in round three, 15 of 15 in round four and 8 of 8 in round five, each run with a filter naming the tests that should kill it. Round four covered each reader's orphan check, notify's mark checks and the default that accepts either kind and its callers.
  • Each round had a code review and a security review. The round-four security re-check found no fail-open behavior in the rules it checked; a narrower re-check of round five runs beside this pull request's CI. Tests reproduced and verified fixes for orphan segments beside a legacy file, a notify mark past its log and trail readers accepting either kind.
  • On macOS, on round four's head after merging main, tests passed in cmd/guardana-control (821) and cmd/guardana-gateway (920). Tests also passed in internal/supervise (479), internal/docscheck (472), internal/coverage (362), internal/ingest/egresslog (218), internal/ingest/otelgenai (187), internal/trailfile (159) and internal/gateway/e2e (132). Other passing packages were internal/observelog (123), internal/segmentlog (101), internal/findinglog (96), internal/notify (74), internal/lineexport (23), examples/refund-supervision (5) and internal/recordlog (5). Round five's changed packages, internal/observelog, internal/notify and cmd/guardana-control, passed again on macOS and on Linux.
  • The vet target, vetting with twoaccounts, macOS and Linux linting, formatting, check-sizes, check-brand and docs-check passed.
  • On Linux, the tests that need the Go toolchain, go.mod or root in the test container cannot run there; they failed or were skipped, and the rest passed. Code inspection showed scenario run --trail rejects both kinds. No command-level test covered it. On the last head, the pre-push checks passed: vet, vetting with twoaccounts, macOS and Linux linting, formatting, check-sizes, check-brand, then docs-check after the last documentation change. The round-five Linux run predates its last two commits, a skip-list line and a message rewording. No race or local quality run. CI's quality run is the gate.

Documentation

Moved the finding record, its log, notify and findings export from docs/reference/supervision.md (at its word budget) to docs/reference/findings.md. Updated links to the moved sections.

Updated observations, coverage, supervision, reaction, CLI, versions (manifest and both exports), egress access log, contracts, status, glossary, privacy, the supervise-and-stop and egress-proxy guides, and the site. Updated links in ADR-0047, the upgrade-from-0.18 guide and the adapters page.

CHANGELOG lists upgrade steps under Changed. Use new, empty --log and --findings directories per project. Use a new --state directory and run notify --init. Move export readers to 0.2. Of the 35 pages docs-impact flags, 18 changed. The other 17 were checked for the changed terms (the two logs, their exports, notify's state) and still hold.

The record log port now lives in internal/recordlog, as ADR-0091
decides: the Log port, its Reader and Stats, the Holding state whose
zero value is unknown, the segment and manifest types, and the port's
refusals. The package imports no file-system package. internal/segmentlog
is the segments kind behind it: Open and Inspect take a recordlog.Config,
refuse the zero kind, and read lines back through the directory handle
the writer holds, failing the log on any mismatch. internal/trailfile
names the kind in one place and reads export, cursors and reindex through
the Reader; an unknown holding state is an error, never free. trail
segments prints from Stats and says unknown where another process cannot
see the writer's bounds. Conformance cases 10 to 13 join the port's suite,
each with its negative control.

Signed-off-by: Konrad Karauda <konrad@karauda.com>
…sees

A segment others may write now fails a read-back in segmentlog and
refuses a repeat in trailfile; both tests kill the mutant that swaps the
checked open for a plain one. The import check drops a case that could
only ever be an import cycle. Reader.Stats says which numbers are the
writer's and unknown to a reader, never a measured zero.

Signed-off-by: Konrad Karauda <konrad@karauda.com>
…ject

An observation log is now a directory of segments under the record log
port, bound to the tenant and project of the descriptor that made it and
named by a random log id in a version 0.2 segments manifest. The single
file observations.jsonl is still read and exported, never written: an
import into its directory is refused, naming --log with a new directory.
The byte bound refuses an append; guardana-gateway prune prunes an
observation log as it prunes a trail.

The observation export is version 0.2 for both forms: its header names
pruned_before, a cursor's segment key folds in the log id, a cursor of a
pruned segment is refused as expired and one of another log as another
file. coverage and supervise refuse a log any of whose segments were
pruned. The live segment is locked with segmentlog.Lock, so a second
writer is refused with the directory's lock file gone.

The findings log is not converted yet.

Signed-off-by: Konrad Karauda <konrad@karauda.com>
…riter's refusal

Signed-off-by: Konrad Karauda <konrad@karauda.com>
Signed-off-by: Konrad Karauda <konrad@karauda.com>

# Conflicts:
#	cmd/guardana-gateway/segments.go
#	internal/recordlog/port.go
#	internal/recordlog/segment.go
#	internal/segmentlog/errors.go
#	internal/segmentlog/port.go
#	internal/segmentlog/port_test.go
#	internal/segmentlog/view.go
#	internal/trailfile/log_holding_test.go
A log opened to prune holds the live file, so a reader that asks only the
live file's lock finds the log held, and the record log refuses a live
file its opener did not lock.

Signed-off-by: Konrad Karauda <konrad@karauda.com>
supervise --findings writes a directory of segments through the record
log port, bound to the supervised run's tenant and project, sealed at
64 MiB and refused past 1 GiB. A log of another project is refused, and
so is a directory holding findings.jsonl, which is still read and
exported but never written. The duplicate index covers the segments not
pruned, and guardana-gateway prune prunes the log.

react, notify and findings export read either form through one reader;
react and notify state how many segments were pruned. notify reads its
records and lines in one read and binds its state to the log id.
findings export moves to 0.2: the header carries pruned_before, cursors
over segments are keyed by segment and log id, and a cursor of a pruned
segment is refused as expired.

Signed-off-by: Konrad Karauda <konrad@karauda.com>
… keep the gates green

A finding or report of another tenant or project is refused, each tested
apart. The notify case moves to the unix test file it needs, scanLog
returns only what its callers use, and three tests are split under the
complexity bound.

Signed-off-by: Konrad Karauda <konrad@karauda.com>
Coverage and supervise read an observation log some of whose segments
were pruned instead of refusing it: coverage names the source's log not
whole and exits 1, supervise leaves the rules that rest on the source's
reports not checked with the count as the reason. A removed descriptor
whose log was pruned is refused, as what the pruned segments held is
unknown.

notify keeps the last sealed segment it read through in its state and
exits 1 when a segment past it was pruned; react, which keeps no state,
exits 1 whenever its log has pruned segments.

The 0.2 manifest carries a required kind, observations or findings, set
when the log is made and checked at every open and read, so a writer or
reader of one kind refuses the other. Both exports stop before a record
of another tenant or project than the log is bound to. A live segment
opened shorter than read is read again, a tail whose live file changed
size since the read is held, and segment files with no manifest are
damage, never a directory with no log. A prune over a torn live segment
names the step that mends it.

Signed-off-by: Konrad Karauda <konrad@karauda.com>
Keeps each function within the complexity bound; the kind test's config cases become their own test.

Signed-off-by: Konrad Karauda <konrad@karauda.com>
Signed-off-by: Konrad Karauda <konrad@karauda.com>
…otify mark ahead of its log

A directory holding the single-file log and a live or sealed segment that
no manifest names was read and exported as the single file alone. ReadDir
and ExportDir of findings, ReadDir of observations, and an export of
observations.jsonl by its path now refuse it as damage; the commands exit 2.

notify accepted a mark above the log's last sealed segment, so a later
prune of segments the state never read counted as read. After the log's
identity is checked, such a state is refused as ahead of its log, naming a
new, empty state directory and init as the step.

Signed-off-by: Konrad Karauda <konrad@karauda.com>
A reader given neither a log id nor a kind read a 0.2 manifest of any
kind, so trail export, trail and a scenario's trail read an observation
or a findings log as a trail. Such a reader now refuses a log a log id or
a kind names as ErrLogKind, unless it sets recordlog.Config.AnyKind, which
a writer and a reader given a log id or a kind are refused. segmentlog.Prune
and the gateway's prune and trail segments set it and take every kind.

Signed-off-by: Konrad Karauda <konrad@karauda.com>
Pages for ADR-0092: the observation log and the findings log are logs of
segments of one tenant and project, pruned by an operator, exported as
format 0.2, and a pruned log is read as not whole. The finding record,
its log, notify and findings export move from supervision.md, which
reached its word budget, to a new reference page, findings.md; links to
the moved sections follow them. ADR-0092 is accepted and names the
manifest's kind.

Signed-off-by: Konrad Karauda <konrad@karauda.com>
…either kind

findings.md, contracts.md and the CHANGELOG say what the last fixes
changed: notify refuses a state ahead of its log, a single file beside
segments no manifest names is damage, and trail and trail export refuse
an observation or findings log as another kind of record.

Signed-off-by: Konrad Karauda <konrad@karauda.com>
The egress access log page said the observation log is rotated by hand;
a new log starts instead.

Signed-off-by: Konrad Karauda <konrad@karauda.com>
observe export of a file named on its own judged its directory only when
the file was called observations.jsonl, so a segment of a log was exported
as a whole single-file log: pruned_before 0, the end reached at that
segment's end, and no tenant or project binding. A file whose directory
holds a log's manifest is now refused as a segment of that log, naming the
directory to give instead, as trail export does; a file beside a segment
no manifest names is damage, whatever its spelling.

An export of a directory holding both a log of segments and the single
file is now damage, as ReadDir and findings export find it.

Signed-off-by: Konrad Karauda <konrad@karauda.com>
Only a log of segments leaves a read-through mark, so a state marked over
one and run over a single-file log was refused as a state ahead of its log,
whose advice set up a new state over the wrong log. It is now refused as
another log.

Signed-off-by: Konrad Karauda <konrad@karauda.com>
Observations.jsonl is another spelling of the single file only on a volume
that folds case; on Linux the test skips, and the gate fails a skip the
list does not name.

Signed-off-by: Konrad Karauda <konrad@karauda.com>
Signed-off-by: Konrad Karauda <konrad@karauda.com>
…ngle file under a marked state is another log

Signed-off-by: Konrad Karauda <konrad@karauda.com>
@karauda
karauda requested a review from a team November 30, 2026 12:14
@karauda
karauda requested a review from a team as a code owner November 30, 2026 12:14
@cloudflare-workers-and-pages

Copy link
Copy Markdown

🚀 Deploying Preview to Cloudflare 🚀

Preview Deployments by commit

Status Deployment URL Commit Updated (UTC) See this deployment's details
  • Build: Failed ❌

View logs ↗
693acd2 2026-11-30T12:15:09.301Z View logs ↗

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant