Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ The five most frequent and costly error patterns LLMs introduce into ORE Studio
| [[id:694CC015-2319-4A60-A912-C47D01BA70E1][Mine failed builds]] | DONE | 2026-11-18 | 2026-11-18 | Collect failures from failed CI runs, fix-up commits, PR reviews and memories. |
| [[id:C2E54246-99BD-435E-803E-3C10652B67AB][Rank the patterns]] | DONE | 2026-11-29 | 2026-11-29 | Normalise error messages, group them into patterns and rank them by frequency and cost. |
| [[id:7BD09169-B1E5-46CA-8D10-4B5FFE681471][Ship checks for the top patterns]] | STARTED | 2026-11-19 | | Write a check for each of the top five patterns and prove each against its past failure. |
| [[id:4F014496-473F-4053-B86E-F4CA2B8EC19F][Build the checks the blame analysis recommends]] | DONE | 2026-12-04 | 2026-12-04 | Build the three proactive checks the blame analysis names, or record why the two that need another project's data belong there. |

* Decisions

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
:PROPERTIES:
:ID: 4F014496-473F-4053-B86E-F4CA2B8EC19F
:END:
#+title: Task: Build the checks the blame analysis recommends
#+description: Build the three proactive checks the blame analysis names, or record why the two that need another project's data belong there.
#+type: task
#+level: s1
#+filetags: :catch_llm_error_patterns:sprint_01:v0:
#+owner: marco
#+branch: check/a-tenant-first-key
#+pr: 278
#+blocked_on:
#+blocked_since:
#+created: 2026-12-04
#+updated: 2026-12-04
#+environment:
#+todo: DISCOVERED BACKLOG STARTED BLOCKED | DONE ABANDONED

This page documents a [[id:31C868B9-306E-4282-BA8C-07E647021B34][task]] in the [[id:63D5482E-E1E7-45B0-883F-3B2DDFA2B447][Story: Catch the errors LLMs introduce]] story. It captures the goal, current status, acceptance, and any notes or results.

* Goal

(Describe what user-visible-or-internal change this task produces.)

* Status

| Field | Value |
|--------------+----------------------------------------|
| State | DONE |
| Parent story | [[id:63D5482E-E1E7-45B0-883F-3B2DDFA2B447][Story: Catch the errors LLMs introduce]] |
| Now | Done: the tenant-first key check is built; the other two need data another project owns. |
| Waiting on | Nothing. |
| Next | Nothing. |
| Last touched | 2026-12-04 |

* Acceptance

- The tenant-first primary-key check exists as a rule of =rls_coverage=,
fires on a table whose key does not begin with =tenant_id=, is quiet on one
that does, and honours the ignore file.
- The answer-shape check is recorded as ORE Studio's to write: compass has no
answer-shape corpus, and the corpus is a project's data.
- The permission-classification check is recorded as ORE Studio's to write
for the same reason; the web half, that every card's keys exist in all
three languages, already exists as =catalogueSchema= in
=projects/compass.web/packages/pages/src/i18n/translate.ts=.

* Plan

1. Read the analysis at
[[id:4FF7664A-B0A7-4EB8-96D8-3FAB6EAE7692][The blame folder of sprint 31,
read for recurring breaks]] and the codecs it names.
2. Build the tenant-first rule in =rls_coverage=: the fact carries the
table's first key column, the reduce reports RLS_003 when =tenant_id= is
not it, and the ignore file can excuse a table with its reason.
3. Check what the other two need of compass. The answer shapes and the
permission classification are files and tables of ORE Studio's, not
concepts compass models, so the checks belong in its tree; the i18n
cardinality the analysis asks for is already enforced at module load.

* Measurements

Every number this task claims about a tree, with the command that produced it
and the commit it was measured at. A number without both is not a measurement,
because a clean-up record describes a tree and trunk moves under a branch: a
consumer count, a gate's component count and a suite's size all change with no
code changing, and the reader of a bare number cannot tell which tree it came
from. Where the raw output matters, put it in an =evidence/= file beside the
task and name that file in the Command column.

| What | Value | Command | Commit |
|------+-------+---------+--------|
| =compass.sql.tests= | 131 assertions in 38 cases | =compass.sql.tests= | this branch |
| New rule | RLS_003, =tenant_not_first_key= | =rls_coverage= version 3 | this branch |

* Notes

- The analysis recommended three checks. Only the tenant-first key is
compass's to build: the answer-shape corpus and the permission
classification are ORE Studio's data, and a compass rule over them would
have to name ORE Studio's files, which the codecs avoid. They are recorded
here so the ORE Studio side can pick them up with this page as the
evidence.

* Test Scenarios

Manual QA scenarios (scaffolded via =compass add test_scenario=)
that verify this task. Link
new ones here as they're created; the scenario doc itself links back
via its "Verifies task" field.

| Scenario | State | Notes |
|----------+-------+-------|
| | | |

* PRs

| PR | Title |
|----+-------|
| | |

* Review

| # | Comment summary | File | Decision | Notes |
|---+-----------------+------+----------+-------|
| | | | | |

* Result

=rls_coverage= gains a third rule: a table with =tenant_id= whose primary
key does not begin with it is reported, and the ignore file excuses one with
a reason. Its test covers a key that begins with =id=, one that begins with
=tenant_id=, and the ignored case. The other two checks are ORE Studio's,
for the reason in the Notes, and the i18n parity the analysis asked for
already exists in compass.web.
29 changes: 24 additions & 5 deletions projects/compass.sql/src/codecs/rls_coverage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,17 @@ namespace ct = compass::codec::types;
constexpr std::array<std::string_view, 1> sources{
"46AC210B-6BDF-49D2-BA47-35404AAEBA18"};

constexpr std::array<ct::rule, 2> rules{{
constexpr std::array<ct::rule, 3> rules{{
{"missing_rls", "A table with a tenant_id column enables row-level "
"security in a create script (RLS_001).", sources,
ct::blame_method::added},
{"missing_party_isolation", "A table with a party_id column has a "
"restrictive policy on party_id in a create script (RLS_002).",
sources, ct::blame_method::added}}};
sources, ct::blame_method::added},
{"tenant_not_first_key", "A table with a tenant_id column and a "
"primary key begins the key with tenant_id, so a row's tenant is "
"part of what identifies it (RLS_003).", sources,
ct::blame_method::added}}};

constexpr std::array<ct::option, 2> options{{
{"create_dir", "projects/ores.sql/create",
Expand Down Expand Up @@ -160,6 +164,9 @@ void map(std::string_view, std::string_view bytes, const ct::option_values&,
.number(static_cast<std::uint32_t>(t.columns.size()));
for (const auto& c : t.columns)
fact.text(c.name);
fact.number(t.primary_key.empty() ? 0u : 1u).text(
t.primary_key.empty()
? std::string_view{} : std::string_view(t.primary_key.front()));
}
fact.number(static_cast<std::uint32_t>(model.row_level_security.size()));
for (const auto& t : model.row_level_security)
Expand All @@ -178,6 +185,8 @@ struct table {
std::string_view path;
std::uint32_t offset = 0;
std::vector<std::string_view> columns;
bool has_key = false;
std::string_view key_first;
};

void reduce(std::span<const ct::scanned_file> files,
Expand All @@ -193,6 +202,8 @@ void reduce(std::span<const ct::scanned_file> files,
t.columns.resize(fact.number());
for (auto& c : t.columns)
c = fact.text();
t.has_key = fact.number() != 0;
t.key_first = fact.text();
tables.insert_or_assign(name, std::move(t));
}
for (auto n = fact.number(); n > 0; --n)
Expand Down Expand Up @@ -231,6 +242,13 @@ void reduce(std::span<const ct::scanned_file> files,
"enable row level security on the table and give it a "
"tenant isolation policy, or list it under RLS_001 in the "
"ignore file with its reason");
if (has("tenant_id") && t.has_key && t.key_first != "tenant_id" &&
!ignored("RLS_003", name))
report(2, "Table '" + table_name + "' has tenant_id but its "
"primary key does not begin with tenant_id",
"make tenant_id the first column of the primary key, or "
"list the table under RLS_003 in the ignore file with its "
"reason");
if (has("party_id") && !isolated.contains(name) &&
!ignored("RLS_002", name))
report(1, "Table '" + table_name + "' has party_id but no AS "
Expand All @@ -245,10 +263,11 @@ void reduce(std::span<const ct::scanned_file> files,

const ct::descriptor rls_coverage{
.name = "rls_coverage",
.version = 2,
.version = 3,
.summary = "Reports each table with tenant_id that does not enable "
"row-level security, and each with party_id that has no "
"restrictive party policy, as the er-diagram gate does.",
"row-level security or whose primary key does not begin with "
"tenant_id, and each with party_id that has no restrictive party "
"policy, as the er-diagram gate does.",
.reads = ct::inputs::of_types({}),
.options = options,
.rules = rules,
Expand Down
29 changes: 29 additions & 0 deletions projects/compass.sql/tests/codecs_rls_coverage_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,32 @@ TEST_CASE("a run after an edit to one script finds what a full run finds",
CHECK(tests::places(r.findings) == places{
{"projects/ores.sql/create/trading/trading_cash_create.sql", 1}});
}

TEST_CASE("a table whose primary key does not begin with tenant_id is "
"reported where it is created", "[codecs][rls_coverage]") {
const auto r = tests::run(codecs::rls_coverage, {
{std::string(root) + "plain/plain_keys_create.sql",
table("ores_plain_keyed_tbl",
" tenant_id uuid not null,\n id uuid not null,\n"
" primary key (id, tenant_id)") +
"alter table ores_plain_keyed_tbl enable row level security;\n"
"create policy p on ores_plain_keyed_tbl as restrictive using "
"(party_id = any(visible()));\n"},
{std::string(root) + "plain/plain_tenanted_create.sql",
table("ores_plain_tenanted_tbl",
" tenant_id uuid not null,\n id uuid not null,\n"
" primary key (tenant_id, id)") +
"alter table ores_plain_tenanted_tbl enable row level security;\n"},
{"projects/ores.sql/utility/validation_ignore.txt",
"RLS_003 ores_plain_ignored_tbl\n"},
{std::string(root) + "plain/plain_ignored_create.sql",
table("ores_plain_ignored_tbl",
" tenant_id uuid not null,\n id uuid not null,\n"
" primary key (id)") +
"alter table ores_plain_ignored_tbl enable row level security;\n"}});
CHECK(tests::places(r.findings) == places{
{"projects/ores.sql/create/plain/plain_keys_create.sql", 1}});
REQUIRE(r.findings.size() == 1);
CHECK(std::get<2>(r.findings[0]) == "Table 'ores_plain_keyed_tbl' has "
"tenant_id but its primary key does not begin with tenant_id");
}
Loading