Skip to content

docs(semantic-layer): adopt target architecture for Phase B - #2184

Merged
cyberantonz merged 4 commits into
constructorfabric:mainfrom
cyberantonz:docs/adopt-semantic-layer
Aug 4, 2026
Merged

docs(semantic-layer): adopt target architecture for Phase B#2184
cyberantonz merged 4 commits into
constructorfabric:mainfrom
cyberantonz:docs/adopt-semantic-layer

Conversation

@cyberantonz

@cyberantonz cyberantonz commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Adopts the semantic-layer design as the governing Phase B architecture for the presentation-layer split. Part of #1803.

What

Brings the design into the repo under docs/domain/semantic-layer/specs/:

Governance

Adopted as a governed in-repo doc following the metrics-domain precedent (docs/domain/metrics/specs/DESIGN.md, itself governing-but-unregistered). Converting it into the strict cfs sdlc DESIGN template (numbered sections, cpt-semantic-* IDs, Functional-Driver/NFR tables, a companion PRD) is a larger, separate task — deferred so the reformat does not distort the design before the schema-rewrite decision is committed.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Documentation
    • Added comprehensive Semantic Layer documentation covering architecture, requirements, implementation planning, APIs, data definitions, security controls, migration strategy, and operational considerations.
    • Documented compiler-driven metric computation, dataset-backed definitions, versioning, caching, discovery, editing, and validation.
    • Added guidance for phased migration from legacy metric infrastructure.
  • Configuration
    • Added Semantic Layer to the product documentation and artifact registry for improved discoverability and traceability.

Adopt the semantic-layer design (definitions-as-data, one compiler over
datasets, custom-dataset SQL escape hatch) as the governing Phase B design
for the presentation split, under docs/domain/semantic-layer/specs/.

- DESIGN.md / IMPLEMENTATION.md: the target architecture and its phased,
  parity-checked migration, adopted verbatim from the research.
- FINDINGS.md: adoption review — how the shipped YAML registry is this
  design's Phase 1 first step; the sub-issue re-scope (compiler-first drops
  the generated-SQL drift gate); and the org-scope authorization the design
  must name (Security: no people outside your org scope; Scope isolation: no
  other teams/cohorts), injected server-side beside tenancy.

Governed in-repo following the metrics-domain precedent; conversion into the
strict cfs sdlc DESIGN template (+ companion PRD) is deferred to avoid
distorting the design before the schema-rewrite decision is committed.

Part of constructorfabric#1803

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Anton Zelenov <antonz@constructor.tech>
@cyberantonz
cyberantonz requested a review from a team as a code owner August 4, 2026 10:33
@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds governed documentation for a compiler-first semantic layer. It defines semantic contracts, execution and storage rules, migration phases, discovery and editing APIs, authorization requirements, and architecture decisions.

Changes

Semantic layer architecture

Layer / File(s) Summary
Semantic model and governing contracts
docs/domain/semantic-layer/specs/README.md, docs/domain/semantic-layer/specs/PRD.md, docs/domain/semantic-layer/specs/DESIGN.md, docs/domain/semantic-layer/specs/REFERENCE.md, docs/domain/semantic-layer/specs/FINDINGS.md
Defines datasets, measures, metrics, custom datasets, catalogs, structured definitions, server-owned semantics, and the transitional YAML registry.
Compiler, storage, and authorization lifecycle
docs/domain/semantic-layer/specs/DESIGN.md, docs/domain/semantic-layer/specs/PRD.md
Specifies compiler execution, time handling, caching, definition storage, database schemas, API contracts, and compiler-injected authorization scopes.
Implementation phases and runtime surfaces
docs/domain/semantic-layer/specs/IMPLEMENTATION.md, docs/domain/semantic-layer/specs/DESIGN.md, docs/domain/semantic-layer/specs/FINDINGS.md
Defines migration phases, validation, legacy infrastructure removal, discovery, runtime editing, observability, and adoption dependencies.
Governed artifacts and registry wiring
.cf-studio/config/artifacts.toml, docs/domain/semantic-layer/specs/DESIGN.md, docs/domain/semantic-layer/specs/FINDINGS.md
Registers the semantic-layer system and records document status, traceability, adoption decisions, and unresolved design items.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested reviewers: ktursunov

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the semantic-layer architecture adoption for Phase B, which matches the pull request's main objective.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Scope isolation must hold across cohort membership: an R&D member and a
Sales member who share a tag are never in the same cohort. The org chart
gates cohort composition; tags refine within the boundary, never across it.
Notes the current gap (only org_unit cohorts are implicitly org-scoped;
arbitrary/tag cohort keys are not yet intersected with org visibility) and
where it must be enforced (cohort dataset + compiler injected scope, constructorfabric#1980).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Anton Zelenov <antonz@constructor.tech>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/domain/semantic-layer/specs/DESIGN.md`:
- Around line 48-54: Add the text language tag to both diagram code fences:
docs/domain/semantic-layer/specs/DESIGN.md lines 48-54 and
docs/domain/semantic-layer/specs/IMPLEMENTATION.md lines 295-299. Keep the
diagram contents unchanged.
- Around line 429-434: Update the per-input read decision described in the
cache-serving flow to check definition availability before selecting cached rows
or compiling live data. When availability is not available, return the stored
unavailable error; only allow cached or live execution when availability is
available, while preserving the existing policy, version, and coverage checks.
- Around line 418-424: Clarify the custom-dataset rebuild semantics in the
DESIGN.md section around the definition DAG refresh: permit serving the previous
table only when refresh fails without a semantic definition-version change.
After a version bump, invalidate the superseded table and require reads to use
the live view or return unavailable; do not allow failed rebuilds to serve
superseded custom-dataset data.
- Around line 162-175: Align percentile support across all three documented
sites: in docs/domain/semantic-layer/specs/DESIGN.md lines 162-175, add the
complete percentile aggregation contract to the measure schema; in
docs/domain/semantic-layer/specs/DESIGN.md lines 230-235, update the
expressiveness claim to include percentile; and in
docs/domain/semantic-layer/specs/IMPLEMENTATION.md lines 119-124, document the
required validator, compiler, and storage work for percentile.

In `@docs/domain/semantic-layer/specs/FINDINGS.md`:
- Around line 81-84: Update the stale DESIGN.md reference in FINDINGS.md to
point to the document’s actual unnumbered Principles heading, or revise
DESIGN.md to add the referenced “§2 (Principles & Constraints)” structure;
ensure the Compiler section reference also matches an existing section.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: b08f5d60-b115-4568-b9df-577957390f82

📥 Commits

Reviewing files that changed from the base of the PR and between 5a54e30 and a71b75f.

📒 Files selected for processing (4)
  • docs/domain/semantic-layer/specs/DESIGN.md
  • docs/domain/semantic-layer/specs/FINDINGS.md
  • docs/domain/semantic-layer/specs/IMPLEMENTATION.md
  • docs/domain/semantic-layer/specs/README.md

Comment thread docs/domain/semantic-layer/specs/DESIGN.md
Comment thread docs/domain/semantic-layer/specs/DESIGN.md Outdated
Comment thread docs/domain/semantic-layer/specs/DESIGN.md Outdated
Comment thread docs/domain/semantic-layer/specs/DESIGN.md Outdated
Comment thread docs/domain/semantic-layer/specs/FINDINGS.md Outdated
Author template-conformant PRD.md and DESIGN.md for the semantic layer and
register them as cfs sdlc artifacts (new `semantic-layer` system in
artifacts.toml). Both pass per-artifact cfs validation (toc + validate +
check-language) and add zero new whole-registry errors.

- PRD.md / DESIGN.md: the governed artifacts (cpt-semantic-layer-* IDs),
  distilled from the reference narrative; injected scopes (tenant, org-scope
  entity visibility, cohort isolation) are first-class FRs/NFRs, a principle,
  a component, and a sequence.
- REFERENCE.md: the original design narrative, kept verbatim as the deep
  rationale the governed specs cite.
- FINDINGS.md: adds the three open review items (percentile capability;
  no serving a superseded custom-dataset after a version bump; gate cache
  reads on availability) and points at the governed specs.
- Fold in CodeRabbit doc fixes: language-tag the diagram fences; fix the
  stale section reference.

Part of constructorfabric#1803

Signed-off-by: Anton Zelenov <antonz@constructor.tech>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/domain/semantic-layer/specs/DESIGN.md`:
- Around line 678-688: Update the dataset schema around
datasets.database_relation to model warehouse relations and custom SQL as
distinct source variants, adding a source discriminator with separate
relation_name and validated select_sql fields. Move source-specific availability
and captured role-annotated schema into the selected variant, and update the
surrounding contract descriptions to reflect the distinct validation, quoting,
lineage, and execution paths.
- Around line 753-770: The measure_cache schema must store mergeable state
rather than a single numeric value for non-additive measures. Update the measure
cache design around measure_cache and its PK/additional-info rules to define
aggregation-specific state shapes and merge rules, including sum/count
components for avg and subject identity or equivalent mergeable distinct state
for count_distinct, before permitting those aggregations to be cached.
- Around line 753-770: Update the measure_cache schema and related semantics to
include insight_tenant_id UUID in each row, the primary key, partitioning,
refresh/invalidation scope, and cache-read predicates so cached work is
tenant-scoped. Extend the cache identity to include reporting timezone, or
explicitly define and use a canonical UTC representation consistently.

In `@docs/domain/semantic-layer/specs/PRD.md`:
- Around line 271-275: The Materialization Cache requirement currently permits
live computation for unavailable definitions. Update the PRD requirement and its
corresponding DESIGN.md rule to return the stored unavailable-definition error
without cached or live rows, while retaining live fallback only for stale
versions, uncovered ranges, and disabled policy.
- Around line 185-190: Update the custom-dataset deletion requirement in the
gated SQL layer specification to block deletion whenever any definition
references the dataset, including direct references from dependent custom
datasets, not only measure references. Align the wording with the
dependency-protection behavior specified by DESIGN.md.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 7b662fa2-f4b1-4fae-a7c3-d7ded549e0d3

📥 Commits

Reviewing files that changed from the base of the PR and between a71b75f and 19c4a20.

📒 Files selected for processing (7)
  • .cf-studio/config/artifacts.toml
  • docs/domain/semantic-layer/specs/DESIGN.md
  • docs/domain/semantic-layer/specs/FINDINGS.md
  • docs/domain/semantic-layer/specs/IMPLEMENTATION.md
  • docs/domain/semantic-layer/specs/PRD.md
  • docs/domain/semantic-layer/specs/README.md
  • docs/domain/semantic-layer/specs/REFERENCE.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • docs/domain/semantic-layer/specs/IMPLEMENTATION.md

Comment on lines +678 to +688
| Column | Type | Description |
|--------|------|-------------|
| `key` | String | Stable dataset identifier |
| `database_relation` | String | Warehouse database + relation (or the registered custom SELECT) |
| `read_discipline` | Enum | Dedup strategy the compiler inherits |
| `retention_horizon` | Interval | History depth part of the served contract |
| `origin` | Enum | `product` \| `custom` |

**PK**: `key`

**Additional info**: Custom-dataset rows carry the validated SELECT and its captured, role-annotated schema; availability state is stored on the row and read by serving/discovery.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Separate relation identifiers from custom SQL bodies.

datasets.database_relation is defined as either a warehouse relation or a registered custom SELECT. These values require different validation, quoting, lineage, and execution paths.

Add a source discriminator and separate fields such as relation_name and validated select_sql. Keep availability and captured schema attached to the selected source variant.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/domain/semantic-layer/specs/DESIGN.md` around lines 678 - 688, Update
the dataset schema around datasets.database_relation to model warehouse
relations and custom SQL as distinct source variants, adding a source
discriminator with separate relation_name and validated select_sql fields. Move
source-specific availability and captured role-annotated schema into the
selected variant, and update the surrounding contract descriptions to reflect
the distinct validation, quoting, lineage, and execution paths.

Comment thread docs/domain/semantic-layer/specs/DESIGN.md
Comment thread docs/domain/semantic-layer/specs/PRD.md
Comment thread docs/domain/semantic-layer/specs/PRD.md
@cyberantonz
cyberantonz enabled auto-merge August 4, 2026 11:55
@cyberantonz
cyberantonz added this pull request to the merge queue Aug 4, 2026
Merged via the queue into constructorfabric:main with commit a5ab5d9 Aug 4, 2026
21 checks passed
@cyberantonz
cyberantonz deleted the docs/adopt-semantic-layer branch August 4, 2026 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants