@malloy-publisher/skills 0.1.53 → 0.1.55

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/package.json +1 -1
  2. package/skills/eval-answer/SKILL.md +1 -1
  3. package/skills/eval-diagnose/SKILL.md +1 -1
  4. package/skills/eval-import/SKILL.md +1 -1
  5. package/skills/eval-improve/SKILL.md +1 -1
  6. package/skills/eval-judge/SKILL.md +1 -1
  7. package/skills/eval-loop/SKILL.md +1 -1
  8. package/skills/eval-report/SKILL.md +1 -1
  9. package/skills/malloy-analysis/SKILL.md +1 -1
  10. package/skills/malloy-analysis-report/SKILL.md +1 -1
  11. package/skills/malloy-charts/SKILL.md +1 -1
  12. package/skills/malloy-classify/SKILL.md +1 -1
  13. package/skills/malloy-compliance-review/SKILL.md +1 -1
  14. package/skills/malloy-dashboards/SKILL.md +1 -1
  15. package/skills/malloy-define/SKILL.md +1 -1
  16. package/skills/malloy-define-agent/SKILL.md +1 -1
  17. package/skills/malloy-discover/SKILL.md +1 -1
  18. package/skills/malloy-document/SKILL.md +1 -1
  19. package/skills/malloy-excel-review/SKILL.md +1 -1
  20. package/skills/malloy-excel-review/reference/cookbook-scenario.md +1 -1
  21. package/skills/malloy-excel-review/reference/translate-formulas.md +1 -1
  22. package/skills/malloy-getting-started/SKILL.md +1 -1
  23. package/skills/malloy-gotchas-modeling/SKILL.md +1 -1
  24. package/skills/malloy-html-data-apps/SKILL.md +1 -1
  25. package/skills/malloy-lookml-review/SKILL.md +1 -1
  26. package/skills/malloy-materialization/SKILL.md +21 -21
  27. package/skills/malloy-materialization/reference/access-filter.md +5 -5
  28. package/skills/malloy-materialization/reference/annotation.md +16 -11
  29. package/skills/malloy-materialization/reference/refresh.md +4 -3
  30. package/skills/malloy-materialization/reference/storage.md +12 -18
  31. package/skills/malloy-materialization/reference/tuning.md +10 -11
  32. package/skills/malloy-model/SKILL.md +4 -2
  33. package/skills/malloy-model-as-you-go/SKILL.md +1 -1
  34. package/skills/malloy-modeling/SKILL.md +1 -1
  35. package/skills/malloy-notebooks/SKILL.md +1 -1
  36. package/skills/malloy-phrase-detection/SKILL.md +1 -1
  37. package/skills/malloy-powerbi-review/SKILL.md +1 -1
  38. package/skills/malloy-publish/SKILL.md +1 -1
  39. package/skills/malloy-queries/SKILL.md +1 -1
  40. package/skills/malloy-reports/SKILL.md +1 -1
  41. package/skills/malloy-review/SKILL.md +1 -1
  42. package/skills/malloy-run-agent/SKILL.md +1 -1
  43. package/skills/malloy-source-unreachable/SKILL.md +1 -1
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@malloy-publisher/skills",
3
3
  "description": "Agent skills for Malloy and the Malloy Publisher",
4
- "version": "0.1.53",
4
+ "version": "0.1.55",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "main": "dist/index.js",
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: eval-answer
3
3
  description: 'Score one analytical answer against a verified golden, and score which of the entities the golden depends on retrieval delivered to the answerer. Run the contamination checklist, re-execute the submitted query yourself, then spawn a judge subagent per skill:eval-judge. Append attempt, tool_call, score, and retrieval_score events to the file ledger (reference/ledger-schema.md). Never explain the failure (eval-diagnose) or edit the model (eval-improve). Use when asked whether an answer was correct, to score a run, or to baseline a model.'
4
- version: 0.1.53
4
+ version: 0.1.55
5
5
  ---
6
6
 
7
7
  # Evaluate One Answer
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: eval-diagnose
3
3
  description: 'Diagnose why a scored answer failed and who owns the fix, then cluster the failures by shared root cause. Walk dataset, agent-call, get_context/model, get_context/retrieval, construction, then model-definition. Append issue events to the file ledger, linked by traceId, one per cluster. Use after eval-answer, when triaging a run, or before changing a model. Does not edit the model (eval-improve).'
4
- version: 0.1.53
4
+ version: 0.1.55
5
5
  ---
6
6
 
7
7
  # Diagnose One Answer
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: eval-import
3
3
  description: 'Turn a list of questions into an eval set, whatever shape it arrived in: a JSONL a customer sent, a CSV, a spreadsheet export, a markdown doc, an email thread, or a pull from production logs. Classify each item by what came WITH the question (a query, a number, prose criteria, or nothing), write cases.jsonl and set.json per reference/case-format.md, keep the file as it arrived, and seal each question so a later edit is detectable. Never marks a value-bearing golden verified and never invents a question. Use when questions arrive from outside and need to become a set, or before the first run against a set nobody here authored.'
4
- version: 0.1.53
4
+ version: 0.1.55
5
5
  ---
6
6
 
7
7
  # Import questions into an eval set
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: eval-improve
3
3
  description: 'Make the smallest safe edit that closes a diagnosed gap the model repo owns: a Malloy model edit, or a package skill under skills/. Every factual claim carries a probe receipt. Use after eval-diagnose, or when asked to fix a model so an agent can discover the right answer. Never accepts its own edit; the acceptance check belongs to eval-loop. Does not decide whether an answer was wrong (eval-answer) or why (eval-diagnose).'
4
- version: 0.1.53
4
+ version: 0.1.55
5
5
  ---
6
6
 
7
7
  # Improve the Model
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: eval-judge
3
3
  description: 'Decide whether ONE answer matches its golden, and say whether you believe the golden. Read this before emitting any verdict. Covers containment, column pairing, near_match, refusals, and the gold_status judgement. Use when scoring an attempt in an evaluation run; never to conduct a run (eval-loop), diagnose a failure (eval-diagnose) or edit a model (eval-improve).'
4
- version: 0.1.53
4
+ version: 0.1.55
5
5
  ---
6
6
 
7
7
  # The judge
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: eval-loop
3
3
  description: 'Conduct a local Publisher evaluation loop in five steps: scrape/run, eval, diagnose, improve, checkpoint. You are the conductor: import cases into the file ledger, spawn a blind answerer, then run eval-answer, eval-diagnose, and eval-improve. Persistence is plain files: the set in the model package''s evals/ directory, runs in the set''s workdir; checkpoints are git commits of the model repo. `eval.py` runs each step from the set''s eval.toml. Use to score a model, diagnose failures, improve behind an acceptance check, or roll back a bad direction.'
4
- version: 0.1.53
4
+ version: 0.1.55
5
5
  ---
6
6
 
7
7
  # The Evaluation Loop
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: eval-report
3
3
  description: 'Write the summary a person reads after an evaluation run: what ran, what it scored, which failures were the MODEL and which were the EVAL itself (out of turns, contaminated, unestablished golden, unreadable judge), what was learned, and what to do next. Every claim links to the artifact behind it. Use at the end of any run, before quoting a number to anyone. Never scores an answer (eval-answer) or decides who owns a failure (eval-diagnose).'
4
- version: 0.1.53
4
+ version: 0.1.55
5
5
  ---
6
6
 
7
7
  # Report a Run
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: malloy-analysis
3
3
  description: "Read before your first get_context call on any business or data question. The required workflow, not background: which source, which rows, how to verify. Skipping it causes confident wrong answers."
4
- version: 0.1.53
4
+ version: 0.1.55
5
5
  ---
6
6
 
7
7
  <!-- Copyright (c) Credible Data Inc. SPDX-License-Identifier: MIT -->
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: malloy-analysis-report
3
3
  description: Combine validated Malloy queries into a report (a linear report, read top to bottom). Use when the user asks to "create a report", "combine these into a report", or wants a persistent multi-query artifact.
4
- version: 0.1.53
4
+ version: 0.1.55
5
5
  ---
6
6
 
7
7
  <!--
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: malloy-charts
3
3
  description: Read before choosing a chart or adding a chart annotation. Chart types, tag syntax and scale rules, KPI cards, dashboards, sparklines, and the renderer mistakes that fail silently.
4
- version: 0.1.53
4
+ version: 0.1.55
5
5
  ---
6
6
  <!--
7
7
  Copyright (c) Credible Data Inc.
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: malloy-classify
3
3
  description: 'Propose #(classification) annotations for a Malloy model from an access policy''s class scheme, backed by aggregate value evidence from the served data, and show them as a diff before writing anything. Use when the user asks to "classify the model", "tag PHI/PII", "label sensitive fields", or adds fields to a package that a policy governs, and before running malloy-compliance-review on a model nobody has classified.'
4
- version: 0.1.53
4
+ version: 0.1.55
5
5
  ---
6
6
 
7
7
  <!--
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: malloy-compliance-review
3
3
  description: 'Check a Malloy package and its controls against a written access policy: turn the policy''s prose into a control register, run compliance.py check against a served package (structure, access as each role, and the values themselves), judge what needs a person, and produce a report and a signable attestation. Use when the user asks whether a model "complies with", "satisfies" or "meets" a policy, HIPAA, SOC 2, PCI or the like, asks for a compliance review or attestation, or wants the review in CI.'
4
- version: 0.1.53
4
+ version: 0.1.55
5
5
  ---
6
6
 
7
7
  <!--
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: malloy-dashboards
3
3
  description: "Renamed to malloy-reports. A dashboard is now a report with layout=grid: a .malloy file with an ## artifact tag, written at the package root. Load malloy-reports instead when the user asks for a dashboard, a filterable view, or drill-through between views."
4
- version: 0.1.53
4
+ version: 0.1.55
5
5
  ---
6
6
 
7
7
  <!--
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: malloy-define
3
3
  description: Propose scope, a source plan and field definitions for a Malloy model. Which tables and questions, which sources at what grain, then renames, dimensions and measures, each backed by querying data.
4
- version: 0.1.53
4
+ version: 0.1.55
5
5
  ---
6
6
  <!--
7
7
  Copyright (c) Credible Data Inc.
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: malloy-define-agent
3
3
  description: Define a package agent - a named brief, with its own skills, optional schedules and a run budget, declared in a package's publisher.json. Use when the user asks to create, add, change or fix an agent in a package, or wants a recurring or unattended job. Not for adopting an agent that already exists (that is malloy-run-agent), and not for a one-off question, which you just answer.
4
- version: 0.1.53
4
+ version: 0.1.55
5
5
  ---
6
6
  <!--
7
7
  Copyright (c) Credible Data Inc.
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: malloy-discover
3
3
  description: Silent data discovery for Malloy modeling. Used at Step 1 of the modeling workflow. Scans tables, columns, distributions, and relationships without user interaction. The agent builds an internal picture before presenting anything.
4
- version: 0.1.53
4
+ version: 0.1.55
5
5
  ---
6
6
  <!--
7
7
  Copyright (c) Credible Data Inc.
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: malloy-document
3
3
  description: 'Add documentation with #(doc) tags to Malloy models so fields and sources are described in plain language. Use when user asks to "add documentation", "add doc tags", "document the model", or wants fields and sources described for natural-language search and discovery. For runtime filters, declare given: parameters (see the malloy-model skill); #(filter) is deprecated. Filters are a runtime/modeling construct (governance, latency, correctness), not a documentation tag.'
4
- version: 0.1.53
4
+ version: 0.1.55
5
5
  ---
6
6
 
7
7
  <!--
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: malloy-excel-review
3
3
  description: Move an Excel workbook (.xlsx or .xlsm) onto Malloy - recover the model hiding in its cells, translate its formulas and pivots, and prove the numbers match against the values the file already stores. Use when a workbook is present, when a user wants to migrate or switch off a spreadsheet, and whenever a specific formula has to become Malloy - SUMIFS, COUNTIF, SUMPRODUCT, VLOOKUP, XLOOKUP, INDEX/MATCH, pivot tables, assumption cells, roll-forwards, circular references, Monte Carlo, or a Power Pivot model. Carries worked recipes, each labelled executed or semantics-cited in place, and states what each port costs. Works with or without a database connection.
4
- version: 0.1.53
4
+ version: 0.1.55
5
5
  ---
6
6
  <!--
7
7
  Copyright (c) Credible Data Inc.
@@ -881,7 +881,7 @@ the given, which is what the `absolute` regions already list.
881
881
  `#@ persist name="compounding_tbl"` to
882
882
  `source: persisted_compounding is compounding -> { select: * }`, where `compounding` is the
883
883
  recursion in `translate-formulas.md` (it reads its givens through `%{ }`). The package's
884
- build plan listed it under `refusedSources` with `reason: given_in_persisted_query` and the
884
+ build plan listed it under `refusedSources` with `reason: reads_given` and the
885
885
  message that a given in a persisted query "is substituted at BUILD time, so the table
886
886
  would hold the default's rows and serve them to every caller". The same shape of
887
887
  recursion with its numbers written as literals was accepted into the build plan. Only
@@ -157,7 +157,7 @@ Executed: with the defaults the five balances are 10500, 11025, 11576.25, 12155.
157
157
  and 12762.815625, the cached `Forecast!B6:F6`. With `givens: {"GROWTH_RATE": 0.02}` the
158
158
  fifth is 11040.808032, and with `0.08` it is 14693.280768, the cached What-If data
159
159
  table cells `Assumptions!E3` and `E6`. Label: `executed`. `#@ persist` on such a source
160
- is refused at planning (`given_in_persisted_query`): a persisted build would bake in the
160
+ is refused at planning (`reads_given`): a persisted build would bake in the
161
161
  default givens. `cookbook-scenario.md#persistence` has what was tried.
162
162
 
163
163
  ## 3. Routes
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: malloy-getting-started
3
3
  description: First steps for using a Malloy Publisher deployment through its MCP tools. Use when connecting to Publisher for the first time, when you do not yet know the available environments, packages, or models, or when a user asks what data they can explore. Also use for "malloy help" or which Malloy skill to read. Covers verifying the server, discovering data with get_context, and running a first grounded query.
4
- version: 0.1.53
4
+ version: 0.1.55
5
5
  ---
6
6
  <!--
7
7
  Copyright (c) Credible Data Inc.
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: malloy-gotchas-modeling
3
3
  description: Malloy modeling mistakes and compile-error fixes. Read before writing sources, dimensions, measures or joins, and when a .malloy file will not compile. Reserved words, NULLs, dates, field access.
4
- version: 0.1.53
4
+ version: 0.1.55
5
5
  ---
6
6
  <!--
7
7
  Copyright (c) Credible Data Inc.
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: malloy-html-data-apps
3
3
  description: "Build or modify an in-package HTML data app for a Malloy Publisher package (a public/ directory the package serves): design it, write its Publisher.query code, embed it. Hand-authored, no build step."
4
- version: 0.1.53
4
+ version: 0.1.55
5
5
  ---
6
6
  <!--
7
7
  Copyright (c) Credible Data Inc.
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: malloy-lookml-review
3
3
  description: Analyze LookML files as prior art for Malloy modeling. Used during Step 1 (DISCOVER) when .lkml files are present. Coordinates reference files that extract business logic, relationships, and curation decisions. Works with or without a database connection.
4
- version: 0.1.53
4
+ version: 0.1.55
5
5
  ---
6
6
  <!--
7
7
  Copyright (c) Credible Data Inc.
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: malloy-materialization
3
3
  description: Add, confirm and debug Malloy Persistence materializations in a package - persist an expensive source so queries read a pre-built table, in the source's own warehouse or in a storage destination. Read this whenever the user wants to materialize a source, add a persist annotation, speed up a slow source, build one stored rollup over another, tune what to persist, or asks why a persist source isn't building or isn't being read.
4
- version: 0.1.53
4
+ version: 0.1.55
5
5
  ---
6
6
  <!--
7
7
  Copyright (c) Credible Data Inc.
@@ -18,7 +18,7 @@ This file is the core. The details live beside it, one topic per file, and each
18
18
 
19
19
  - `reference/annotation.md` - the `#@ persist` tag: what can carry it, the name rules, identity and reuse, readers of a persisted source, and every option with where it is explained.
20
20
  - `reference/policy.md` - the `publisher.json` block: `scope`, `queryMetadata`, and where the rules are enforced.
21
- - `reference/storage.md` - building into a **storage destination** (`storage=`), `partition=`, where a given may sit, which sources that tier refuses, and how a stored table is served.
21
+ - `reference/storage.md` - building into a **storage destination** (`storage=`), where a given may sit, which sources that tier refuses, and how a stored table is served.
22
22
  - `reference/chaining.md` - one stored source built **over another stored source**: what makes it reuse the parent's table or recompute from the warehouse, and how to read which happened.
23
23
  - `reference/refresh.md` - keeping a table current: `freshness`, `schedule`, and `refresh="incremental"`.
24
24
  - `reference/access-filter.md` - persisting a `#(access_filter)`-gated source, and the bound on a stale access decision.
@@ -26,16 +26,16 @@ This file is the core. The details live beside it, one topic per file, and each
26
26
 
27
27
  ## v1 or v2: which spelling to write
28
28
 
29
- Publisher has two spellings. **v1** is `#@ persist` on a source and `#@ preaggregate` on a measure, and it is what a server reads by default. **v2** is `#(materialize)` on a source and `#(preaggregate)` on a measure, in development behind the server switch `PUBLISHER_MATERIALIZE` (default off). Since the v1 cutover both are served the same way: a stored table by the served copy (the author's own files with each stored source re-rooted on its table), a rollup by the rollup leg, so a query reads a table only when the path report says so. Everything else in this skill describes v1 unless it says otherwise.
29
+ Publisher has two spellings. **v1** is `#@ persist` on a source and `#@ preaggregate` on a measure, and every server reads it. **v2** is `#(materialize)` on a source and `#(rollup)` on a measure, on by default behind the server switch `PUBLISHER_MATERIALIZE` (`false` turns it off; the switch is removed one release after the default ships). Since the v1 cutover both are served the same way: a stored table by the served copy (the author's own files with each stored source re-rooted on its table), a rollup by the rollup leg, so a query reads a table only when the path report says so. Everything else in this skill describes v1 unless it says otherwise.
30
30
 
31
31
  **Pick by what the server runs, then by where the table goes:**
32
32
 
33
33
  | The server | A table in a storage destination | A table in the source's own warehouse | A rollup on a measure |
34
34
  |---|---|---|---|
35
- | `PUBLISHER_MATERIALIZE` on | `#(materialize) storage="lake"` (needs `PERSIST_STORAGE_MODE=on` too) | `#(materialize) name="..."` (`name=` is required here) | `#(preaggregate) grain=["a", "b"]` |
36
- | switch off (the default) | `#@ persist name="..." storage="lake"` | `#@ persist name="..."` | `#@ preaggregate grain="a, b"` |
35
+ | `PUBLISHER_MATERIALIZE` on (the default) | `#(materialize) storage="lake"` (needs `PERSIST_STORAGE_MODE=on` too) | `#(materialize)`, or `#(materialize) name="schema.table"` to name and place it | `#(rollup) grain=["a", "b"]` |
36
+ | switch off (`PUBLISHER_MATERIALIZE=false`) | `#@ persist name="..." storage="lake"` | `#@ persist name="..."` | `#@ preaggregate grain="a, b"` |
37
37
 
38
- So for new work, write v2 where the server has the switch on, and v1 where it is off. One exception: a source with a row-level gate (`#(authorize)`, `#(access_filter)`) is built as `#(materialize)` only with `PUBLISHER_MATERIALIZE_GATED_SOURCES` on as well; otherwise keep it on `#@ persist`. Ask whoever runs the server if you cannot tell; the startup log lists `materialize.enabled=true from PUBLISHER_MATERIALIZE` when it is on. **With the switch off, `#(materialize)` is ignored with no warning at all** (no build, no serve verdict, answered live), and `#(preaggregate)` is only an `annotation-near-miss` warning, so a v2 annotation on a v1 server looks exactly like a build that never ran.
38
+ So for new work, write v2 where the server has the switch on, and v1 where it is off. A source with a row-level gate (`#(authorize)`, `#(access_filter)`) of its own is built and served past that gate on either tier, database or `storage=`, `#(materialize)` or `#@ persist`, with `PUBLISHER_MATERIALIZE_GATED_SOURCES` off: the table holds every caller's rows and the gate is re-applied on every read. A `storage=` table puts those rows, ungated, in the destination, where anyone with direct access to it can read them; say so when you materialize a gated source there. A row filter it inherits, a gate reached through a join, or a gate over a source whose build reads a given is refused on both tiers. Ask whoever runs the server if you cannot tell; the startup log lists `materialize.enabled=true from PUBLISHER_MATERIALIZE` when it is on. **With the switch off, `#(materialize)` is ignored with no warning at all** (no build, no serve verdict, answered live), and `#(rollup)` is only an `annotation-near-miss` warning, so a v2 annotation on a v1 server looks exactly like a build that never ran.
39
39
 
40
40
  ```malloy
41
41
  // v2, switch on: no ##! experimental.persistence needed in this file
@@ -46,21 +46,21 @@ source: east_orders is orders_base extend {
46
46
  }
47
47
 
48
48
  source: sales is orders_base extend {
49
- #(preaggregate) grain=["category"]
50
- #(preaggregate) grain=["category", "region"]
49
+ #(rollup) grain=["category"]
50
+ #(rollup) grain=["category", "region"]
51
51
  measure: revenue is amount.sum()
52
52
  }
53
53
  ```
54
54
 
55
55
  What is different about v2, briefly:
56
56
 
57
- - **It stores the source as written** - every dimension (computed, private and internal ones too) with its `where:` applied, not a query's output - so a plain `extend` over a table is fine and needs no `-> { select: * }`. Keys are closed: `name`, `storage`, `refresh`, `watermark`, `merge_key`, `partition`, `freshness.*`, `queryMetadata.*`, `inline`. Any other key refuses the publish (`materialize-unknown-key`).
57
+ - **It stores the source as written** - every dimension (computed, private and internal ones too) with its `where:` applied, not a query's output - so a plain `extend` over a table is fine and needs no `-> { select: * }`. Keys are closed: `name`, `storage`, `refresh`, `watermark`, `merge_key`, `freshness.*`, `queryMetadata.*`, `inline`. Any other key fails the publish and the load (`materialize-unknown-key`; the retired `partition=` is `materialize-retired-key`).
58
58
  - **The base must not declare measures, views or joins**, unless the base is materialized too. A `#(materialize)` source that inherits one is built but never read: `served-copy-not-served` ("This source inherits fields ..."), serve verdict `live` / `served_copy`, every query live. Build over a base with none (as above), or keep the query shape (`orders -> { select: * } extend { ... }`) and declare the measures after it.
59
59
  - **Joins are references by default.** `inline=["j"]` stores a join_one as `j__<field>` columns, or a join_many as a pair table; an incremental pair table names a watermark on each side, `watermark=["updated_at", "j.updated_at"]`.
60
- - **`#@ persist` on a view and `#@ -persist` on a reader are the same in both.** A persisted view is built only with the switch on. `#@ preaggregate` is deprecated (a `deprecated-preaggregate-annotation` warning with the switch on; it still builds).
61
- - **Confirm it the v2 way.** The package's serve verdicts (`GET .../packages/{pkg}/status`, `serveVerdicts`) read `serves`; a query's path report reads `servedBy.kind: "materialized"` with `via: "served_copy"` (a rollup: `kind: "rollup"`; a persisted view: `kind: "view"`). `manifestBindingStatus` does not cover v2 tables.
60
+ - **`#@ persist` on a view and `#@ -persist` on a reader are the same in both.** A persisted view is built only with the switch on, and so is `#@ persist` on a named `query:` (`reference/annotation.md`). Off, either is answered live, its line is still read (an invalid one fails the load), and a valid one warns `persist-view-not-built` or `persist-query-not-built`. `#@ preaggregate` is deprecated (a `deprecated-preaggregate-annotation` warning with the switch on; it still builds). So is `#(preaggregate)`, `#(rollup)`'s former name: it is read the same for one release, with the same warning, and a measure that carries both fails the load (`rollup-invalid`). Write `#(rollup)`.
61
+ - **Confirm it the v2 way.** The package's serve verdicts (`GET .../packages/{pkg}/status`, `serveVerdicts`) read `serves`; a query's path report reads `servedBy.kind: "materialized"` with `via: "served_copy"` (a rollup: `kind: "rollup"`; a persisted view: `kind: "view"`; a persisted named query: `kind: "query"`). `manifestBindingStatus` does not cover v2 tables.
62
62
 
63
- **Existing v1 code is not wrong**, and moving it is optional. When asked to move it, follow `docs/materialization-migration.md` in the Publisher repository: one v1 spelling at a time, a dry-run publish (`POST .../packages?dryRun=true`) to read the warnings and serve verdicts, a build (every migrated source rebuilds once, because its content address moves), then the path report and a served-versus-live comparison against an opted-out reader (`#@ -persist source: x_live is x extend {}`, declared in a model file, not in the query text). A colocated `#(materialize)` must keep a `name=`; keeping the v1 source's `name=` is fine, since the package's own runs wrote that table.
63
+ **Existing v1 code is not wrong**, and moving it is optional. When asked to move it, follow `docs/materialization-migration.md` in the Publisher repository: one v1 spelling at a time, a dry-run publish (`POST .../packages?dryRun=true`) to read the warnings and serve verdicts, a build (every migrated source rebuilds once, because its content address moves), then the path report and a served-versus-live comparison against an opted-out reader (`#@ -persist source: x_live is x extend {}`, declared in a model file, not in the query text). Keep the v1 source's `name=` when you move it: an unversioned or `scope: "package"` package's table stays at that name (the package's own runs wrote it). Without `name=`, a v2 table takes a readable name, `<package>__<file>__<source>__p<hash>`, and on BigQuery a database table then is not built: a `#(materialize)` or `#@ persist` source with no dataset-qualified `name=`, or a rollup whose `name=` (or its base's) gives no dataset, is refused at plan (reason `needs_qualified_name`) and serves live, so give it a dataset-qualified `name=`. Under `scope: "version"` a `name=` sets the start of the table's name, schema or dataset included, and the version and a hash follow it (`analytics.summary_t__v1_2_0__p<hash>`), and no view is ever made at `name=`.
64
64
 
65
65
  ## The recipe (get this right and it just works)
66
66
 
@@ -77,10 +77,10 @@ What is different about v2, briefly:
77
77
  ```
78
78
  - **Only `query_source` and `sql_select` sources are persistable** - a `-> { ... }` pipeline or a `conn.sql("...")`, including one refined by a trailing `extend { ... }`. A `#@ persist` on a *plain* `extend` over a bare `conn.table(...)` is **refused, not ignored**: the package warns, and every run that covers it fails naming the source, so a whole-package run builds nothing until you fix it. Persist a query source instead (`source: x is raw -> { where: ...; select: * }`).
79
79
  - **Quote the name, once.** A bare `name=my_table` fails the package load with `persist annotation name must be quoted`; a name quoted *inside* the quotes (`name="\"My Table\""`) also fails the load, as not a plain identifier path. Publisher quotes each segment itself, so mixed case and reserved words need no extra quoting. The target's container must already exist and be writable by the connection.
80
- - **The name is not the identity.** A persist source is identified by a content address of its connection, SQL and partition layout, so a rebuild with unchanged logic reuses the table and two sources with the same body share one. An `extend` of a persisted source reads the same table and is not a second build target.
81
- - **A `name=` is one table on its schema, whichever package asks.** Publisher's own builds name a table with no `name=` after the source plus a hash of the environment and package (`orders__p3f9c2a1b`), so packages sharing a schema never collide. A `name=` is used as written and marked as its package's; if another package already holds it, that source's build is refused (`table-owned-elsewhere` in the run's failures) and it answers live. Give it a different `name=`.
80
+ - **The name is not the identity.** A persist source is identified by a content address of its connection and SQL, so a rebuild with unchanged logic reuses the table and two sources with the same body share one. An `extend` of a persisted source reads the same table and is not a second build target.
81
+ - **A `name=` is one table on its schema, whichever package asks.** Publisher's own builds give a table with no `name=` a readable name, `<package>__<file>__<source>__p<8 hex>` (`ecommerce__orders__orders__p3f9c2a1b`), the hex a hash of the environment, package, model and source, so packages sharing a schema never collide. A `name=` is used as written and marked as its package's; if another package already holds it, that source's build is refused (`table-owned-elsewhere` in the run's failures) and it answers live. Give it a different `name=`.
82
82
 
83
- The name rules, bound arguments, `#@ -persist`, and every option (`storage=`, `partition=`, `refresh=`, `freshness.*`, `queryMetadata.*`) are in `reference/annotation.md`.
83
+ The name rules, bound arguments, `#@ -persist`, and every option (`storage=`, `refresh=`, `freshness.*`, `queryMetadata.*`) are in `reference/annotation.md`.
84
84
 
85
85
  3. **Package persistence policy in `publisher.json`** (all optional):
86
86
  ```jsonc
@@ -94,7 +94,7 @@ What is different about v2, briefly:
94
94
  }
95
95
  ```
96
96
  - **`scope`** is a package-level contract about sharing tables across versions; on a standalone server it changes nothing except gating `schedule`. Its deprecated root-level home still works, but the two homes disagreeing **fails the load**.
97
- - **`freshness`** is the objective a **hosted control plane** enforces by refreshing the table; a **standalone** Publisher does not act on it at all. `fail` behaves like `live` today; only `stale_ok` keeps serving a stale table.
97
+ - **`freshness`** bounds how old a served table may be, the same way on every mechanism (rollups included) and in both deployments: a standalone run stamps the window on the tables it builds and rebuilds one past it on its next run; a **hosted control plane** stamps its own manifest and schedules refreshes to meet it. `fail` behaves like `live` today; only `stale_ok` keeps serving a stale table.
98
98
  - **`queryMetadata`** tags every build statement and every query for the backend's cost attribution. Root level; the home inside `materialization` is deprecated. Observability only.
99
99
  - **`schedule`** is a 5-field UTC cron that **requires `scope: "version"`** and **excludes `freshness`**; it fires only on a standalone server whose scheduler is enabled.
100
100
 
@@ -120,7 +120,7 @@ A green run is not proof, and neither is a fast query (on small data a live reco
120
120
  3. **The query names the table.** A query's full result (the REST query response without `compactJson`) carries the SQL it ran. Served from the table, its `FROM` names the physical table; computed live, it carries the source's own SQL instead. This is the per-query proof.
121
121
  4. **A reload unbinds them.** Reloading the package - including the automatic reload when a watched file is saved - drops the binding, and queries compute live until the next materialization run, which reuses unchanged tables and binds them again. (A server *restart* re-establishes the bindings from its store; a reload does not.) After editing a model, run a build before you trust a timing.
122
122
 
123
- A query response's `servedFrom` field does not answer this question for a table built in the source's own connection: it reports only the `storage=` tier's outcome (`storage` when that tier answered, `live_fallback` when it degraded to a live recompute) and is empty otherwise, served from a colocated table or not. Do not read `live_fallback` here as a signal about a colocated table.
123
+ A query response's `servedFrom` field names the tier that answered: `database` for a table built in the source's own connection, `storage` for a `storage=` table, `live_fallback` when a `storage=` read failed and live answered, and empty when no table answered. The path report's `servedBy.tier` names the same tier.
124
124
 
125
125
  ## Debugging a no-op build
126
126
 
@@ -140,7 +140,7 @@ source: smoke_raw is my_conn.table('some_dataset.some_table')
140
140
  #@ persist name="scratch_dataset.persist_smoke_test"
141
141
  source: persist_smoke is smoke_raw -> { aggregate: n is count() }
142
142
  ```
143
- If **even this** doesn't build after a real run, the problem is package-wide: read the run's error (a non-persistable source anywhere fails the whole run and names it), then check that the connection can write the target dataset. If the smoke source builds and your real one doesn't, your real source is the problem: its file's flag, or its entry in `failures` / `refusedSources`. Delete the smoke file and drop its table afterward (`malloy-pub delete materialization <id> --drop-tables`).
143
+ If **even this** doesn't build after a real run, the problem is package-wide: read the run's error (a non-persistable source anywhere fails the whole run and names it), then check that the connection can write the target dataset. If the smoke source builds and your real one doesn't, your real source is the problem: its file's flag, or its entry in `failures` / `refusedSources`. Delete the smoke file, delete its run (`malloy-pub delete materialization <id>`, record-only), and drop its table yourself through the connection.
144
144
 
145
145
  ## Gotchas
146
146
 
@@ -151,7 +151,7 @@ If **even this** doesn't build after a real run, the problem is package-wide: re
151
151
  - **A ready run can still have lost a source** - read `manifest.failures` and `metadata.refusedSources`.
152
152
  - **A reload unbinds; a restart rebinds** - run a build before trusting a timing.
153
153
  - **Reuse is by content address, not by name** - `--force-refresh` and every scheduler fire defeat it.
154
- - **Removing a persist source does not drop its table** - `delete materialization --drop-tables` drops what no other ready run names, and serving reverts to live in place.
155
- - **A given inside the persisted query is refused; in the source's own `extend` block it is applied per caller** - `reference/storage.md`.
154
+ - **Removing a persist source does not drop its table** - and neither does `delete materialization`, which is record-only. Drop the table yourself through its connection once no remaining ready run, of any version (list runs per version with `versionId`), names a table with that name in any place; serving reverts to live in place.
155
+ - **A given inside the persisted query is refused; in the source's own `extend` block it is applied per caller; inherited from a base it is refused and the source answers live** - `reference/storage.md`.
156
156
  - **A join to a non-persisted source, or a nested column, serves live for the queries that touch it** - the source's own fields still serve from the table.
157
- - **A `#(access_filter)`-gated source freezes its gating column when persisted** - `storage=` and `#@ preaggregate` refuse it outright; `reference/access-filter.md`.
157
+ - **A `#(access_filter)`-gated source freezes its gating column when persisted** - `#@ preaggregate` refuses it outright; a `storage=` table holds every caller's rows, ungated, in the destination; `reference/access-filter.md`.
@@ -5,21 +5,21 @@ SPDX-License-Identifier: MIT
5
5
 
6
6
  # Persisting a `#(access_filter)`-gated source
7
7
 
8
- A gated source **can** be persisted, but only on one tier and only in one shape, and the thing to be careful about is not refused by anything - you have to decide it.
8
+ A gated source **can** be persisted, on either tier but only in one shape, and the thing to be careful about is not refused by anything - you have to decide it.
9
9
 
10
- - **`storage=` and `#@ preaggregate` always refuse a gated source**, naming it. The build skips a refused source, records it on the run (`metadata.refusedSources`), and builds the rest of the package. A run fails on a refusal only when every authored source it targeted was refused, or when `sourceNames` named this one; a refused rollup never fails it. (`#@ persist storage=<name>` is the tier that materializes into a separate registered storage destination and serves from there, rather than building in the source's own connection; `#@ preaggregate` stores a rollup Publisher derives from a measure you annotated with a grain, rather than a source you wrote.) A rollup also groups *across* the gated column, so it could not be row-filtered afterwards even in principle.
11
- - **A colocated `#@ persist` (no `storage=`) is admitted** when the gate is provably the entry point's **own row filter**. The gate is found through the import -> rename -> `query_source` -> `extend` chain, so a gate the persisted source did not declare itself still counts, and an inherited gate is admitted like a declared one. It is refused in exactly two cases: the gate is reached only through a join, or it does not classify as a row filter at all.
10
+ - **A rollup (`#(rollup)` or `#@ preaggregate`) over a gated source is built only where its gate holds on the rollup's rows**: database, every gate the base's own (declared on the base's own statement, not inherited from a source it extends, not through a join), and every field it reads a grain dimension. The gate is then re-applied on every read, as on a stored source (with `PUBLISHER_MATERIALIZE_GATED_SOURCES` on, an inherited gate too). Any other gated rollup is refused, naming it. The build skips a refused source, records it on the run (`metadata.refusedSources`), and builds the rest of the package. A run fails on a refusal only when every authored source it targeted was refused, or when `sourceNames` named this one; a refused rollup never fails it. (`#@ preaggregate` stores a rollup Publisher derives from a measure you annotated with a grain, rather than a source you wrote.) A rollup also groups *across* the gated column, so it could not be row-filtered afterwards even in principle.
11
+ - **A `#@ persist`, database or `storage=`, is admitted** when the gate is the entry point's **own row filter** (or an `#(authorize)` lock): declared on the persisted source itself, and classified as a row filter. Both tiers follow the same rule (so does `#(materialize)`): the table holds every caller's rows and the gate is re-applied on every read through Publisher. (`#@ persist storage=<name>` materializes into a separate registered storage destination and serves from there, rather than building in the source's own connection.) **A `storage=` table puts those rows, ungated, at rest in the destination**, where anyone with direct access to the destination reads every row; tell the author before choosing that tier for a gated source, and make sure no connection a model can name reaches the destination (its catalog, schema or data path): stored tables are named predictably, so any package could read the gated rows through it. It is refused in three cases: the gate is reached only through a join, it does not classify as a row filter at all, or the persisted source inherits it from a source it derives from or extends (`source: mine is gated -> { ... }`, `gated extend { ... }`, across imports or two hops away). A table of an inherited gate would hold every caller's rows, and the served copy, which reads the table in place of the source that declares the gate, cannot apply the gate to it, so every query would answer live anyway: it is not built. Declare the gate on the persisted source itself to serve it from a table.
12
12
 
13
13
  **What to be wary of.** Persisting does not weaken the gate: it changes only where rows are read FROM, and the gate still runs live on every query as that query's own `WHERE`, so filtered rows come back filtered. What freezes is the **column the gate filters on**. A row whose access decision changes - it changes owner, say - keeps being served under its OLD decision until the next rebuild. That is a stale *access decision*, not merely stale data, and nothing raises an error.
14
14
 
15
15
  **None of this is needed for the gate to work.** It is enforced live on every query either way; what needs a bound is how long a *stale* decision can survive. Of the three controls that look like that bound, only the first is:
16
16
 
17
- - **`freshness.window="24h"` with `freshness.fallback="live"` is the bound** (`reference/refresh.md`). The serve path re-checks freshness per query, so once the artifact ages past the window it drops out of the serving set and the query recomputes live, correctly filtered - whether or not a rebuild ever lands. Three details decide whether you actually get that. **`fallback` must not be `stale_ok`**: under `stale_ok` a stale artifact keeps being served, which voids the bound (`live` and `fail` both bound it today). Window and fallback resolve *independently, per field*, across the source, model-file and package layers, so a package-level `stale_ok` silently defeats a window you set on the source. Prefer the **per-source** spelling `#@ persist name="..." freshness.window="24h" freshness.fallback="live"` over the package-wide `materialization.freshness` key: the gated source is what needs the bound, and setting it package-wide forces every other persisted source to recompute once stale too. And **a content-identical sibling shares the artifact, so it shares the window**: reuse is keyed on the content-addressed `sourceEntityId`, which folds the connection and the SQL but *not* the source name, so two persist sources whose bodies compute the same SQL resolve to one table carrying one freshness policy. A host that folds the siblings' policies keeps the tightest window any of them declares - a sibling declaring nothing cannot loosen yours, and yours pulls that sibling's reads off the table once it lapses - and keeps the bounding fallback, so a sibling's `stale_ok` cannot void your bound either. If two sources need genuinely different windows, give them genuinely different SQL.
17
+ - **`freshness.window="24h"` with `freshness.fallback="live"` is the bound** (`reference/refresh.md`). The serve path re-checks freshness per query, so once the artifact ages past the window it drops out of the serving set and the query recomputes live, correctly filtered - whether or not a rebuild ever lands. Three details decide whether you actually get that. **`fallback` must not be `stale_ok`**: under `stale_ok` a stale artifact keeps being served, which voids the bound (`live` and `fail` both bound it today). Window and fallback resolve *independently, per field*, across the source, model-file and package layers, so a package-level `stale_ok` silently defeats a window you set on the source. Prefer the **per-source** spelling `#@ persist name="..." freshness.window="24h" freshness.fallback="live"` over the package-wide `materialization.freshness` key: the gated source is what needs the bound, and setting it package-wide forces every other persisted source to recompute once stale too. And **a content-identical sibling shares the artifact, so it shares the window**: reuse is keyed on the content-addressed `sourceEntityId`, which folds the connection and the SQL but *not* the source name, so two persist sources whose bodies compute the same SQL, with the same `name=` or none, resolve to one table carrying one freshness policy (different `name=`s are different tables). A host that folds the siblings' policies keeps the tightest window any of them declares - a sibling declaring nothing cannot loosen yours, and yours pulls that sibling's reads off the table once it lapses - and keeps the bounding fallback, so a sibling's `stale_ok` cannot void your bound either. If two sources need genuinely different windows, give them different `name=`s or genuinely different SQL.
18
18
 
19
19
  Both of those are properties of the **host** that assembles the manifest, not of the annotation: the publisher reports freshness per source and does no folding itself. Where the host does not fold, which sibling's policy reaches the wire is unspecified; a host that folds does so when it next publishes a version's manifest, not retroactively to manifests already distributed - so you can declare the window correctly and not have it in force yet.
20
20
  - **A cron alone is not a bound.** A failed build or a stopped scheduler leaves the source serving its old decisions indefinitely. `freshness` and `schedule` are mutually exclusive; for a gated source, take the window.
21
21
  - **`refresh="incremental"` does not bound revocation.** The delta only re-reads rows in `[covered_through, frontier)`, so a row that changes owner *without its watermark advancing* is never re-read - while the entry still reports an advancing `coveredThrough` and reads as healthy. Only a full rebuild recomputes the gating column.
22
22
 
23
- **And the window only binds where the serving manifest carries it.** Freshness is enforced from fields a control plane stamps onto the manifest it distributes; a Publisher that serves what it just built binds the table with no `dataAsOf` and no window, and an entry carrying no window never ages out. So on a standalone deployment the declared window is inert unless something binds the manifest through the API with those fields - which leaves a rebuild cadence you actually verify as the only bound, and makes leaving a revocation-sensitive source unpersisted the safer call.
23
+ **The window binds on a standalone server and under a control plane alike.** A standalone run stamps the declared window and the table's `dataAsOf` on the manifest it commits, as a control plane stamps the manifest it distributes, so the table ages out per query either way. Under a control plane, the control plane's manifest decides: what it stamps applies whatever the model declares.
24
24
 
25
25
  When recommending `#@ persist` on a gated source, pair it with a freshness window and say out loud what staleness the author is accepting. A gated source with neither a window nor a full-rebuild cadence has no bound on how long a revoked row keeps being served.
@@ -12,27 +12,29 @@ source: my_rollup is some_source -> { group_by: ...; aggregate: ... }
12
12
 
13
13
  ## What can carry it
14
14
 
15
- **Only `query_source` and `sql_select` sources are persistable** - a source whose definition has a `-> { ... }` pipeline or a `conn.sql("...")`, including one refined by a trailing `extend { ... }`. What is **not** persistable is a *plain* `extend` over a bare `conn.table(...)` (a filtered pass-through). A `#@ persist` on such a source is **refused, not ignored**: the package carries a warning naming the source (code `persist-not-materializable`), and any materialization run that covers it fails with `annotated '#@ persist' but were not recognized as a materializable source`, so a whole-package run builds nothing until you fix it. Persist a query source instead (`source: x is raw -> { where: ...; select: * }`), or remove the annotation.
15
+ **Only `query_source` and `sql_select` sources are persistable** - a source whose definition has a `-> { ... }` pipeline or a `conn.sql("...")`, including one refined by a trailing `extend { ... }`. What is **not** persistable is a *plain* `extend` over a bare `conn.table(...)` (a filtered pass-through). A `#@ persist` on such a source (or on a table base with only added fields, such as `duckdb.table('x') extend { measure: … }`, or on an unbound parameterized source) is **not ignored**: the publish and the load fail, naming the source (code `persist-not-materializable`). Persist a query source instead (`source: x is raw -> { where: ...; select: * }`), or remove the annotation.
16
16
 
17
- **A parameterized source must have its argument bound.** `#@ persist` on `high_value(min_amount is 500) -> { ... }` builds one fixed relation; on the free template `high_value -> { ... }` it is refused (`free_parameter`), since there is no single relation to store. A `given` the persisted *query* reads is refused the same way (`given_in_persisted_query`); a given in the source's own `extend` block is applied per caller at read. `reference/storage.md` says where a given may sit.
17
+ **A named `query:` persists its result only with `PUBLISHER_MATERIALIZE` on.** Then `#@ persist` on a top-level `query:` builds its result (as `<query>__query`), and the table answers `run: q`, a `queryName` call, a report naming `q`, and `run: q -> { … }`; a refinement (`q + { … }`) and any use of `q` inside another definition are answered live. A query that reaches a row-level gate (its source's own, an inherited one, or a joined source's), or reads a given or `now`, is not built; persist a view on a gated source instead. Whenever it is not built, the package carries a `warn` with code `persist-query-not-built` saying why, and the workaround that works everywhere: persist a source over it (`#@ persist` on `source: q_result is q`) and query that source.
18
18
 
19
- **A `#@` line that does not parse persists nothing.** Malloy drops the source from the build and it serves live. The package carries an `error` warning (code `persist-unparseable`) and a publish is refused; a package already published still loads. A key Publisher does not read (`merge_keys=` for `merge_key=`) is a `warn` (code `persist-unknown-key`) and changes nothing, so read the package warnings after every edit. A `#@` line Malloy never routes to persistence (`#@persist` with no space, `# persist`, `#(persist)`, or a misspelled directive such as `#@ persits`) persists nothing either; the package carries a `warn` with code `annotation-near-miss` that names the spelling it meant.
19
+ **A parameterized source must have its argument bound.** `#@ persist` on `high_value(min_amount is 500) -> { ... }` builds one fixed relation; on the free template `high_value -> { ... }` it is refused (`free_parameter`), since there is no single relation to store. A `given` the persisted *query* reads is refused the same way (`reads_given`); a given in the source's own `extend` block is applied per caller at read. `reference/storage.md` says where a given may sit. A persisted query that reads `now` (in its stages, a view it runs, the `where:`, a field or a join of the source it reads, `select: *` included, or the query of a query-shaped source it is built from or joins) is refused too (`current_time`, a `persist-not-built` warning, answered live), since its table would hold the rows as of the build; `now` in the source's own `extend` block is applied at every read and builds.
20
+
21
+ **A mistake on the line fails the load.** A `#@` line that does not parse (`persist-unparseable`), a key Publisher does not read (`merge_keys=` for `merge_key=`, `persist-unknown-key`), a retired key (`partition=`, `sharing=`, `schedule=`, `realization=`; `persist-retired-key`, and on `#(materialize)` `materialize-retired-key`), and a value that is wrong as written (an empty or non-text `storage=`, an `@env.` reference; `persist-invalid`) each fail the publish and the load, on every path: publish, reload, restart, watch mode. A `#@` line Malloy never routes to persistence (`#@persist` with no space, `# persist`, `#(persist)`, or a misspelled directive such as `#@ persits`) fails the same way, code `materialization-near-miss`, naming the spelling it meant. The error has one line per mistake, each ending with its code in brackets, and shows in the publish response and `/status` `loadErrors`; a failed reload keeps serving the previous model (`stale: true`). Fix what it names and reload. A _valid_ annotation Publisher cannot build (an unconfigured destination, a gate, a dialect that cannot refresh incrementally) is different: that declaration alone is refused with a `warn` under its mechanism's not-built code (`persist-not-built`, formerly `persist-source-refused`; `materialize-not-built`; `persist-view-not-built`; `persist-query-not-built`; `rollup-not-built`), answered live, and the package loads. The build plan's `refusedSources` holds one record for it, with the reason.
20
22
 
21
23
  ## The name
22
24
 
23
25
  - **Quote it, once.** `name="my_table"`, or a path `name="dataset.table"` / `name="project.dataset.table"`. A **bare** `name=my_table` fails the package **load** - so every publish and every restart - with `persist annotation name must be quoted`; it never silently no-ops.
24
26
  - **Plain identifier segments only**: dot-separated segments of letters, digits, underscores and hyphens. A quoted name holding a space, quote, semicolon or backtick is rejected with its own message (`persist annotation name must be a plain identifier path`), because the name is inlined into DDL. Publisher quotes each segment for the target warehouse, so case is preserved (`name="OrdersDaily"`) and reserved words work (`name="order"`); never add quotes inside the value.
25
- - **Never quote inside the quotes.** `name="\"Quoted Tbl\""` is refused when the model loads: a name must be a plain identifier path (letters, digits, `_`, `-`, dot-separated), and Publisher quotes each segment for the warehouse itself.
26
- - **One name per table.** Two distinct persist sources that resolve to the same `name=` in the same destination clobber each other (the second build overwrites the first, and dropping one drops the other's). Publisher refuses the publish (unless the deployment opts out with `PERSIST_COLLISION_ENFORCE=false`), warns on the package at load, and answers both sources live rather than from the shared table. A shared *body* is fine (it shares one table by content address); a shared name over different bodies is not.
27
+ - **Never quote inside the quotes.** `name="\"Quoted Tbl\""` fails the load (`persist-invalid`): a name must be a plain identifier path (letters, digits, `_`, `-`, dot-separated), and Publisher quotes each segment for the warehouse itself.
28
+ - **One name per table.** Two distinct persist sources that resolve to the same `name=` in the same destination clobber each other (the second build overwrites the first, and dropping one drops the other's). The publish and the load fail (`materialization-table-collision`). A deployment that opts out with `PERSIST_COLLISION_ENFORCE=false` loads the package instead, refuses both sources alone (`persist-not-built`), and answers them live rather than from the shared table. A shared *body* is fine (it shares one table by content address); a shared name over different bodies is not.
27
29
  - **The target's container must exist.** `name="analytics.daily"` puts the table in `analytics`, which the connection must be able to write and which Publisher does not create. The source can *read* anything the connection can read.
28
30
  - **The name is not the identity.** In a standalone Publisher `name=` is the physical table, rebuilt in place; a hosted deployment may assign the physical name itself. A `storage=` destination takes a single undotted name, since placement there is the destination's.
29
31
 
30
32
  ## Identity and reuse
31
33
 
32
- A persist source's identity is its **`sourceEntityId`**: a content address of its connection, its canonical SQL and its `partition=` layout. Not the name, not the file, not the package version. So:
34
+ A persist source's identity is its **`sourceEntityId`**: a content address of its connection and its canonical SQL. Not the name, not the file, not the package version. So:
33
35
 
34
- - **A rebuild with unchanged persist logic reuses the existing table** (skip-if-unchanged); changing the SQL or the partition layout builds fresh under a new address. `--force-refresh` and every scheduler fire defeat the skip; an incremental source is exempt from it and advances by its boundary instead (`reference/refresh.md`).
35
- - **Two sources whose bodies compile to the same SQL share one table**, however they are named, and share one freshness policy and one incremental boundary with it.
36
+ - **A rebuild with unchanged persist logic reuses the existing table** (skip-if-unchanged); changing the SQL builds fresh under a new address. `--force-refresh` and every scheduler fire defeat the skip; an incremental source is exempt from it and advances by its boundary instead (`reference/refresh.md`).
37
+ - **Two sources whose bodies compile to the same SQL share one table** when they name the same one (the same `name=`, or none), and share one freshness policy and one incremental boundary with it. Different `name=`s are different tables, each built under its own name.
36
38
  - **A republish by itself builds nothing on a standalone server**; reuse is a property of the next *run*.
37
39
 
38
40
  ## Readers of a persisted source
@@ -48,13 +50,16 @@ A persist source's identity is its **`sourceEntityId`**: a content address of it
48
50
  |---|---|---|
49
51
  | `name="..."` | the target table (required) | above |
50
52
  | `storage=<destination>` | build into a storage destination and serve from it | `reference/storage.md` |
51
- | `partition="a,b"` | lay the stored table out by those columns (`storage=` only) | `reference/storage.md` |
52
53
  | `refresh="incremental" watermark="col" [merge_key="a,b"]` | refresh by bounded delta instead of a full rebuild | `reference/refresh.md` |
53
54
  | `freshness.window="24h" freshness.fallback="live"` | per-source freshness objective (hosted deployments) | `reference/refresh.md` |
54
55
  | `#@ queryMetadata.<key>="v"` (sibling line) | per-source cost-attribution properties | `reference/policy.md` |
55
56
  | `#@ -persist` (on a reader) | opt a reader out of the table | above |
56
57
  | `#@ preaggregate grain="..."` (on a measure) | store a derived rollup | `reference/storage.md` |
57
58
 
58
- On a server with `PUBLISHER_MATERIALIZE` on, the v2 spelling `#(materialize)` takes the same keys but `realization`, plus `inline=[...]`, as a closed set (an unknown key refuses the publish), and `#(preaggregate) grain=["a", "b"]` replaces `#@ preaggregate`. The main skill's "v1 or v2" section says when to write which.
59
+ `storage=` and `name=` may be written beside the route's key or inside it: `#@ persist storage="lake"` and `#@ persist { storage="lake" }` place the table the same way, on every route (`#@ persist`, a persisted view, `#@ preaggregate`, `#(materialize)`, `#(rollup)`). When both are written, the one inside the key wins, even when it names nothing. A `storage=` that is empty or only whitespace, or that is a list or a block rather than text, fails the publish and the load (`persist-invalid`, or the route's own `*-invalid` code): name the destination, or drop the key to build in the source's own warehouse.
60
+
61
+ On a server with `PUBLISHER_MATERIALIZE` on, the v2 spelling `#(materialize)` takes the same keys, plus `inline=[...]`, as a closed set (an unknown key fails the publish and the load), and `#(rollup) grain=["a", "b"]` replaces `#@ preaggregate`.
62
+
63
+ A rollup (`#(rollup)` or `#@ preaggregate`) takes `name=` too, as a prefix: `name="analytics.orders_rollup"` creates `analytics.orders_rollup__p<hash>`, the container placing it and the leaf starting its name, as `name=` does under `scope: "version"`; the hash, and so the identity, stays Publisher's. Without `name=` the table takes the readable name `<pkg>__<file>__<base>_by_<grain>__p<hash>`, in its base's database `name=` container if it has one (`#@ persist` or `#(materialize)`). The leaf is lowercased in the name; one the name would otherwise rewrite (a space, punctuation, a leading digit, `__`), an empty one, or one ending in `__p<8 hex>`, fails the load (`rollup-invalid`). Changing the leaf renames the table (rebuilt once; the old one is dropped). `namespace="analytics"` is the deprecated spelling of the container alone, with a `deprecated-rollup-namespace` warning. The main skill's "v1 or v2" section says when to write which.
59
64
 
60
- An unrecognized key on the tag is a warning on the package. The retired per-source `sharing=` and `schedule=` are rejected at publish: scope and schedule are declared once for the package (`reference/policy.md`).
65
+ An unrecognized key on the tag fails the publish and the load (`persist-unknown-key`). The retired per-source `sharing=` and `schedule=` fail them too (`persist-retired-key`): scope and schedule are declared once for the package (`reference/policy.md`). So does `realization=`, even `"COPY"`: every table is built by CREATE TABLE AS SELECT.
@@ -17,8 +17,9 @@ or package-wide in `publisher.json` under `materialization.freshness`, or per mo
17
17
 
18
18
  - `window` is how old a table may be before it is stale. `fallback` says what a query over a stale table does: `live` and `fail` both skip the table and compute live (`fail` is reserved to error later; today it behaves as `live`); `stale_ok` keeps serving the stale table.
19
19
  - A **hosted control plane** enforces the objective: it refreshes the table to stay within the window and stamps each manifest entry with `dataAsOf` and the window, and the serve path re-checks freshness **per query**, so a table that ages past its window drops out of the serving set whether or not a rebuild ever lands.
20
- - A **standalone** Publisher does not act on it: it binds what it just built with no `dataAsOf` and no window, and an entry carrying no window never ages out. The declaration is inert there unless something binds the manifest through the API with those fields set. For a standalone server, the only refresh is a run or the scheduler below.
21
- - Two sources whose bodies compile to the same SQL share one table, and a host that folds their policies keeps the tightest window and the bounding fallback for both. If two sources need different windows, give them different SQL.
20
+ - A **standalone** run stamps the same fields itself: each table it builds carries the declared window and fallback and a `dataAsOf` of the run's start (or of an older stored table it was built from), so the serve path ages it exactly as it ages a hosted table. Its next run rebuilds a table past its window instead of carrying it forward; nothing rebuilds it the moment the window passes, so trigger runs yourself (the package `schedule` excludes `freshness`). A window is a whole number and a unit (`90s`, `30m`, `24h`, `7d`, `2w`) and a fallback is `live`, `stale_ok` or `fail`; anything else fails the load on every mechanism. A table is never fresher than what it read: a rebuilt windowed table rebuilds a carried upstream of unknown age, and takes an older upstream's `dataAsOf`.
21
+ - A **rollup** takes the same keys on `#(rollup)` or `#@ preaggregate`, and otherwise its base's own declaration, then the model file's and the package's, so it goes stale with its base. Measures of one rollup share one freshness; two that disagree, an unknown key in the group, or a window that does not read as above fail the load.
22
+ - Two sources whose bodies compile to the same SQL, with the same `name=` or none, share one table, and a host that folds their policies keeps the tightest window and the bounding fallback for both. If two sources need different windows, give them different SQL or different `name=`s.
22
23
 
23
24
  ## `schedule`: the power tier
24
25
 
@@ -44,7 +45,7 @@ source: daily_orders is orders -> { group_by: order_date; aggregate: revenue is
44
45
  - **An invalid declaration fails the package load**, not just the publish: `watermark=` without `refresh="incremental"`, `merge_key=` without a watermark, a watermark that names no materialized column or an aggregate, a `calculate:` field, or an unsupported dialect. Postgres, BigQuery and Snowflake sources only (the dialect that has to express the range); a DuckDB source has to say `refresh="full"`.
45
46
  - **`forceRefresh` never re-seeds**; it only defeats skip-if-unchanged, and an incremental source is exempt from that anyway. Ask for a full rebuild with `reseed` (`malloy-pub materialize --reseed`, or per source on the build instruction). Keeping them apart is what lets a schedule drive deltas at all, since every scheduled fire is forced.
46
47
  - Each manifest entry reports what the run **did**: `refresh: delta | full | none`, with `ledger.coveredThrough` as the boundary now in force. Every fallback - no recorded boundary, a boundary measured on a different table or watermark, drifted columns, `MERGE` on a Postgres older than 15 - rebuilds in full and succeeds, so a source quietly rebuilding on every run looks exactly like one advancing unless you read `refresh`. The reason codes (`forced`, `no_boundary`, `lineage_changed`, `table_renamed`, `merge_unsupported`, `table_unreadable`, `table_emptied`, `shape_mismatch`, `ledger_unreadable`, `chained_storage`, `frontier_unreadable`, `not_advanced`) say why.
47
- - Two sources that compile to identical SQL share one table **and one boundary**; if their incremental declarations differ, neither ever advances. Publisher warns and names both.
48
+ - Two sources that compile to identical SQL, with the same `name=` or none, share one table **and one boundary**; if their incremental declarations differ, neither ever advances. Publisher warns and names both.
48
49
  - `storage=` is supported: the warehouse computes the bounded range and the DML lands in the destination. A **chained** stored source always rebuilds in full (`chained_storage`): see `reference/chaining.md`.
49
50
  - The boundary lives in the publisher's own per-process store. A host that spreads a package's refreshes over several workers holds the ledger itself: it stores each entry's `ledger` object and sends them back as `buildInstructions.ledger` on the next run. Standalone, the store is the publisher's, always.
50
51
 
@@ -3,9 +3,9 @@ Copyright (c) Credible Data Inc.
3
3
  SPDX-License-Identifier: MIT
4
4
  -->
5
5
 
6
- # The storage tier: `storage=`, `partition=`, and how a stored table is served
6
+ # The storage tier: `storage=`, and how a stored table is served
7
7
 
8
- By default a persist source is built **in its own connection** (colocated): the warehouse runs the query and the table lands beside the data. `#@ persist name="..." storage=<destination>` builds it into a **storage destination** the environment declares instead - today a DuckLake catalog over local or object storage - and serves it from there, so a query served from the table never runs in the warehouse at all.
8
+ By default a persist source is built **in its own connection** (database): the warehouse runs the query and the table lands beside the data. `#@ persist name="..." storage=<destination>` builds it into a **storage destination** the environment declares instead - today a DuckLake catalog over local or object storage - and serves it from there, so a query served from the table never runs in the warehouse at all.
9
9
 
10
10
  ```malloy
11
11
  #@ persist name="daily_orders" storage=lake
@@ -13,28 +13,22 @@ source: daily_orders is orders -> { group_by: order_date; aggregate: total is am
13
13
  ```
14
14
 
15
15
  - `storage=` names a **storage destination**, never a connection. Destinations are declared on the environment (`storageDestinations: [{ "name": "lake", "type": "ducklake", "ducklakeConnection": { "catalog": {...}, "storage": {...} } }]`, by config or by environment PATCH); a build naming one the environment does not hold fails the run with a `DestinationNotFoundError`. Reads of the environment report a destination's name and type only, never its config.
16
- - The build is a native **query passthrough**: the source warehouse (Postgres, BigQuery or Snowflake) computes the query and only the result crosses into the store, through DuckDB. A source on a DuckDB connection is refused for `storage=` (there is nothing to push down). A `#(access_filter)`-gated source is always refused on this tier (`reference/access-filter.md`).
17
- - The tier is gated by `PERSIST_STORAGE_MODE` (`off` / `write-only` / `on`). Under `off` a `storage=` source is **skipped by the build and served live, with no error** - it is never built colocated instead. Under `write-only` it builds but is still served live, and the package warns. If a `storage=` source "did nothing", check the mode before the model.
16
+ - The build is a native **query passthrough**: the source warehouse (Postgres, BigQuery or Snowflake) computes the query and only the result crosses into the store, through DuckDB. A source on any other connection, the package's DuckDB sandbox (`duckdb.sql(...)`, `duckdb.table(...)`) and an environment DuckDB connection included, is refused at load: it is not built, it is answered live, and the route's `*-not-built` warning (reason `storage_source_unsupported`) names the connection. Drop `storage=` to build it in its own connection, or move the source to a warehouse connection. A DuckLake source builds only into its own catalog. A `#(access_filter)`-gated source is always refused on this tier (`reference/access-filter.md`).
17
+ - The tier is gated by `PERSIST_STORAGE_MODE` (`off` / `write-only` / `on`). Under `off` a `storage=` source is **skipped by the build and served live, with no error** - it is never built in the database tier instead. Under `write-only` it builds but is still served live, and the package warns (`materialization-storage-mode`). If a `storage=` source "did nothing", check the mode before the model.
18
+ - **Hidden columns are stored.** A `storage=` table holds every column its source declares, `private:` and `internal:` ones included (a renamed one under the name its query gives it; an `except:`-ed one not at all, unless another source with identical SQL shares the table and stores it - a fix is coming), and the served copy hides them again: a measure over a hidden column is answered from the table, and a caller is refused a hidden column in live's words. The values are at rest in the destination, readable by anyone with direct access to it, never through Publisher. To keep a value out of the destination, leave it out of the source's query, do not just hide it. `#(carries)` checks what a caller can reach, not what a table stores.
18
19
  - A package may name several destinations; each source routes to its own.
19
- - `partition=` requires `storage=` (refused as `partition_without_storage` otherwise) and every named column must be one of the source's public output columns.
20
+ - `partition=` is not supported: a stored table is written unpartitioned, and a package whose `#@ persist` or `#(materialize)` carries `partition=` fails the publish and the load (`persist-retired-key`, `materialize-retired-key`). Remove the key; it was a layout only, so the cost is scan time and no answer changes.
20
21
 
21
22
  ## Where a given may sit
22
23
 
23
24
  A persisted table is built once, with no caller present, so a `given` has to be somewhere the build never reads it.
24
25
 
25
- - **Inside the persisted query - refused.** `scoped_rollup is orders -> { where: region = $REGION; group_by: ... }` has only the declaration default available at build time, so the table would hold one caller's slice and nothing at read would re-apply the filter. The build refuses it (`given_in_persisted_query`). The same applies when the given is *inherited*: a query over a source whose `extend` block carries the term reads that filter into its SQL, and is refused just the same - what decides is whether the **build** would substitute a value, not which line the author typed it on.
26
- - **In the persist source's own `extend` block - honoured per caller.** `#@ persist ... storage=lake` on `fact is raw -> { select: * } extend { where: org_id = $ORG_ID }` strips the term from the build, stores every caller's rows in one table, and re-applies the term per caller at read. One artifact serves every tenant, and a term a caller writes on an extension of it still scopes what is read. Partition on the scoped column (`partition="org_id"`) so each caller's reads touch one partition.
26
+ - **Inside the persisted query - refused.** `scoped_rollup is orders -> { where: region = $REGION; group_by: ... }` has only the declaration default available at build time, so the table would hold one caller's slice and nothing at read would re-apply the filter. The build refuses it (`reads_given`). The same applies when the given is *inherited*: a query over a source whose `extend` block carries the term reads that filter into its SQL, and is refused just the same - what decides is whether the **build** would substitute a value, not which line the author typed it on.
27
+ - **In the persist source's own `extend` block - honoured per caller.** `#@ persist ... storage=lake` on `fact is raw -> { select: * } extend { where: org_id = $ORG_ID }` strips the term from the build, stores every caller's rows in one table, and re-applies the term per caller at read. One artifact serves every tenant, and a term a caller writes on an extension of it still scopes what is read.
28
+ - **Inherited from a base - refused, answered live.** `#@ persist` (or `#(materialize)`) on `r is scoped extend { ... }`, where `scoped is raw extend { where: org_id = $ORG_ID }`, is not built: only the persisted source's own declaration is re-applied over its table at read. It is refused (`inherited_where_with_given` for `#@ persist`, a `materialize-not-built` warning for `#(materialize)`) and answers live, correctly but at live speed. The same holds for a given-reading dimension a base declares. To serve it from a table, move the given-reading `where:` onto the persisted source itself, and let extensions that persist nothing read its table.
27
29
 
28
30
  A `#(access_filter)` gate is the same shape with a different source of truth; see `reference/access-filter.md`.
29
31
 
30
- ## `partition=`: laying the table out
31
-
32
- `#@ persist ... storage=lake partition="org_id"` writes the stored table as one file set per distinct value, so an equality term on that column (`=`, `in`) reads only the files it names; `partition="org_id,day"` nests them in the order given. It is a **layout and carries no isolation**: every filter is re-applied at read whether or not its column is partitioned, so a partition list that omits the column a query filters by costs a full scan, never a wrong answer.
33
-
34
- Use it for the column the reads filter by. A rollup carrying every key at a fine grain (every species, every tenant, every product) that each query filters to one key is read **whole** per query without a partition on that key - that is what makes a pre-aggregated table answer in seconds instead of milliseconds. Partition on the filter key and read cost tracks one partition while build cost tracks the whole table. Nothing checks the column's cardinality for you: a partition per value across very many values is the many-small-files case, and that judgement is yours.
35
-
36
- `partition=` is part of the source's content address, so changing it rebuilds the table. A chained downstream of a partitioned parent reads the parent's table like any other.
37
-
38
32
  ## Shaping a rollup for its reads
39
33
 
40
34
  A stored rollup pays at build time so that reads are cheap; the grain and the inputs decide whether they are.
@@ -57,11 +51,11 @@ Routing is decided per query, not per source, so one source can serve some queri
57
51
 
58
52
  What the server reports:
59
53
 
60
- - `QueryResult.servedFrom`: `storage` when the tier answered, `live_fallback` when the tier was bound but a run-time store failure degraded the query to a live recompute, and empty for everything else (a colocated hit, no binding, or an ineligible query - three different things).
54
+ - `QueryResult.servedFrom`: `storage` when the tier answered, `database` when a table in the source's own database did, `live_fallback` when the tier was bound but a run-time store failure degraded the query to a live recompute, and empty when no table answered (no binding, or an ineligible query; the path report says which).
61
55
  - The package's `storageServeBindings`, in its serving state at `GET /api/v0/environments/{env}/packages/{pkg}/status` (an older server: its entry in `GET /api/v0/status`, or the package read), lists the stored tables the package is currently bound to, with each entry's origin (`persist` or `preaggregate`). `manifestEntryCount` does not count them.
62
- - `publisher_storage_serve_routing_total{outcome=storage|live_fallback|runtime_live_fallback|blocked_by_row_level_gate, origin}` counts routed queries, and each query's path report names the table that answered (`servedBy.via: served_copy`) or why each one was skipped.
56
+ - `publisher_query_route_total{leg, outcome, reason}` counts each leg the router considered (`used`, `skipped` with the path report's reason, `fallback` when a stored run failed and live answered), and each query's path report names the table that answered (`servedBy.via: served_copy`) or why each one was skipped.
63
57
  - A query's full result carries the SQL it ran; served from the store, its `FROM` names the destination and the physical table.
64
58
 
65
59
  ## Pre-aggregation uses the same tier
66
60
 
67
- `#@ preaggregate grain="category, order_day"` on a **measure** stores a rollup Publisher derives at that grain and routes to it when a query groups by a subset of the grain; queries do not change. It builds through the same plan, manifest and scheduler as `#@ persist`, needs no `##!` flag, inherits the base source's freshness, and refuses a gated source. A rollup on a measure the published surface hides is not built; the package loads and warns. See `docs/preaggregation.md` for grain choice. On a server with `PUBLISHER_MATERIALIZE` on, write it `#(preaggregate) grain=["category", "order_day"]` instead; `#@ preaggregate` is deprecated there.
61
+ `#@ preaggregate grain="category, order_day"` on a **measure** stores a rollup Publisher derives at that grain and routes to it when a query groups by a subset of the grain; queries do not change. It builds through the same plan, manifest and scheduler as `#@ persist`, needs no `##!` flag, inherits the base source's freshness, and refuses a gated source. A rollup on a measure the published surface hides is not built; the package loads and warns. A hidden (`private` or `internal`) grain dimension is stored and stays hidden; a `where:` of the source's own that reads a given over grain dimensions is left out of the build and re-applied per caller at read; and a query that sets its own `timezone:` but reads no date or timestamp is answered from the rollup. See `docs/preaggregation.md` for grain choice. On a server with `PUBLISHER_MATERIALIZE` on, write it `#(rollup) grain=["category", "order_day"]` instead; `#@ preaggregate` is deprecated there.
@@ -5,7 +5,7 @@ SPDX-License-Identifier: MIT
5
5
 
6
6
  # Tuning materializations for cost and performance
7
7
 
8
- This skill turns the signals the open-source Publisher already records (the materialization history, per-run and per-source timings, which sources were built vs reused, and for the storage tier how queries were routed) into concrete, **recommendations-only** advice: which sources to persist, which to stop persisting, which to chain or partition, and how to schedule them. The Publisher has the raw signals, and you read them with the `malloy-pub` CLI.
8
+ This skill turns the signals the open-source Publisher already records (the materialization history, per-run and per-source timings, which sources were built vs reused, and for the storage tier how queries were routed) into concrete, **recommendations-only** advice: which sources to persist, which to stop persisting, which to chain, and how to schedule them. The Publisher has the raw signals, and you read them with the `malloy-pub` CLI.
9
9
 
10
10
  > **Recommendations only. Never change a model, schedule, or scope without the user's explicit go-ahead.** Present the findings and the proposed edits, then apply them only when asked. Persisting the wrong source wastes storage and rebuild time; unpersisting a hot one makes queries slow. Let the user decide.
11
11
 
@@ -15,7 +15,7 @@ Assumes the `malloy-pub` CLI is on PATH and points at the server (`--url` or `MA
15
15
 
16
16
  Establish what the package persists today and how it is governed.
17
17
 
18
- - **Persist sources:** the sources annotated `#@ persist name="..."` in the package's `.malloy` files, with their tier (`storage=` or not), `partition=`, and `refresh=`. Read the models (or `get_context` the package) to list them, and read `GET …/packages/{pkg}/build-plan` for what a run will build and what it will refuse.
18
+ - **Persist sources:** the sources annotated `#@ persist name="..."` in the package's `.malloy` files, with their tier (`storage=` or not) and `refresh=`. Read the models (or `get_context` the package) to list them, and read `GET …/packages/{pkg}/build-plan` for what a run will build and what it will refuse.
19
19
  - **Schedule + scope:**
20
20
 
21
21
  ```bash
@@ -34,7 +34,7 @@ The history is where cost lives. Each run records its trigger, timing, and per s
34
34
  malloy-pub list materialization --environment <env> --package <pkg>
35
35
  ```
36
36
 
37
- Columns: ID, Status, **Trigger** (`SCHEDULER` vs `ON_DEMAND`), Started, Completed, Error.
37
+ Columns: ID, Status, **Trigger** (`scheduler` vs `on_demand`; a run recorded before 0.15 says `SCHEDULER` vs `ON_DEMAND`), Started, Completed, Error.
38
38
 
39
39
  - **A single run's detail** (the cost signals):
40
40
 
@@ -44,25 +44,24 @@ The history is where cost lives. Each run records its trigger, timing, and per s
44
44
 
45
45
  In the JSON, read:
46
46
  - `metadata.durationMs`: how long the whole run took.
47
- - `metadata.sourcesBuilt` / `sourcesReused` / `sourcesFailed`: how much work the run did. A run that reused most sources was cheap. **A `SCHEDULER` run never reuses**: every scheduled fire is forced, so its `sourcesReused` is 0 by construction; judge a scheduled run by its duration and its per-source entries instead. An incremental source is counted as built even when its refresh applied nothing.
47
+ - `metadata.sourcesBuilt` / `sourcesReused` / `sourcesFailed`: how much work the run did. A run that reused most sources was cheap. **A scheduler run never reuses**: every scheduled fire is forced, so its `sourcesReused` is 0 by construction; judge a scheduled run by its duration and its per-source entries instead. An incremental source is counted as built even when its refresh applied nothing.
48
48
  - `metadata.sourcesRefused` and `metadata.refusedSources` (present only when a source was refused, and only on a run the publisher planned itself): sources the eligibility gate skipped. Each one serves live on every query, so a refused source the user expected to be persisted is a finding in its own right; its entry's `message` says what to change.
49
49
  - `manifest.entries` - a map keyed by `sourceEntityId`. Each entry carries `sourceName`, `physicalTableName`, `realization`, and the per-source cost signals: `buildDurationMs`; `queryCostBytes` where the warehouse reports it; `refresh: delta | full | none` for an incremental source (a `full` on an unchanged source every run is a source that never advances); `upstreamReuse: reused | recomputed` for a chained source (a `recomputed` with `upstreamRecomputeReason` is a chain that went back to the warehouse).
50
50
  - `manifest.failures`: sources the run lost while still finishing ready.
51
51
 
52
52
  Look across several runs, not one: the pattern over the recent history (how often it rebuilds, how long each source takes, what reuses) is the signal.
53
53
 
54
- - **For `storage=` tables, how queries were routed.** `publisher_storage_serve_routing_total{outcome, origin}` on the metrics endpoint counts queries answered from the store (`storage`) against ones that degraded (`live_fallback`, `runtime_live_fallback`), and each query response's `servedFrom` says it per query. Nothing equivalent exists for a table built in the source's own warehouse: there, "rarely queried" is a judgement from the model and the user's knowledge, not a measured metric. Say so when it matters.
54
+ - **For `storage=` tables, how queries were routed.** `publisher_query_route_total{leg, outcome, reason}` on the metrics endpoint counts each serving leg the router considered: `used` when it answered, `skipped` with the reason, and `fallback` when its stored run failed and live answered, and each query response's `servedFrom` says it per query. For a table built in the source's own warehouse there is no route counter, but each response's `servedFrom` reads `database` when one answered, so a log of responses measures it. Say so when it matters.
55
55
 
56
56
  ## Step 3: Analyze and recommend
57
57
 
58
58
  Weigh rebuild cost against query benefit. Common findings:
59
59
 
60
- - **Persist candidate:** an expensive, frequently-queried source that is _not_ persisted (recomputed on every query). Recommend adding `#@ persist name="..."`. Strongest when the source is a heavy aggregate/join reused by many queries and its inputs change slowly. If the source carries a `#(access_filter)` gate, check which case it is first. A gate reached only through a `join_*`, or not classifying as a row filter, means the colocated persist is **refused** - the build skips it and it serves live - so do not recommend persisting it at all. Where the gate is the source's own row filter the persist is admitted, and then only recommend it alongside a freshness window (`freshness.fallback="live"`): the gating column freezes at build time, so without one a revoked row can be served under its old access decision indefinitely (see `access-filter.md`).
60
+ - **Persist candidate:** an expensive, frequently-queried source that is _not_ persisted (recomputed on every query). Recommend adding `#@ persist name="..."`. Strongest when the source is a heavy aggregate/join reused by many queries and its inputs change slowly. If the source carries a `#(access_filter)` gate, check which case it is first. A gate reached only through a `join_*`, or not classifying as a row filter, means the database persist is **refused** - the build skips it and it serves live - so do not recommend persisting it at all. Where the gate is the source's own row filter the persist is admitted, and then only recommend it alongside a freshness window (`freshness.fallback="live"`): the gating column freezes at build time, so without one a revoked row can be served under its old access decision indefinitely (see `access-filter.md`).
61
61
  - **Removal candidate:** a persisted source that is cheap to compute, rarely queried, or rebuilt far more often than it is read. Recommend dropping the `#@ persist` annotation (and its table): the storage + rebuild cost is not buying anything.
62
62
  - **Chain candidate:** a `storage=` rollup whose intermediates re-read the warehouse on every build while a stored root already holds the rows. Rewire the intermediates onto the stored root (declaration order, a distinct `-> { select: * }` intermediate, joins onto stored siblings - `chaining.md`), and read `upstreamReuse` on the next run to confirm the chain holds. Keep a self-join or a wide hash aggregate over a large fact **in the warehouse**: chained, it builds in the destination's engine under its memory bound.
63
- - **Partition candidate:** a `storage=` rollup carrying every key at a fine grain that queries filter to one key - read whole per query. Recommend `partition="<key>"` on the filter column (`storage.md`), noting the cardinality.
64
63
  - **Denominator candidate:** a ratio whose numerator is a rollup and whose denominator counts the fact table per query. Persist the denominator at its own grain.
65
- - **Cadence mismatch:** a `SCHEDULER` cadence out of step with how fast the data changes or how long a build takes. If the build's `durationMs` approaches the interval, the cadence is too aggressive. If queries routinely read stale data, tighten it. For an incremental source, `refresh: delta` with small `buildDurationMs` per fire is the cheap steady state; `refresh: full` every fire means the boundary is being lost (read the reason).
64
+ - **Cadence mismatch:** a scheduler cadence out of step with how fast the data changes or how long a build takes. If the build's `durationMs` approaches the interval, the cadence is too aggressive. If queries routinely read stale data, tighten it. For an incremental source, `refresh: delta` with small `buildDurationMs` per fire is the cheap steady state; `refresh: full` every fire means the boundary is being lost (read the reason).
66
65
  - **Scope mismatch:** `scope: version` re-materializes per published version (right when versions must be isolated, e.g. a schedule); `scope: package` reuses one lineage across versions (cheaper when versions can share). A schedule _requires_ `version`. If a package carries a schedule it does not need, clearing it is step one; the scope itself is edited in `publisher.json` (the CLI does not move it back).
67
66
 
68
67
  Frame each recommendation with the evidence from Step 2 (the run IDs, timings, built/reused counts, per-entry fields) so the user can judge it.
@@ -77,14 +76,14 @@ Frame each recommendation with the evidence from Step 2 (the run IDs, timings, b
77
76
 
78
77
  (`--wait` gives up after 120 s by default and exits non-zero while the build continues; raise `--timeout` for a real build.)
79
78
 
80
- - **Remove a persist source:** delete the `#@ persist` annotation, rebuild, then drop the old run's tables:
79
+ - **Remove a persist source:** delete the `#@ persist` annotation, rebuild, delete the old runs, then drop the old table yourself:
81
80
 
82
81
  ```bash
83
82
  malloy-pub materialize --environment <env> --package <pkg> --wait
84
- malloy-pub delete materialization <old-id> --environment <env> --package <pkg> --drop-tables
83
+ malloy-pub delete materialization <old-id> --environment <env> --package <pkg>
85
84
  ```
86
85
 
87
- > `--drop-tables` drops the physical tables in that run's manifest **except any a still-ready run also names** - with the stable names an auto-run assigns, a table the new run carried forward survives the delete. Deleting a run also re-derives the package's serve bindings from the latest remaining ready run (or clears them to serve live), so a delete does not break queries; it can leave a table behind. A removed source's table is therefore dropped only once no ready run names it - delete the old runs that do, or drop it in the warehouse yourself.
86
+ > Deleting a run is **record-only**: it never drops a table. It re-derives the package's serve bindings from the latest remaining ready run (or clears them to serve live), so a delete does not break queries. To drop the old table, read its `physicalTableName` from the old run's manifest, check that no remaining ready run, of any version, names a table with that name in any place (the runs list answers for the latest version only, so list each version's runs with `versionId`; with the stable names an auto-run assigns, a table the new run carried forward is still served, and two destination names can reach one DuckLake), then drop it through its connection.
88
87
 
89
88
  - **Change the schedule / cadence:**
90
89
 
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: malloy-model
3
3
  description: Build Malloy semantic models with base source and joined source files. Use when creating or modifying .malloy files, user asks to "create a malloy model", "add dimensions", "add measures", "create a source", or any Malloy model authoring task.
4
- version: 0.1.53
4
+ version: 0.1.55
5
5
  ---
6
6
 
7
7
  <!--
@@ -332,9 +332,11 @@ Each extension replaces the base's `false` on the lock route with its own rule.
332
332
  - **Every given the gate references must be declared on the entry model's own surface, and must carry no default.** In a package curated with `index.malloy`, "on the surface" means `index.malloy` imports it: import the declaring file whole, or name the given in a selective import (`import { orders, GROUPS } from "orders.malloy"`). A given the model cannot resolve is refused at load. So is a referenced given declared _with_ a default: a caller who supplies nothing would get that default and be admitted or excluded by a value the gate's own line never shows, so it is refused rather than reasoned about case by case.
333
333
  - **A scalar/array mismatch between the operator and the given's declared type is a load-time refusal**, not a request-time warehouse error: `org_id in $GROUPS` requires `GROUPS` to be array-typed, `region = $REGION` requires `REGION` scalar. Negation is likewise refused outright, so there is no empty-given inversion surprise to warn about.
334
334
  - **Entry point only: not joined, but inherited through `extend`.** The gate applies to the source a query enters through. A gate on a source reached only via `join_*` **never fires**, at any depth, so anything ungated that joins a locked base hands the base's rows to every caller. A source that `extend`s a locked base and declares no gate of its own **does** carry the base's gate; declaring its own annotation replaces it. A source derived from a locked base via a query (`source: z is locked -> { … }`) instead **always carries the base's gate in addition to its own**: the derivation recurses into the base unconditionally, so an own gate does not replace it, and the two combine as separate AND'd entries. Pair a locked base with curated extension sources, using access modifiers (`include { public: …, private: * }`), so an extension re-exposes only a curated column surface, and keep sensitive sources out of ungated joins. Publisher checks this at load and **warns** (`join-bypass`, in `warnings`, in every package) when a published source author-joins a locked source while carrying no gate of its own, or joins a row-filtered source whose gate reads a given none of the entry source's gates read (the fix is in the message: scope the entry on the same given, carry the key in the `on`, or drop the join). It never refuses the load for this; a compliance review run in CI is the hard stop. A join the _caller_ writes in query text is the caller entering the joined source, so that source's gate does apply to it: a lock is decided, a row filter is grafted into the join. That holds for a query source the model declares over an inline `table(...) extend { … }` base as much as for a table source: the join anchors on the declared source, and the derivation carries the base's gate. The author-join side has a contract of its own: when a gated entry source author-joins a tenant-scoped source, carry the tenant key in the `on` (`on list_id = values.list_id and org_id = values.org_id`), because the joined source's gate does not fire through that join and the ON is what keeps the rows to the caller's tenant. Where a join cannot be keyed that way, the entry source's own gate may reference the joined column (`#(access_filter) values.org_id = $ORG_ID`): that is enforced, at the cost of turning that `join_one` into an inner join, so a row with no match drops rather than surviving with nulls.
335
+ - **Know this: a time-based gate follows the query's time zone.** `#(access_filter) dday = $ON_DAY`, with `dday is ts.day`, is computed in the query's `timezone:`, so a query choosing its zone shifts which rows the gate admits, by up to 14 hours around midnight. When the gate is an access boundary, gate on a column that already holds the date or key (a `date`-typed column or a `tenant_id`), not a timestamp truncated in a query stage or an `extend` dimension, or make sure the rows either side of the boundary belong to the same tenant.
336
+ - **Know this: a gate inherited through `->` filters the derivation's output, not its input.** In `source: shares is sales -> { group_by: region, category; aggregate: total, share is total / all(total) }` over a source gated `region = $REGION`, `all()`, `exclude()`, window functions, `calculate:` and a top-N `limit` are computed across every row before the gate applies. The caller sees only their rows, but a share of the grand total or a rank over hidden rows is visible, and a top-N can come back empty. When those figures are sensitive, filter the derivation's input: put a `where:` on the same given in the derivation's first stage (`sales -> { where: region = $REGION; group_by: …; aggregate: share is total / all(total) }`), so `all()`, `exclude()`, windows and `limit` see only the caller's rows (a gate declared on the derived source also filters its output, so it does not do this). Otherwise keep global-context functions out of a derivation over a gated source, or compute the global context explicitly from an ungated source you intend to expose.
335
337
  - **A derivation that drops a column the gate reads fails CLOSED.** `extend { except: org_id }`, or an `accept:` that omits it, leaves the grafted filter unable to compile, so the request is denied rather than served ungated. The one hole to know: dropping the gated column and then `rename:`-ing a _different_ column onto that exact name grafts successfully and binds the gate to the wrong column. Narrow, but real, so don't recycle a gated column's name. If a derivation's own projection needs to drop the column a row-level term would read, use a source-level term (`'literal' in/= $GIVEN`) instead, since it never depends on any projected column.
336
338
  - **The quoted-string and file-level forms are refused at load and no longer exist.** A quoted expression on the `source:` line, in either quote, a file-level `##(…) "<expr>"` applying to every source in the file, and the earlier `internal dimension: authorized is <expr>` form are all retired; the load names the rewrite. Every `.malloy` file in a package compiles at load and any failure aborts the package, so a retired-form gate anywhere in the package is refused. Only a declaring file _outside_ the package escapes that: it loads and denies every request instead, with no compile-time hint. See your deployment's reference documentation.
337
- - **A gated source can be persisted, but the gating column freezes.** `storage=` and `#@ preaggregate` refuse a gated source outright; a colocated `#@ persist` is admitted when the gate is provably the entry point's own row filter. The gate still runs live on every query, so rows come back filtered - but the column it filters ON is frozen at build time, so a row whose access decision changes keeps being served under the old decision until the next rebuild. Pair `#@ persist` on a gated source with a freshness window (`fallback="live"`), which is the only control that bounds that - and read `skill:malloy-materialization` for where that window binds, because on a standalone Publisher it does not.
339
+ - **A gated source can be persisted, but the gating column freezes.** `storage=` and `#@ preaggregate` refuse a gated source outright; a database `#@ persist` is admitted when the gate is provably the entry point's own row filter. The gate still runs live on every query, so rows come back filtered - but the column it filters ON is frozen at build time, so a row whose access decision changes keeps being served under the old decision until the next rebuild. Pair `#@ persist` on a gated source with a freshness window (`fallback="live"`), which is the only control that bounds that - and read `skill:malloy-materialization` for where that window binds, because on a standalone Publisher it does not.
338
340
 
339
341
  > **Trust caveat.** Givens are **caller-asserted**, anyone who can reach the query API can claim a favorable given, e.g. `{"ROLE":"admin"}`. Neither annotation is a real boundary unless it sits behind a trusted tier that sets givens from its own verified context, never directly from an untrusted caller. Neither is, on its own, end-user authentication. Publisher is a microservice that runs locally with the user's own permissions or inside their cloud behind that gateway, so say so whenever you describe what a gate protects.
340
342
  >
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: malloy-model-as-you-go
3
3
  description: 'After answering a data question, write down what the answer assumed so the next reader can trust the number. A field with a #(doc) in the model when you can edit it, an extend in the notebook when you can only author reports, or a stated assumption plus a Malloy snippet when you can only chat. Use after every answered question that rested on a judgment call, and whenever a question is asked against tables that have no model yet.'
4
- version: 0.1.53
4
+ version: 0.1.55
5
5
  ---
6
6
 
7
7
  <!--
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: malloy-modeling
3
3
  description: Build semantic models with Malloy for the Malloy Publisher. Read this skill whenever the user asks about modeling data or specifically mentions Malloy.
4
- version: 0.1.53
4
+ version: 0.1.55
5
5
  ---
6
6
  <!--
7
7
  Copyright (c) Credible Data Inc.
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: malloy-notebooks
3
3
  description: "Renamed to malloy-reports. A notebook is now a report with layout=linear: a .malloy file with an ## artifact tag, written at the package root. Load malloy-reports instead when the user asks for a notebook, a data story, or a report that reads top to bottom."
4
- version: 0.1.53
4
+ version: 0.1.55
5
5
  ---
6
6
 
7
7
  <!--
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: malloy-phrase-detection
3
3
  description: How to phrase search_text on a get_context call so retrieval returns the fields you need instead of a truncated catalog. Covers target-type classification and decomposition patterns.
4
- version: 0.1.53
4
+ version: 0.1.55
5
5
  ---
6
6
  <!-- Copyright (c) Credible Data Inc. SPDX-License-Identifier: MIT -->
7
7
 
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: malloy-powerbi-review
3
3
  description: Move a Power BI semantic model (TMDL, PBIP, or .pbix) onto Malloy - read their model, transpile its DAX, and prove the numbers match. Use when Power BI artifacts are present, when a user wants to migrate or switch off Power BI, and whenever a specific DAX measure has to become Malloy - CALCULATE, ALL/ALLSELECTED/ALLEXCEPT, RANKX and top-N, time intelligence, USERELATIONSHIP, calculation groups, what-if parameters, or an RLS role. Carries a worked, executed transpile per construct and states what each port costs. Works with or without a database connection.
4
- version: 0.1.53
4
+ version: 0.1.55
5
5
  ---
6
6
  <!--
7
7
  Copyright (c) Credible Data Inc.
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: malloy-publish
3
3
  description: Package Malloy models for serving by Malloy Publisher. Use when user asks to "publish", "package", "deploy", or wants to share models with others.
4
- version: 0.1.53
4
+ version: 0.1.55
5
5
  ---
6
6
  <!--
7
7
  Copyright (c) Credible Data Inc.
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: malloy-queries
3
3
  description: Read before writing or debugging a Malloy query. Dates, aggregates vs dimensions, joins, filters, strings, window functions, chart annotations, and the compile errors a SQL habit produces.
4
- version: 0.1.53
4
+ version: 0.1.55
5
5
  ---
6
6
  <!--
7
7
  Copyright (c) Credible Data Inc.
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: malloy-reports
3
3
  description: "Build or modify a Malloy Publisher report: a .malloy file with an ## artifact tag, written at the package root unless asked otherwise, laid out as a grid (a dashboard, scanned at a glance) or linear (a notebook or data story, read top to bottom), with filter controls rendered from givens and # drill click-through. Use when the user asks for a dashboard, a notebook, a report, a data story, a filterable view, or drill-through between views, and no code is wanted. Legacy .malloynb files are read, not authored."
4
- version: 0.1.53
4
+ version: 0.1.55
5
5
  ---
6
6
 
7
7
  <!--
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: malloy-review
3
3
  description: Malloy semantic-model code review. Invoke when the user asks to review, audit, or critique a `.malloy` file, a folder of Malloy models, or a GitHub PR that touches Malloy. Enforces project modeling standards and emits a navigable review file.
4
- version: 0.1.53
4
+ version: 0.1.55
5
5
  ---
6
6
  <!--
7
7
  Copyright (c) Credible Data Inc.
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: malloy-run-agent
3
3
  description: Adopt an agent a Malloy package declares, by name. Use only when the user names a package agent, for example "run the analyst agent on storefront" or "work as the agent in this package". Fetches the agent's definition with get_agent, works from its instructions, installs its skills, and runs one of its tasks when asked.
4
- version: 0.1.53
4
+ version: 0.1.55
5
5
  ---
6
6
  <!--
7
7
  Copyright (c) Credible Data Inc.
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: malloy-source-unreachable
3
3
  description: Work out why a source is missing from get_context, or why a query against it was refused with a 404 or a 403, and what to do next. Use when a source you expect is absent from discovery, when execute_query answers "No queryable source", when a query that used to work stops working, or when deciding whether a package's curation is hiding something you need.
4
- version: 0.1.53
4
+ version: 0.1.55
5
5
  ---
6
6
  <!-- Copyright (c) Credible Data Inc. SPDX-License-Identifier: MIT -->
7
7