Skip to content

armgit / AiSOC

Public Imported from GitHub
0

Open-source AI Security Operations Center: alert fusion, LLM-agent triage, MITRE ATT&CK investigation, and a replayable decision ledger for every agent step. Self-hostable, runs with no API keys, MIT licensed. Ships an MCP server for Claude, Cursor and Continue.

docs(4.3): cold-tier query guide, claim row, and the 4.3 progress entry

Beenu Arora15ca374934b1
diff --git a/DEPTH_PROGRESS.md b/DEPTH_PROGRESS.md
index 2b73a6f8e..27683a06f 100644
--- a/DEPTH_PROGRESS.md
+++ b/DEPTH_PROGRESS.md
@@ -448,7 +448,7 @@ invented fields on the first run of the gate.
hub, and the Data Lake Gen2 listing path has never run against a real
storage account. The claim row is `PARTIAL` for exactly that reason.
- [ ] **4.2** Standard inputs (syslog, OTLP, Kafka, TAXII 2.1)
-- [~] **4.3** Retention the tenant chooses. **Two of three bullets
+- [x] **4.3** Retention the tenant chooses. **All three bullets
closed.** The lake TTL is now a 400-day ceiling rather than a fixed 90
days, in `001_init.sql`, in the tiering DELETE and in a `MODIFY TTL`
migration so an existing volume converges; `MAX_LAKE_DAYS` bounds what a
@@ -460,11 +460,57 @@ invented fields on the first run of the gate.
violations, one per rule) wired into `ci.yml :: python-lint`. 13 new
tests, api suite 4,569 -> 4,582.
- **Open, and not attempted:** the third bullet — a cold-data query through
- `/lake/sql` or a hunt reporting an estimated cost and a progress state
- instead of timing out silently. `/lake/sql`'s `cost` today is a
- rate-limit token price, not a scan estimate, and there is no progress
- state at all.
+ **The third bullet is now closed too.** `/lake/sql`'s `cost` was the
+ rate limiter's token price — a number about how often you may ask, not
+ about how much the asking will read — and there was no progress state
+ at all: a cold query either returned inside the published 30-second
+ bound or raised a bare timeout.
+
+ Every figure in the new estimate is ClickHouse's own: rows and parts
+ from `EXPLAIN ESTIMATE`, the warm/cold split from `system.parts`
+ joined to the storage policy's volumes (a part is cold because the
+ server says it is on the cold volume, not because of its age — those
+ disagree whenever a move is in flight), and progress from
+ `system.processes` keyed on a query id we set. There is deliberately
+ **no invented throughput constant**: a predicted duration needs a
+ bytes-per-second figure and the only honest source is a measurement on
+ the deployment's own hardware, so the routing rule is structural — a
+ query goes to a job when the estimate says it must read the cold
+ volume.
+
+ `estimated_usd` is **null** unless the deployment configures
+ `AISOC_LAKE_COLD_RETRIEVAL_USD_PER_GB`.
+ `docs/decisions/storage-cost-model.json` prices residency, not reads;
+ quoting it for a scan would be the wrong number stated confidently.
+ `null` means "we do not know what this costs" and `0.0` means "this
+ costs nothing", and a test pins that they are never confused.
+
+ Jobs are rows (migration `111`), not an in-process registry: the API
+ runs more than one replica, and that shape has been shipped and
+ regretted three times here. 26 pure tests, 12 live ones against real
+ Postgres, eight new rules in `check_retention_window.py`, and
+ `lake-query-jobs-live.yml`.
+
+ **The test that had to be rewritten, because the first one proved
+ nothing.** The claim race originally gathered five concurrent claims
+ and asserted one winner — and it passed under a SELECT-then-UPDATE
+ implementation as well, measured by subverting the claim and watching
+ it stay green. It is now two explicitly interleaved transactions, and
+ that version goes red when the predicate is removed.
+
+ **Two of the eight new gate rules were wrong in the same direction**
+ and were caught by their own injections: the terminal-state rule
+ matched a status string `list_stuck_jobs` legitimately also uses, and
+ the routing rule matched a response *field name* rather than the
+ branch, so an endpoint that reports `touches_cold` and ignores it
+ passed.
+
+ **Not measured, and why: no ClickHouse was exercised.** There is none
+ in CI and none on the machine this was written on, so `EXPLAIN
+ ESTIMATE`, the `system.parts` join and the `system.processes` read are
+ asserted against ClickHouse's documented shapes with the parsing
+ tested on recorded rows. What is proven live is the job lifecycle,
+ which is where the concurrency defects are.
**Two limits on what is closed**, recorded rather than left to be found:
the lake half is gated statically — no test in CI watches a row survive
@@ -531,6 +577,7 @@ invented fields on the first run of the gate.
| 2026-10-07 | 0.3 | `make up` and `make smoke` (10/10) pass. Injection suite and load-harness baselines committed. `make up-full` deferred (D2) and hosted model rows blocked (D3). Fixing D1 was a precondition for the load-harness baseline. |
| 2026-10-09 | 3.3 | Identity privilege (18 rules) and a per-tenant first-seen store (2) built; 5 rules were never unreachable (gate operator drift, D9); 18 retired with a reason (D10). `MAX_UNREACHABLE` 45 → 2, the two remaining both needing the 3.4 baseline. Two matcher operators three shipped rules already used were implemented. |
| 2026-10-09 | 3.2 | Ordered and unordered sequences in the windowed engine; all four translatable Sigma correlation types compile, seven refusal reasons recorded. No upstream correlation rule exists in this tree to import (D8), so the corpus is first-party and labelled as such. |
+| 2026-10-11 | 4.3 | Third bullet closed. Reproduced: `check_retention_window.py` with the new rules reported no cold-query estimator, no job surface and no job table on the pre-fix tree. Built `lake_cold_query.py` (EXPLAIN ESTIMATE + system.parts + system.processes, no invented throughput or price), `lake_query_runner.py` and migration `111`. Negative control: removing the `status = 'queued'` predicate makes both interleaved transactions claim one job and the live suite goes red. The first version of that test — five gathered claims — passed under the broken implementation and was replaced. 26 pure + 12 live tests; matrix 306 rows, 303 GATED. |
| 2026-10-11 | 4.2 | Reproduced: `check_standard_inputs.py` against the pre-fix tree reported no OTLP package, no Kafka input and no TAXII server — the only TAXII-shaped route being a demo-gated sample list. Built all three, after moving the consumer-health classifier out of `graph_ws` into `streamhealth` so the new Kafka consumer shares the table rather than copying it. Negative controls recorded in the PR: a timestamp-only TAXII cursor loses an indicator in the single-row pagination walk (measured — 3 of 4), and nineteen gate injections each go red. Writing it found four defects, including an OTLP template nobody could mint a token for and a gate rule that read an error message instead of the behaviour. Ingest Go suite green; api projection suite 37; live TAXII suite 15. |
| 2026-10-09 | 4.1 | Reproduced: `check_cloud_native_collection.py` on the unmodified tree reported all three collection paths absent. Implemented `aws_cloudtrail_s3` (SQS-notified S3 objects; management events, data events and VPC flow logs; delete-after-emit), `gcp_pubsub` (REST pull on a log-sink subscription; ack-after-read) and `azure_event_hubs` (Capture blobs over the Data Lake Gen2 JSON API, with a focused Avro OCF reader). Negative controls recorded in the PR: deleting the SQS message before the object is read, acknowledging the Pub/Sub batch before it is built, ignoring the Avro union branch index, and ignoring the flow-log header line each fail a named test, and all were restored. Connectors suite 1014 -> 1098 passed. |
| 2026-10-09 | 3.1 | All 74 decided. 50 translated into `wd-*` rules derived from each original's own clauses and replayed through the real engine (162 assertions); 24 refused with a reason across five kinds. `MAX_UNREACHABLE` 119 → 45, published executable 2,603 → 2,529, windowed 18 → 68. Three findings recorded as D4–D6 below. |
diff --git a/apps/docs/docs/operations/cold-tier-queries.md b/apps/docs/docs/operations/cold-tier-queries.md
new file mode 100644
index 000000000..77fb99054
--- /dev/null
+++ b/apps/docs/docs/operations/cold-tier-queries.md
@@ -0,0 +1,131 @@
+---
+id: cold-tier-queries
+title: Querying the cold tier
+sidebar_label: Cold-tier queries
+---
+
+A tenant can keep up to 400 days of events, and most of that lives on the
+cold volume once the tiering policy has moved it there. Reading it is
+slower and costs money, and until recently the only thing the platform
+told you about that was a timeout.
+
+Three surfaces now cover it.
+
+## Ask what a query would read
+
+```bash
+curl -sS -X POST "$AISOC_URL/api/v1/lake/estimate" \
+ -H "Authorization: Bearer $AISOC_API_TOKEN" \
+ -H 'Content-Type: application/json' \
+ -d '{"sql": "SELECT event_time, src_ip FROM raw_events WHERE event_time > now() - INTERVAL 300 DAY"}'
+```
+
+```json
+{
+ "estimated_rows": 418000000,
+ "estimated_parts": 1240,
+ "estimated_bytes": 91273000000,
+ "cold_bytes": 84900000000,
+ "warm_bytes": 6373000000,
+ "touches_cold": true,
+ "tables": ["raw_events"],
+ "estimated_usd": null,
+ "cost_basis": "no retrieval price is configured, so no money figure is reported. …"
+}
+```
+
+Every figure is ClickHouse's own. Rows and parts come from `EXPLAIN
+ESTIMATE` — the planner's answer after partition pruning. The warm/cold
+split comes from `system.parts` joined to `system.disks`, matched against
+the volume names your storage policy declares, so a part is cold because
+ClickHouse says it is on the cold volume and not because of its age. Those
+two disagree whenever a move is in flight or the TTL has changed, and the
+disk is the one that decides what the read costs.
+
+The estimate is charged at the schema rate rather than the query rate.
+Pricing it like a scan would train analysts to skip it.
+
+### Why `estimated_usd` is usually null
+
+Because no retrieval price is configured.
+`docs/decisions/storage-cost-model.json` is a **storage** rate card —
+dollars per GB-month resident — and using it to price a read would be
+quoting the wrong number confidently. Set your provider's retrieval price
+and you get a figure derived from it:
+
+```bash
+AISOC_LAKE_COLD_RETRIEVAL_USD_PER_GB=0.01
+```
+
+`null` means "we do not know what this costs". `0.0` means "this costs
+nothing". They are never confused.
+
+## Run it as a job
+
+`POST /api/v1/lake/sql` refuses a query the estimate says must read the
+cold volume, with `409` and the estimate attached:
+
+```json
+{
+ "error": "cold_scan",
+ "message": "this query reads the cold tier, which does not reliably finish inside the 30s synchronous bound. Submit it to POST /api/v1/lake/query-jobs, …",
+ "estimate": { "...": "..." }
+}
+```
+
+The routing rule is structural, not a predicted duration. Predicting one
+would need a bytes-per-second figure, and the only honest source for that
+is a measurement on your own hardware, which the platform has not got.
+`force_sync: true` overrides it when you already know the scan is small.
+
+```bash
+curl -sS -X POST "$AISOC_URL/api/v1/lake/query-jobs" \
+ -H "Authorization: Bearer $AISOC_API_TOKEN" \
+ -H 'Content-Type: application/json' \
+ -d '{"sql": "SELECT …", "row_cap": 5000}'
+```
+
+Answers `202` with a job. Poll it:
+
+```bash
+curl -sS "$AISOC_URL/api/v1/lake/query-jobs/$JOB_ID" -H "Authorization: Bearer $AISOC_API_TOKEN"
+```
+
+| Field | Meaning |
+|---|---|
+| `status` | `queued`, `running`, `succeeded`, `failed`, `cancelled` |
+| `rows_read`, `bytes_read` | From `system.processes`, the server's own counters |
+| `total_rows_approx` | ClickHouse's running estimate; it moves |
+| `progress_ratio` | `0.0`–`1.0`, or **`null`** when the server has not published a total |
+| `estimate` | As taken at submit time, never recomputed |
+| `columns`, `rows`, `row_count` | Present once `succeeded` |
+| `error` | Present once `failed`, with what to change |
+
+`progress_ratio` being null is a real state, not a bug. ClickHouse
+publishes `total_rows_approx` best-effort, so a running query can have a
+numerator and no denominator — and a bar that renders 100% because the
+denominator was zero is worse than one that says it does not know.
+
+The estimate on a job is the number you agreed to before the scan started
+and is never recomputed. Moving it afterwards would make the record of
+what you were told untrue.
+
+`POST /api/v1/lake/query-jobs/{id}/cancel` stops a running scan and asks
+ClickHouse to kill the query. A job that has already ended answers `409`
+rather than being quietly re-marked.
+
+## Limits worth knowing
+
+* A job is capped at 15 minutes. That is a policy ceiling, not a
+ measurement — nothing here claims a cold scan takes fifteen minutes. It
+ is the point past which a human should be asked whether they still want
+ the answer.
+* Results are held on the job row, bounded by the `row_cap` you submitted.
+ The caller is polling, so there is nothing to stream to.
+* A job whose runner died — an API replica restarted mid-scan — stays
+ `running` with nothing behind it. `list_stuck_jobs` is what surfaces
+ those; a job still running long past the ceiling is not progressing.
+* If the estimator cannot run (the role cannot read `system.parts`, say),
+ a query runs the way it always did rather than being refused. Refusing
+ would make the lake unusable on a deployment whose system tables are
+ restricted. The skip is logged.
diff --git a/apps/docs/sidebars.ts b/apps/docs/sidebars.ts
index bdf7a7f0c..b2b804108 100644
--- a/apps/docs/sidebars.ts
+++ b/apps/docs/sidebars.ts
@@ -197,6 +197,7 @@ const sidebars: SidebarsConfig = {
"operations/enterprise-sso",
"operations/console-mfa",
"operations/data-governance",
+ "operations/cold-tier-queries",
"compliance/evidence-pack",
"compliance/fips-posture",
"operations/credentials",
diff --git a/docs/audit/CLAIM_TO_GATE_MATRIX.md b/docs/audit/CLAIM_TO_GATE_MATRIX.md
index 47f9688da..2cf41dc4b 100644
--- a/docs/audit/CLAIM_TO_GATE_MATRIX.md
+++ b/docs/audit/CLAIM_TO_GATE_MATRIX.md
@@ -17,6 +17,7 @@ Statuses: `GATED` (a CI job fails when the claim stops being true) · `PARTIAL`
| An OpenTelemetry Collector can export logs to AiSOC with no forwarder in between: `POST /v1/logs` reads ExportLogsServiceRequest in both the protobuf and the JSON encodings, and gzip bodies | `apps/docs/docs/connectors/otlp-logs.md`; depth plan 4.2 / parity 6.10 | `ci.yml :: python-lint` (`check_standard_inputs.py --self-test` then the gate: the content-type switch has a case arm for each encoding — matched against the arm rather than against any mention, because two error messages name both encodings when refusing a third and the first cut of the rule passed a receiver that had stopped accepting JSON entirely; gzip is decompressed; PartialSuccess is set; a publish failure answers 503 with Retry-After; the tenant comes from `tok.TenantID` and from no attribute; the receiver is routed at `/logs`, constructed in `main.go` and named in `/readyz`; the `otlp-logs` template ships and is in `ALLOWED_TEMPLATE_IDS`) + `ci.yml` ingest Go job (`internal/otlp`, 27 cases through the real route against protobuf and JSON bodies built with the OTLP protobuf types: both encodings land, the response uses the request's encoding, a gzipped body is accepted, resource and scope attributes reach the OCSF event, severity is derived from the number when the text is absent, a tenant in a resource attribute is ignored, a publish failure is 503 with Retry-After, a partly unprojectable batch reports rejected_log_records while the good record still lands, and an unknown JSON field does not refuse the batch) | core | GATED | Writing the suite found two defects: a well-formed empty batch answered 400, because an ExportLogsServiceRequest with no fields set encodes to zero protobuf bytes and the body reader called that unreadable; and the partial-success path had no reachable trigger, so the contract was a mechanism with no caller. **No live OpenTelemetry Collector has been exercised against this endpoint** — the bodies are built with the vendor's own protobuf types rather than captured from a running collector |
| A customer's own Kafka topics can be consumed directly, and the consumer can tell a fault that will never clear from one that might | `apps/docs/docs/connectors/kafka-input.md`; depth plan 4.2 / parity 6.10 | `ci.yml :: python-lint` (`check_standard_inputs.py`: the input uses the shared `streamhealth` classifier rather than a second copy of the table, names all three failure classes, sets `ErrorLogger` on the reader — with a `GroupID` set that is where every dial, join and rebalance failure goes while the fetch stays blocked — splits the broker list on commas because `kafka.TCP` is variadic, takes the tenant from the resolved token, and is parsed, constructed, started and named per source in `/readyz`) + `ci.yml` ingest Go job (`internal/kafkainput`, 22 cases driving the real loop through a scripted reader: a record carrying a different tenant in its payload *and* a header still lands under the token's; a `RebalanceInProgress` is transient and the loop continues, because it happens on every deploy; a `TopicAuthorizationFailed` stops the loop with the operator action in the readiness detail; an empty record is poison, is counted, does not mark the subscription unhealthy and **is** committed, because a poison record that is not committed is re-read forever; a publish failure does **not** commit; and an idle subscription reports attached with 'nothing has arrived yet' rather than looking broken) | core | GATED | The permanent set is enumerated rather than derived from `kafka.Error.Temporary()`, which answers a different question: `RebalanceInProgress` is non-retriable in the protocol's sense and routine in practice. **No live broker has been exercised** — the loop is driven through a scripted reader, so what is proven is the failure handling rather than the wire protocol, which is kafka-go's |
| Indicators can be published to a partner over TAXII 2.1, from this tenant's own store, without losing one to pagination | `apps/docs/docs/operations/taxii-server.md`; depth plan 4.2 / parity 6.10 | `taxii-live.yml :: TAXII pages every indicator exactly once, and only this tenant's` (real Postgres, every migration applied, 15 cases through the real route functions: another tenant's collection is not found by id or by alias, no other tenant's indicator appears in a page, a collection filter narrows what is published, the manifest pages by the same cursor as objects, a corrupt `next` is a 400 rather than a silent restart, and the walk that matters pages the collection one indicator at a time and requires all four back exactly once. The job asserts migration 110's paging index exists rather than assuming it, greps the run for a skip so the suite cannot pass by not running, and carries a negative control that replaces the `(updated_at, id)` row-value cursor with the bare timestamp comparison and requires the walk to go red — measured: it returns 3 of 4) + `ci.yml` api job (`test_taxii_projection.py`, 37 pure cases over the STIX projection: a quote in a value is escaped per the grammar and the backslash before it, timestamps carry a literal Z, the TLP marking is the id the specification fixes, the STIX id is derived from the row, an unknown filter key is refused rather than ignored) + `ci.yml :: python-lint` (`check_standard_inputs.py`: all six routes a client walks, `added_after`, the row-value cursor, tenant from the principal, `can_write` pinned false, RLS and the paging index in the migration) | core | GATED | Read-only by design: `can_write` is false on every collection and a write answers 403 naming the posture, because an inbound TAXII write is an outside party inserting indicators that drive this tenant's detections. `cve` is refused rather than published as a malformed pattern, with the reason served at `/taxii/unpublished-types` from the same table the projection uses. **No third-party TAXII client has been run against this server** — conformance is asserted against the specification's shapes, not against a client's behaviour |
+| A query over the cold tier reports what it will read and how far it has got, instead of timing out silently | `apps/docs/docs/operations/cold-tier-queries.md`; depth plan 4.3 | `lake-query-jobs-live.yml :: One replica claims a cold scan, and a finished job stays finished` (real Postgres, every migration applied, 12 cases: two **explicitly interleaved** transactions claim one job and exactly one wins, a cancelled job is not overwritten by a late finish, a late progress read does not resurrect a finished job, an unknown denominator stores NULL rather than a number, and another tenant's job id is a 404. The job asserts `progress_ratio` is nullable in the live schema, greps the run for a skip so the suite cannot pass by not running, and carries a negative control removing the `status = 'queued'` predicate, after which both transactions claim the job and the suite must go red) + `ci.yml :: Python — Tests` (api, `test_lake_cold_query.py`, 26 cases: the planner's output is summed by column name so a reorder cannot swap rows and parts, an unreadable column set raises rather than returning zero, an unrecognised disk counts as warm, a progress ratio with no denominator is None and one past its estimate is clamped, and **no money figure is produced without a configured retrieval price**) + `ci.yml :: python-lint` (`check_retention_window.py --self-test`, eight cold-query rules added with one injection each: an estimate this code derives rather than asking the planner, no warm/cold split, an unguarded ratio denominator, a claim two replicas can both win, a terminal state a late finish can overwrite, a cold query still routed synchronously, and jobs that exist in the ORM and in no database) | full | GATED | **`estimated_usd` is null unless a deployment configures `AISOC_LAKE_COLD_RETRIEVAL_USD_PER_GB`.** `docs/decisions/storage-cost-model.json` prices residency, not reads, and quoting it for a scan would be the wrong number stated confidently. The routing rule is structural rather than a predicted duration, because predicting one needs a bytes-per-second figure measured on the deployment's own hardware. **No ClickHouse has been exercised against this** — there is no ClickHouse in CI or on this machine, so `EXPLAIN ESTIMATE`, the `system.parts` join and the `system.processes` progress read are asserted against ClickHouse's documented shapes and the parsing of them is tested on recorded rows; what is proven live is the job lifecycle, which is where the concurrency defects are |
| Investigation Ledger stores every step | README L61, L169 | `ci.yml :: Python — Lint & Type-check` (`check_ledger_replay_contract.py` — response model ↔ console type, client requests ↔ router decorators, and `seq` ordering/uniqueness, each in both directions) + `ci.yml :: Python — Tests` (`test_investigation_replay.py`, 37 cases over `/replay`, `/events`, `/explain`; removing `ORDER BY seq` fails five of them) | core | GATED | — |
| Public eval harness gates every PR | README L62, L77 | `ci.yml :: p1-eval` | core | GATED (but suites are self-consistency; see reality report) | Phase 4 |
| Alert-reduction is a real measurement | README / benchmark page | `ci.yml :: python-test` (fusion) runs `test_alert_reduction_real.py`, which groups a 1 000-alert stream with `RawAlert.correlation_key()` — the method `Correlator` actually calls — and bounds the ratio on both sides, because a floor alone is satisfied by a key that collapses everything into one incident | core | GATED | the legacy suite's 75.3% stays published for continuity and is labelled as not describing this product; the measurement is still a synthetic workload, as the benchmark page states |
@@ -316,8 +317,8 @@ Statuses: `GATED` (a CI job fails when the claim stops being true) · `PARTIAL`
## Summary
-- Total: 305
-- GATED: 302
+- Total: 306
+- GATED: 303
- PARTIAL: 3
- NO GATE: 0