Skip to content

feat: ship the standard SQL editor overhaul#204

Draft
Light2Dark wants to merge 39 commits into
mainfrom
codex/standard-stabilization
Draft

feat: ship the standard SQL editor overhaul#204
Light2Dark wants to merge 39 commits into
mainfrom
codex/standard-stabilization

Conversation

@Light2Dark

@Light2Dark Light2Dark commented Jul 26, 2026

Copy link
Copy Markdown
Member

Summary

  • promote the language-service architecture to the standard package API with a focused ./codemirror entrypoint
  • ship robust relation, column, namespace, CTE, scope, query-binding, statement-boundary, and catalog lifecycle primitives
  • make completion compose with CodeMirror SQL keywords and host sources, distinguish typing triggers, and handle slow-provider refresh/cancellation
  • replace the manual demo wiring with the real editor adapter and an interactive schema-aware playground
  • enforce strict package, browser, worker-isolation, coverage, and large-document performance gates

Why

The previous standard surface and demo did not expose the completed overhaul, suppressed language-provided completion sources, and provided no CI protection for the reported typing slowdown. This consolidates the completed architecture behind one stable API and makes the default development experience representative of real consumers such as marimo.

Evidence

  • 1,706 unit/performance tests and 17 Chromium tests pass
  • coverage: 97.63% statements, 96.35% branches, 99.62% functions, 97.83% lines
  • 1 MiB warmed edit benchmark: ~0.79 ms mean; CI gates multi- and single-statement p95 below 8 ms
  • packed-consumer, SSR/core bundle, parser-worker placement, integrity, typecheck, lint, and demo-build checks pass

Supersedes #203 and advances #169.


Summary by cubic

Ships the new standard SQL editor: a fast shared language service with a first‑class CodeMirror adapter. Also fixes a CodeQL cursor marker alert.

  • New Features

    • Stable service API in @marimo-team/codemirror-sql and adapter in @marimo-team/codemirror-sql/codemirror.
    • Built‑in dialects via duckdbDialect(), postgresDialect(), bigQueryDialect(), dremioDialect().
    • Relation, namespace, and column completion with CTE visibility, deterministic ranking, cancellation, and refresh tokens; composes with CodeMirror SQL keywords and external sources.
    • Synchronous statement boundary queries for exact execution ranges.
    • Parser runs in an isolated, lazily loaded worker; editor stays responsive even when the parser isn’t ready.
    • New playground demo wired to the real adapter; added statement gutter and optional rich completion info.
    • CI adds integrity, changed‑code coverage, and performance gates for large documents and degraded‑editing budgets.
  • Migration

    • Create a shared service: const service = createSqlLanguageService({ dialects: [duckdbDialect(), ...] }).
    • Install the adapter per editor: const support = sqlEditor({ service, initialContext: { dialect: 'duckdb', catalog: { scope: '...' } } }); add support.extension to your EditorView.
    • Replace prior sqlExtension/sqlCompletion usage with the new adapter; pass context/embedded regions via support.setContext or its effects; optional infoResolver allows rich completion info.

Written for commit 8773014. Summary will update on new commits.

Review in cubic

Establishes the next-major engineering foundation before production
architecture changes. Adds the research and implementation plans, split
unit/browser configs, honest aggregate coverage ratchets, 95%
changed-code coverage, governed known failures, strict vNext typing,
clean builds, deterministic packed-consumer validation, Node floor
coverage, and release-gate parity.\n\nValidated locally: lint,
integrity, all TypeScript scopes, 587 unit tests plus one governed
expected failure, aggregate and changed coverage, Chromium browser
smoke, packed consumer/runtime parse, demo build, actionlint, and two
independent adversarial review loops.

<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Sets up the vNext quality foundation with strict typing, split
unit/browser tests, honest coverage gates (aggregate + changed-code),
governed known failures, and deterministic package smoke tests that
preserve the `pnpm` version. Hardens CI/release and unblocks the next
major architecture work.

- **New Features**
- CI: pin Node 20.19.0 and `pnpm` 10.28.2 with version checks; disable
Node-managed PM version enforcement; add concurrency with
cancel-in-progress; fetch full git history; add lint and test integrity
gates; split unit and headless browser runs; enforce aggregate and
changed-code coverage.
- Release: add a compatibility job that runs `pnpm pack` and a consumer
smoke test; preserve and verify `pnpm` 10.28.2 across the smoke path;
`autofix.yml` also runs on `dev-refactor`.
- Known failures governed via `test/known-failures.json` with owner and
expiry.
  - Added vNext docs: `SQL_EDITOR_RESEARCH.md` and `implementation.md`.

- **Refactors**
- Split TS configs and typecheck scripts for source, legacy tests, vNext
tests, and demo; vNext tests use stricter rules.
- Extracted `vitest` configs; `vite.config.ts` now only builds the demo.
- Minor ESM/typing fixes in demo and tests; export test now uses `pnpm
pack`.

<sup>Written for commit ebbeb2f.
Summary will update on new commits.</sup>

<a
href="https://cubic.dev/pr/marimo-team/codemirror-sql/pull/170?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>

<!-- End of auto-generated description by cubic. -->
Defines the accepted vNext capability charter and ADR 0001 before
runtime implementation. The decision establishes a shared
framework-independent language service, one disposable session per
document, atomic revision-guarded updates, original-document UTF-16
ranges, explicit request outcomes, scoped catalog epochs, provider
source forms, and a thin CodeMirror lifecycle adapter.\n\nThe contracts
were derived from the repository research and current marimo
integration, then iterated through three fresh-context design reviews
and two blocker-resolution loops. Local lint, typecheck, test integrity,
workflow validation, diff checks, and aggregate coverage pass.

<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Adds ADR 0001 and a capability charter defining the vNext SQL
language-service contracts. Establishes a framework-agnostic service
with per-document sessions, atomic revision-guarded updates,
original-document UTF-16 ranges, unified request outcomes, and a thin
`CodeMirror` adapter ahead of runtime work.

- **New Features**
- Shared `SqlLanguageService` and per-document `SqlDocumentSession` with
atomic text/context updates.
- Opaque session revisions; all results carry a revision and require a
currency check before apply.
- Standard UTF-16 half-open original-document ranges and validated
incremental changes.
- Unified request outcomes (ready, unavailable, cancelled, failed) with
clear cancellation and provider reports.
- Narrow async provider boundary (no editor/DOM), bounded sync budget,
worker-friendly guidance.
- Catalog epochs with scoped invalidation; template masking/mapping
preserving original offsets; thin `CodeMirror` adapter; walking-skeleton
scope (relation completion first).

<sup>Written for commit 66853b3.
Summary will update on new commits.</sup>

<a
href="https://cubic.dev/pr/marimo-team/codemirror-sql/pull/171?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>

<!-- End of auto-generated description by cubic. -->
## Summary

- add the framework-independent `@marimo-team/codemirror-sql/vnext`
entry point
- implement immutable dialect registration, one session per document,
opaque revision identity/metadata, discriminated atomic updates, and
terminal disposal
- validate and own bounded plain-data contexts; normalize hostile
JavaScript inputs and guard reentrant update/open lifecycle races
- add compile-only API tests, 83 runtime invariant tests, current-API
documentation, and packed isolation smoke coverage without CodeMirror or
node-sql-parser available

## Evidence

- `pnpm run typecheck`
- `pnpm exec oxlint`
- `pnpm run test:coverage` (670 passed, 1 governed expected failure)
- changed vNext runtime coverage: 99% statements, 98.47% branches, 100%
functions, 98.99% lines
- `pnpm run test:browser`
- `pnpm run test:package`
- `pnpm run test:integrity`
- `pnpm run demo`

## Adversarial review

Two independent reviewers challenged correctness and API design. The
first loop found and reproduced reentrant revision overwrite,
service-open disposal, dialect TOCTOU, variance, and optional-property
issues. The implementation and tests were redesigned; both reviewers now
approve with no blocker/high findings.

<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Adds vNext atomic document sessions in
`@marimo-team/codemirror-sql/vnext` with immutable dialects,
per-document sessions, and strict revision/lifecycle invariants.
Strengthens smoke tests with dependency isolation and rollback checks,
and exports `./vnext` for consumers.

- **New Features**
- Public service/session operations are exposed as readonly, bound
function fields to remain safe when passed as callbacks or destructured.
- Packaging/docs/tests: new session primitives guide, `package.json`
`./vnext` subpath export, and smoke tests that run without `@codemirror`
or `node-sql-parser`, verify `vnext` exports, revision identity, and
validate isolation rollback.

- **Bug Fixes**
- Hardened API invariants: reentrant-update guard, early stale-revision
checks before context inspection, idempotent terminal disposal for
session/service, stricter optional-field handling
(`exactOptionalPropertyTypes`), and consistent `SqlSessionError` codes
when normalizing accessors/proxies.

<sup>Written for commit ce6d09a.
Summary will update on new commits.</sup>

<a
href="https://cubic.dev/pr/marimo-team/codemirror-sql/pull/172?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>

<!-- End of auto-generated description by cubic. -->
## Summary

- publish the minimal `SqlTextRange` UTF-16 contract and make
`SqlTextChange` extend it
- add internal immutable identity/masked source snapshots with explicit
`originalText` and `analysisText`
- validate and freeze bounded embedded regions without invoking
accessors or Proxy `get` traps
- preserve length and every CR/LF offset while masking every other
UTF-16 code unit
- store source snapshots in document sessions, reusing them only for
context-only updates
- document the intentional boundary: no public transformer or source-map
SPI yet
- request Copilot once per PR, without later re-requests

## Invariants and risk

- ranges are safe-integer, in-bounds, half-open UTF-16 offsets
- embedded regions are non-empty, ordered, non-overlapping, and capped
at 10,000
- source text is capped at 16 Mi UTF-16 code units
- masking uses bounded 64 Ki-code-unit chunks and cannot allocate per
newline
- arbitrary values thrown by hostile Proxy traps are normalized without
inspecting them
- document updates create a new source snapshot; context-only updates
retain the exact source identity

## Evidence

- `pnpm run typecheck`
- `pnpm exec oxlint`
- `pnpm run test:coverage` (713 passed, 1 governed expected failure)
- changed runtime coverage: 98.78% statements, 97.75% branches, 100%
functions, 98.76% lines
- deterministic randomized UTF-16 masking/range round trips
- full 16,777,216-code-unit CRLF mask and 10,000-region smoke cases
- full-limit newline mask succeeds under `node --max-old-space-size=128`
- `pnpm run test:browser`
- `pnpm run test:package`
- `pnpm run test:integrity`
- `pnpm run demo`

## Adversarial review

Two independent exact-head reviewers challenged correctness and
performance/API design. The first loop found a newline-density memory
amplification and hostile thrown-Proxy escape. Both were redesigned and
regression-tested. Both reviewers approve exact SHA
`1993a6cdca85ec9d3b8a1ddaab5dda0188b85fab` with no blocker, high, or
medium findings.


<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Add internal source coordinate primitives and length-preserving masking
to support safe UTF-16 ranges and embedded-region analysis. Export
`SqlTextRange` and update sessions to use immutable source snapshots,
reusing them for context-only updates.

- New Features
  - Export `SqlTextRange`; make `SqlTextChange` extend it.
- Add immutable source snapshots with `originalText` and `analysisText`,
plus length-preserving masking of embedded regions (CR/LF offsets
preserved). No transformer or source-map SPI yet.
- Validate and freeze inputs with strict caps (16 Mi code units, 10k
regions) and accessor-safe normalization.
- Store source snapshots in document sessions and reuse them on
context-only updates.

<sup>Written for commit 1993a6c.
Summary will update on new commits.</sup>

<a
href="https://cubic.dev/pr/marimo-team/codemirror-sql/pull/173?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>

<!-- End of auto-generated description by cubic. -->
## Summary

- add an internal synchronous parser-free statement partition and
binary-search cursor lookup
- preserve explicit half-open ownership for trivia, terminators, empty
slots, EOF, and left/right affinity
- add bounded PostgreSQL, DuckDB, BigQuery, and Dremio lexical profiles
with opaque fail-closed suffixes
- keep incremental reuse, session attachment, parser semantics, and
public APIs out of this slice

## Safety and performance

- cap materialized slots at 10,000 and collapse the remainder into one
opaque slot
- bound dollar delimiters and retain no statement substrings
- conservatively handle Unicode dollar tags and prefix boundaries
- fail closed for BigQuery procedural bodies, custom delimiters, and
PostgreSQL BEGIN ATOMIC bodies
- 16 MiB scans under a 128 MiB heap: about 44 ms ASCII, 61 ms Latin, 47
ms astral

## Evidence

- exact head: 56b57ea
- focused statement-index tests: 82 passed
- full suite: 795 passed, 1 governed expected failure
- changed coverage: 98.76% statements, 96.97% branches, 100% functions,
98.75% lines
- strict typecheck, non-mutating lint, test integrity, demo build,
packed-package smoke, and Chromium passed
- lexical/correctness reviewer: APPROVE exact head, no
blocker/high/medium findings
- performance/API reviewer: APPROVE exact head, no blocker/high/medium
findings

## Public API

No vNext public exports or generated root declarations are added. The
full scanner remains the correctness oracle for a later independently
reviewed incremental slice.

<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Adds an internal, dialect-aware SQL statement index for vNext. It
partitions `analysisText` into exact half-open slots with binary-search
cursor lookup and bounded resources, with no public API changes.

- **New Features**
- Exact slot partitioning and ownership: terminators associate left;
trailing trivia moves to the next slot; explicit empty slots are
preserved.
- Dialect profiles for PostgreSQL, DuckDB, BigQuery, and Dremio;
protects strings/comments (e.g., dollar-quoting, E-strings,
triple/raw/backtick, nested comments) and fails closed for custom
delimiters, BigQuery procedural blocks, and PostgreSQL BEGIN ATOMIC.
- Left/right-affinity lookup via binary search with explicit EOF
behavior for terminated vs open statements.
- Bounded resources: up to 10,000 materialized slots; bounded
dollar-quote tag length; no statement substring copies; frozen partition
data.
- Reports unterminated strings/comments without exposing internal
semicolons; operates on `analysisText` so UTF-16 offsets match the
original text under the current masking transform; dialect behavior is
keyed by internal profile identity, not a caller-controlled ID.

<sup>Written for commit 2ca3c25.
Summary will update on new commits.</sup>

<a
href="https://cubic.dev/pr/marimo-team/codemirror-sql/pull/174?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>

<!-- End of auto-generated description by cubic. -->
## Summary

- update the dialect-aware statement index incrementally from trusted
analysis-coordinate edits while preserving the full scan as the oracle
- add a private lazy per-session index cache with atomic
invalidation/reuse rules
- replace structural dialect definitions with opaque built-in factory
handles, keeping lexical profiles and indexes out of the public API

## Correctness and safety

- conservative restart at the old slot at or left of the earliest edit
- convergence only at an exact terminated boundary after the final edit
- exact full-oracle fallback for inconsistent metadata or absent
convergence
- global 10,000-slot and opaque-suffix behavior preserved
- monotonic convergence cursor keeps resource-cap recovery linear
- no source text or history retained by the cache

## Validation

- 833 unit tests passed; 1 governed expected failure
- 33 incremental tests with deterministic differential sequences across
all four profiles
- 80,000 additional adversarial differential edits matched the full
oracle
- changed coverage: 98.78% statements, 97.00% branches, 100% functions,
98.77% lines
- typecheck, oxlint, integrity, browser, demo, and packed-package smoke
passed
- 1 MiB benchmark: full scan about 2.2-2.5 ms, middle edit about 0.028
ms, prefix shift about 0.11 ms
- resource-cap recovery about 1.35-1.46 ms after fixing the reviewed
quadratic path

## Review

Two independent exact-SHA reviewers approve
2e83d17 with no unresolved blocker,
high, or medium findings.

<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Adds incremental statement indexing with a lazy, per-session cache so
edits update indexes in microseconds, while a full scan remains the
correctness fallback. Replaces caller-defined dialect objects with
built-in opaque dialect handles that bind lexical behavior internally.

- New Features
- Incremental updates from trusted analysis-coordinate edits; reuse
unchanged prefix and reuse/shift suffix at exact terminated boundaries,
with full-oracle fallback.
- Private per-session statement-index cache: reused on context-only
updates (same profile) and same-text replacements; incrementally updated
on trusted identity-source changes; cleared on profile change or changed
replacements; no source text or history retained.
- Built-in dialect factories return frozen opaque singletons:
`duckdbDialect()`, `postgresDialect()`, `bigQueryDialect()`,
`dremioDialect()`; handles are validated, local to the package instance,
and don’t cross workers/processes.
- Bench and tests: `pnpm run bench:statement-index`; extensive unit,
randomized differential, and session cache tests.

- Migration
- Replace `defineSqlDialect(...)` and `SqlDialectDefinition` with
built-in handles and `SqlDialect`.
- Before: `createSqlLanguageService({ dialects: [defineSqlDialect({ id:
"duckdb", displayName: "DuckDB" })] })`
    - After: `createSqlLanguageService({ dialects: [duckdbDialect()] })`
- Keep using the handle’s `.id` string in document context: `{ dialect:
dialect.id }`.
- Do not copy/serialize/fabricate dialects; pass authentic handles from
the same `@marimo-team/codemirror-sql/vnext` instance (handles don’t
cross workers/processes).

<sup>Written for commit ce94176.
Summary will update on new commits.</sup>

<a
href="https://cubic.dev/pr/marimo-team/codemirror-sql/pull/175?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>

<!-- End of auto-generated description by cubic. -->
## Summary

- define the internal normalized syntax state and parser-analysis
contracts
- bind every artifact, diagnostic, analysis, conformance claim, and
parser to exact source plus authenticated backend/configuration/dialect
authority
- add one mandatory parser runner that normalizes failures and returns
runner-created analyzed state
- add runtime and compile-time invariant tests plus ADR 0002
- keep the stable vNext export surface unchanged

## Safety and correctness

- direct invalidity requires matching conformance authority
- compatibility rejection cannot become authoritative invalid SQL
- malformed locations fail closed instead of becoming unavailable
- parser input is capped at 1 MiB; messages, diagnostics, and
limitations are bounded
- hostile custom iterators cannot bypass collection limits
- full AbortSignal runtime validation matches the declared callback
surface
- raw ASTs and backend payloads remain private

## Validation

- 875 unit tests passed, with 1 governed expected failure
- changed syntax.ts coverage: 97.68% statements, 95.42% branches, 100%
functions, 97.66% lines
- full typecheck and oxlint passed
- browser tests passed
- test integrity passed
- packed-consumer smoke passed
- demo build passed
- two independent adversarial reviewers approved exact commit db43409
after four fix/review loops

## Scope

Internal contract only. This PR does not add a parser adapter,
cache/session wiring, catalog types, or stable public exports.

<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Defines an internal normalized SQL syntax contract with a single parser
runner that authenticates outputs and separates lexical eligibility from
parser analysis. Strengthens cancellation: preserves the exact
`AbortSignal` reason, rejects pre-aborted requests without invoking the
backend, and races cancellation vs. backend completion correctly; public
vNext exports stay the same and ADR 0002 documents the boundary.

- New Features
  - Normalized statement states and parser analyses.
- Branded statement-relative ranges; parser receives only exact
statement text and an AbortSignal.
- Parser, authority, and conformance identities; artifacts/diagnostics
bound to exact source and authority; backend data stays private.
- Runner validates identities, normalizes sync/async failures, handles
cancellation races, and returns authenticated analyzed state. Adds ADR
0002 and tests; no change to stable exports.

- Safety
- 1 MiB input cap; bounded messages and collections; hostile iterators
contained.
- `AbortSignal` surface validated (cross-realm supported); preserves
exact abort reason; pre-aborted requests skip backend; late aborts don’t
override completed backend outcomes.
- Malformed locations and fabricated results fail closed as
malformed-output.
- Compatibility rejection is never treated as invalid; invalidity
requires matching conformance and authority identities.

<sup>Written for commit ed58bac.
Summary will update on new commits.</sup>

<a
href="https://cubic.dev/pr/marimo-team/codemirror-sql/pull/176?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>

<!-- End of auto-generated description by cubic. -->
## Summary
- add an internal normalized node-sql-parser adapter for PostgreSQL,
BigQuery, and DuckDB compatibility evidence
- pin node-sql-parser 5.4.0 and load only dialect-specific builds
through a race-safe pure-Node loader
- keep all successful evidence non-conformant, retain ASTs privately,
and fail closed in browser/worker/DOM-shim realms pending
dedicated-worker support
- document the evidence, execution, resource, packaging, and
global-cleanup boundaries in ADR 0003
- add adversarial unit/browser coverage and validated warm parser
benchmarks

## Correctness policy
- PostgreSQL/BigQuery acceptance: parsed/compatibility with
partial-artifact
- PostgreSQL/BigQuery rejection: unsupported/uncovered-construct, never
invalid
- DuckDB acceptance: parsed/compatibility with dialect-compatibility +
partial-artifact
- DuckDB rejection: unsupported/compatibility-rejected
- Dremio: no adapter

## Validation
- 971 tests passed, 1 expected failure
- changed coverage: 99.13% statements, 99.35% branches, 100% functions,
99.12% lines
- full strict typecheck and non-mutating lint
- Chromium browser suite
- isolated package smoke and demo build
- test integrity check
- preflight-validated parser benchmark
- two independent adversarial review loops approved the final exact tree

<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Add an internal `node-sql-parser` adapter for PostgreSQL and BigQuery
with a DuckDB compatibility path that returns small, private artifacts
under strict bounds and pure-Node loading. Also fixes and documents a
test spelling false positive, and keeps the CI report spelling-clean.

- **New Features**
- Evidence policy: PostgreSQL/BigQuery accept -> parsed/compatibility
(partial); reject -> unsupported/uncovered-construct. DuckDB uses the
PostgreSQL build: accept -> parsed/compatibility (dialect-compatibility,
partial); reject -> unsupported/compatibility-rejected.
- Bounded artifacts: only statement kind + full range; backend ASTs kept
private.
- Resource/placement: 16 KiB statement limit; synchronous parse;
cancellation checked before/after load and after parse; not wired to
sessions.
- Execution realm safety: pure Node only with race-safe loader and
global cleanup; fails closed in window/worker/DOM-shim realms.
- Docs and tests: added ADR 0003, linked ADR 0002, and a vNext adapter
doc; Node and browser tests plus a warm parser benchmark and
`bench:parser-adapter` script; fixed spelling CI false positive and kept
`state/artifacts/reports/pr-177-spelling-ci.md` spelling-clean.

- **Dependencies**
- Pin `node-sql-parser` to `5.4.0` and load only `build/postgresql.js`
and `build/bigquery.js`.

<sup>Written for commit 2543624.
Summary will update on new commits.</sup>

<a
href="https://cubic.dev/pr/marimo-team/codemirror-sql/pull/177?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>

<!-- End of auto-generated description by cubic. -->
## Summary

- accept ADR 0004 for browser-first isolated parser execution
- add a production-shaped Vite 8 / Chromium placement harness for one
lazy, service-owned parser worker
- prove exact PostgreSQL and BigQuery deep builds remain separate lazy
chunks while core and `/vnext` remain parser/worker-free
- record cold/warm phase timings, bundle ceilings, strict-CSP execution,
exact global restoration, cleanup poisoning, and frozen offline fixture
installation

## Scope

This is an evidence gate, not production session wiring. The worker
implementation remains fixture-owned in this PR. The following protocol
PR must move the worker behind a packed optional integration, remove the
fixture's direct parser dependency, and preserve the accepted
packaging/realm boundaries.

## Evidence

- exact `pnpm pack` archive imported under hostile SSR globals
- root and `/vnext` core graph contains no parser modules or orphan
JavaScript
- one static module worker handles PostgreSQL then BigQuery
- page graph contains no parser grammar
- worker graph contains only `node-sql-parser/build/postgresql.js` and
`node-sql-parser/build/bigquery.js`
- grammar chunks are separate, lazy, and transitively budgeted
- real Chromium execution under `worker-src 'self'`
- worker-local `NodeSQLParser` and `global` descriptors restored exactly
- reversible cleanup keeps the loader reusable; failed cleanup poisons
it
- nested fixture install is frozen and offline
- clean temporary root install plus nested offline harness passed
against a brand-new pnpm store

## Validation

- `pnpm run test:worker-placement`
- `pnpm run typecheck`
- `pnpm exec oxlint`
- `pnpm run test:integrity`
- `pnpm test` — 971 passed, 1 expected failure
- `pnpm run test:coverage` — vNext 98.67% statements / 97.13% branches /
100% functions / 98.66% lines
- `pnpm run test:browser`
- `pnpm run test:package`
- `pnpm run demo`
- two independent exact-head adversarial reviewers approved `bd5a08f`
with zero findings

Part of #169.

<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Accepts ADR 0004 for isolated browser parser execution and adds a Vite
8/Chromium harness that proves a single, lazy, service-owned module
worker with PostgreSQL/BigQuery loaded as separate chunks under a strict
CSP; also hardens the fixture to clean up worker listeners/timers to
avoid leaks. CI now fails closed on size, graph, SSR-safety, and
readiness regressions. Part of #169.

- **New Features**
  - Added ADR 0004; updated ADR 0003 and vNext docs to reference it.
- Added `scripts/worker-placement.mjs` to `pnpm pack`, build a nested
fixture, serve with `worker-src 'self'`, run Chromium via `playwright`,
record timings/sizes, and verify: lazy worker creation, no parser in
core/page graphs, separate lazy `node-sql-parser/build/postgresql.js`
and `.../bigquery.js` chunks, exact global restoration, and cleanup
poisoning.
- Enforces ceilings: PostgreSQL 68 KiB gzip, BigQuery 50 KiB gzip,
worker total 120 KiB gzip / 570 KiB raw.
  - CI: added `pnpm run test:worker-placement` step.

- **Dependencies**
- Fixture pins `vite@8.0.13`, `playwright@1.61.1`, and
`node-sql-parser@5.4.0` to match the packed transitive; runs offline
with a frozen lockfile.
- No runtime changes for consumers; adds the test harness and script
only.

<sup>Written for commit 8b1ea20.
Summary will update on new commits.</sup>

<a
href="https://cubic.dev/pr/marimo-team/codemirror-sql/pull/178?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>

<!-- End of auto-generated description by cubic. -->
## Summary

- extract module decoding, parser invocation, result validation, and
error normalization into an internal realm-neutral backend
- preserve Node-specific realm validation, module loading, cleanup,
parser authority, and private AST ownership in the existing adapter
- add exhaustive backend contract tests covering bounds, cancellation
checkpoints, retry caching, hostile values, and ambient neutrality
- document the host/engine responsibility boundary

No public export, session wiring, worker protocol, or user-visible API
is added.

## Validation

- 1,041 unit tests passed; 1 intentional expected failure
- vNext coverage: 98.54% statements, 97.06% branches, 100% functions,
98.53% lines
- new backend coverage: 100% statements, branches, functions, and lines
- source and test TypeScript checks
- oxlint and test-integrity checks
- Chromium browser tests
- exact packed-consumer smoke test
- isolated worker placement and bundle-budget harness
- demo production build
- parser adapter benchmark
- git diff check

## Independent review

Two independent adversarial reviewers approved exact commit 96bd2ce with
zero actionable findings.

<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Extracted a new internal backend for `node-sql-parser` and rewired the
Node adapter to call it. No public API changes.

- **Refactors**
- New `node-sql-parser-backend`: decodes module, runs `astify`,
validates output, and normalizes errors; no Node/window/worker refs.
- Node adapter now only handles realm checks, `require` loading,
cleanup, parser authority, and private AST ownership; uses backend
outcomes.
- Unified backend outcomes; concurrent load de‑dup and retry cache;
enforces `MAX_NODE_SQL_PARSER_STATEMENT_LENGTH`.
- Accepts constructor/`default`/`module.exports`/named `Parser`; ignores
accessors/proxies and redacts private data.
- Added backend tests (bounds, cancellation, retry, hostile values,
ambient neutrality) and documented the host/engine boundary.

- **Bug Fixes**
- Validate AST array lengths, rejecting spoofed or non‑integer length
descriptors.

<sup>Written for commit 08a9d67.
Summary will update on new commits.</sup>

<a
href="https://cubic.dev/pr/marimo-team/codemirror-sql/pull/179?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>

<!-- End of auto-generated description by cubic. -->
## Summary
- add a strict private parser worker wire protocol and browser worker
endpoint
- load only literal PostgreSQL and BigQuery parser modules inside the
isolated worker
- fail closed on malformed messages, unsafe realms, overlap, and
poisoned parser descriptors
- add Node and Chromium coverage plus package artifact assertions

## Validation
- 1,159 Node tests passed with one intentional expected failure
- 4 Chromium worker tests passed
- typecheck, oxlint, test integrity, demo, package smoke, worker
placement, and changed coverage passed
- changed production coverage: 99.46% statements/lines and 100%
branches/functions
- exact-head adversarial review approved by architecture/security,
lifecycle/session, and packaging/browser reviewers

## Scope
Private infrastructure only: no public exports, session wiring, semantic
extraction, cache, or API compatibility commitment.

## Review policy
Copilot review is requested once for this PR. It will not be
re-requested after later pushes.

<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Adds a private, versioned wire protocol and a dedicated module-worker
endpoint for `node-sql-parser` to run parsing in an isolated browser
worker. The endpoint now guards the entire backend operation and uses
stricter, bounded wire decoding; artifacts are production-shaped but
still private.

- **New Features**
- Closed protocol v1 for parse requests/responses; no AST, source text,
or raw errors on the wire; retryability derived from failure code.
- Dedicated worker endpoint that lazily loads `bigquery`/`postgresql`,
reuses the backend normalizer, and restores exact
`NodeSQLParser`/`global` descriptors around module load, decode, parser
construction, parse, and normalization.
- Single-flight only: one in-flight request; malformed or overlapping
requests emit a protocol error and then close.
- Outcomes include normalized statement kind, bounded unsupported
reasons, or bounded failure codes.

- **Bug Fixes**
- Guarded the full worker backend parse and permanently poison on
restoration failure; close the generation on `module-load` failures.
- Bounded and hardened wire decoding: accept only closed plain records,
enforce key limits, and avoid accessor traps.

<sup>Written for commit e06a42f.
Summary will update on new commits.</sup>

<a
href="https://cubic.dev/pr/marimo-team/codemirror-sql/pull/180?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>

<!-- End of auto-generated description by cubic. -->
## Summary

Adds the private main-realm executor for the isolated parser worker
selected in
ADR 0004.

- Lazily creates at most one authoritative worker generation.
- Serializes requests through a bounded FIFO queue with independent
request-count
  and retained UTF-16 text limits.
- Enforces startup, queue-wait, and posted-execution safety deadlines.
- Settles caller cancellation promptly while draining already-posted
work.
- Retires crashed, timed-out, malformed, or poisoned generations without
  replaying posted work.
- Preserves never-posted queued work across eligible generation
replacement.
- Rejects reused worker identities and serializes retirement across
hostile
  cleanup/settlement reentrancy.
- Keeps the worker factory, executor, protocol, and implementation types
private;
  there is no root or `/vnext` public API change.

## Risk classification

Medium: concurrency, cancellation, worker lifecycle, resource
accounting, and
packaging boundaries.

The principal risks are double settlement, stale-generation authority,
physical
worker overlap, posted-work replay, unbounded retention, and browser
bundler
regressions. The implementation mutates ownership before every external
cleanup
or settlement boundary, uses an iterative pump trampoline, and tests
hostile
synchronous callbacks at each boundary.

## Evidence

- Full Node suite: 1,246 passed, 1 expected failure.
- Focused deterministic executor suite: 84 passed.
- Chromium: 4 files / 7 tests, including real worker, crash,
silent-worker
  deadline, recovery, and default static Worker URL behavior.
- Changed executor coverage:
  - Statements: 95.51%
  - Branches: 95.37%
  - Functions: 100%
  - Lines: 95.49%
- All TypeScript project checks, oxlint, test-integrity, and diff checks
pass.
- Packed-package smoke test passes and asserts the executor artifact.
- The post-rebase executor patch ID exactly matches the twice-reviewed
pre-rebase
  patch.

## Adversarial review ledger

The review loop found and fixed:

- cancellation and FIFO reentrancy during promotion;
- `preventDefault` running before generation retirement;
- listener installation continuing after synchronous retirement;
- recursive synchronous worker responses overflowing the stack;
- startup-failure queue transfer and ready-failure ownership errors;
- postMessage accessor disposal/forged-response races;
- a P1 physical-worker overlap during cleanup-triggered nested
submission; and
- same-worker identity reuse after termination.

Two independent reviewers approved the corrected pre-rebase patch. Two
fresh
independent audits also approved the exact rebased head after rerunning
Node,
Chromium, package, coverage, type, lint, integrity, placement, and demo
gates.

## API and rollout

This is implementation infrastructure only. It is not wired to sessions,
completion, diagnostics, or other public features. No compatibility or
migration
work is required in this slice. The next consuming coordinator must
preserve the
same bounded ownership and no-replay rules.

<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Adds a private, single-lane browser executor for the isolated SQL parser
worker with bounded queueing, strict deadlines, and safe lifecycle
handling. Internal only; no public or `/vnext` API changes. Hardened to
fail closed on retirement errors with explicit terminal states.

- **New Features**
- Lazily creates at most one worker generation; posts one request at a
time.
- Bounded FIFO queue with request-count and UTF‑16 text limits;
startup/queue/execution deadlines and prompt caller cancellation.
- Retires crashed/timed-out/poisoned generations without replay;
preserves never-posted queued work across replacement.
- Rejects reused worker identities; retirement is serialized and atomic
to avoid reentrancy races.
- Executor, worker factory, protocol, and types remain private; docs
updated and `scripts/package-smoke.mjs` asserts executor artifacts.

- **Bug Fixes**
- Fails closed if worker retirement throws to prevent accepting new work
in an unsafe state.
- Makes terminal states explicit to avoid resurrection and double
settlement.

<sup>Written for commit 1cb7105.
Summary will update on new commits.</sup>

<a
href="https://cubic.dev/pr/marimo-team/codemirror-sql/pull/181?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>

<!-- End of auto-generated description by cubic. -->
## Summary

- accept ADR 0005 for parser-independent relation completion
- keep the first completion slice independent of parser acceptance and
parser-worker startup
- define a bounded partial-`SELECT` query-site recognizer and narrow CTE
visibility model
- define one provider-owned catalog boundary, canonical suffix
rendering, epochs, cache identity, deadlines, cancellation, and
deterministic composition
- define atomic text/context/embedded-region transactions and
service-originated revision notifications
- define CodeMirror ownership, rich-info decoration, loading refresh
intent, and marimo 1/10/50-view acceptance evidence
- keep provider/completion declarations provisional until the vertical
slice, two provider shapes, packed marimo integration, and hostile
lifecycle suites pass

## Key decisions

- incomplete relation completion does not depend on `node-sql-parser`
- catalog matching/addressability belongs to the provider and scope;
dialect runtime owns SQL decoding and role-aware rendering
- catalog edits replace the authenticated whole typed path with a
provider-proven canonical suffix
- arbitrary embedded regions are grammar barriers; recovered sites
remain explicitly heuristic and incomplete
- one atomic shared-work owner set covers request consumers and refresh
observers
- hard safety deadlines are separate from the 40 ms default interactive
catalog response budget
- terminal and soft loading results carry bounded one-shot
completion-intent leases
- higher epochs discovered by responses or invalidations preserve
active/menu/no-menu completion intent exactly once
- completion search misses never prove unknown-object diagnostics;
authoritative resolution is separate

## Validation

- patch rebased onto merged executor checkpoint `873c926`
- all TypeScript configurations pass
- oxlint passes with zero findings
- test integrity passes
- 1,248 Node tests pass plus 1 expected negative
- three specialist adversarial review loops covered SQL/API correctness,
marimo ergonomics, and concurrency/performance
- final exact-head approvals are recorded for `d66ea25`

## Follow-up

The first implementation change is the runtime-free marimo-shaped type
fixture. No production completion slice starts until that fixture
compiles.


<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Accepts ADR 0005 to provide parser‑independent relation completion with
clear catalog/provider contracts, CTE visibility, and deterministic
lifecycle. Completion now works for incomplete FROM/JOIN without waiting
for `node-sql-parser` or worker startup, and keeps `CodeMirror`
integration separate.

- New Features
- Decoupled relation completion from parser/worker; added bounded
partial-SELECT site and CTE-visibility recognizers.
- Defined catalog provider boundary: scope/search paths in; canonical
paths with `completionPathStart`, epochs, and coverage out.
- Added atomic text/context/embedded-region transactions and
`onDidChange` session notifications for service-originated revisions.
- Clarified dialect-owned identifier decoding/quoting and role-aware
rendering; no generic folding/dedup in the service.
- Specified deterministic ranking, latest-wins cancellation, deadlines
(queue/exec), cache identity, and one-shot refresh intent.
- Documented `CodeMirror` adapter boundary, safe coalesced refresh on
`catalog-availability`, and no worker construction for this slice.

- Migration
- Pass a complete embedded-region set on open/update; regions, text, and
context update atomically.
- Implement the new catalog provider contract (or use
`createInMemoryRelationCatalog`); do not emit SQL text—return decoded
paths and roles.
- Do not gate completion on parser readiness; keep the parser worker and
scoped semantics for future slices.
- Subscribe to `session.onDidChange` and coalesce refresh on
`catalog-availability`; respect the provided completion-intent lease.

<sup>Written for commit d66ea25.
Summary will update on new commits.</sup>

<a
href="https://cubic.dev/pr/marimo-team/codemirror-sql/pull/182?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>

<!-- End of auto-generated description by cubic. -->
## Summary

- add package-private provisional contracts for relation catalog search,
epochs, path authority, dialect-owned decoding/rendering, completion
results, and session lifecycle
- migrate catalog search paths from dot-joined strings to decoded
identifier-component paths with quote provenance
- add a runtime-free marimo-shaped core fixture covering atomic
document/context/region transactions, providers, subscriptions,
completion results, and negative type guarantees
- add a separate CodeMirror fixture requiring explicit disposal for
custom rich-info resources

These declarations intentionally remain outside the `./vnext` public
export surface until the complete vertical slice, two provider shapes,
hostile decoding, packed marimo integration, and lifecycle/performance
gates pass.

## Design constraints

- provider authoring is strongly typed, but runtime ingress will be
erased to `unknown` and strictly decoded
- providers return decoded role-bearing canonical paths and positive
addressability evidence; only dialect runtime data may decode SQL
identifiers or render insertion text
- provider requests contain only bounded catalog/query data; provider
cancellation is passed separately
- consumer results do not expose epochs, scheduler work IDs, deadlines,
configuration identity, or terminal-vs-soft loading causes
- every `catalog-loading` issue carries a bounded remaining intent lease
- custom CodeMirror rich info must return `{ dom, destroy }`, enabling
late-result draining and React-root unmounting

## Validation

- `pnpm run typecheck`
- `pnpm exec oxlint`
- `pnpm run test:integrity`
- `pnpm test` — 1,248 passed, 1 expected failure
- `pnpm run test:browser` — 7 passed
- `pnpm run test:package`
- changed coverage — 100% statements, branches, functions, and lines
- exact-head adversarial approval from SQL/API and marimo ergonomics
reviewers at `d5a38af2804c928bc8acf7f7a0ae91a759f3de24`

Part of #169.

<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Adds provisional, strongly typed contracts for SQL relation completion,
including catalog search, dialect decoding/rendering, completion
items/results, and session lifecycle. Migrates identifier handling to
decoded `SqlIdentifierPath` components and adds a disposable CodeMirror
resolver for custom info. Part of #169.

- New Features
- Relation catalog contracts: search request/response, epochs, coverage
(complete/partial/paginated), provider reports.
- Dialect runtime for identifier decode/render and CTE identifier
equality.
- Completion model for CTEs and catalog relations, with issues and
ready/unavailable/cancelled/failed results.
- Session API with transactional updates, completion, change events, and
disposal.
  - CodeMirror `SqlCompletionInfoResolver` returning `{ dom, destroy }`.
- Export `SqlIdentifierComponent` and `SqlIdentifierPath` from
`src/vnext/index.ts`.

- Migration
- Replace dot-joined search paths with `SqlIdentifierPath`; use
`SqlIdentifierComponent` for all name parts.
- Providers are async, take `AbortSignal` separately, and return decoded
paths (no SQL insert text); rendering moves to the dialect runtime.
- Embedded regions are readonly; document updates must pass the full
`embeddedRegions` set.
- Incomplete completion lists must include at least one issue;
`catalog-loading` issues include `remainingIntentLeaseMs`.

<sup>Written for commit 2d0bade.
Summary will update on new commits.</sup>

<a
href="https://cubic.dev/pr/marimo-team/codemirror-sql/pull/183?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>

<!-- End of auto-generated description by cubic. -->
## Summary

- make embedded regions a public, atomic input to document open and
update transactions
- require every text mutation to carry the complete post-edit region set
while preserving omission and explicit-clear semantics for non-document
updates
- mask embedded regions before statement analysis, with separate source
sequencing and conservative cache reuse
- align runtime decoding with TypeScript structural typing by copying
only declared own data fields and leaving host metadata opaque
- migrate the provisional completion contract and packed consumers to
the real session transaction types

## Correctness and consumer behavior

- text, context, dialect, regions, revision, sequences, and statement
cache commit or roll back together
- stale revisions are rejected before candidate payload inspection;
disposal dominates hostile/reentrant failures
- region ranges use resulting-document UTF-16 coordinates and include
complete non-SQL delimiters such as marimo's `{df}`
- source snapshots and normalized regions are owned and frozen;
same-value source transactions still advance revision/source sequence
- incremental statement indexing remains limited to identity-to-identity
edits; changed masked analysis rebuilds lazily
- structurally richer marimo region/envelope values compile and run
without invoking or retaining extra host fields
- removed outer `kind` and contradictory document fields remain
explicitly forbidden in both types and runtime

## Validation

- `pnpm run typecheck`
- `pnpm exec oxlint`
- `pnpm run test:integrity`
- `pnpm test` — 1,264 passed, 1 expected failure
- `pnpm run test:browser` — 7 passed
- `pnpm run test:package` with typed and runtime nonempty embedded
regions
- `pnpm run test:worker-placement`
- `pnpm run demo`
- changed coverage — 98.70% statements, 97.42% branches, 100% functions,
98.69% lines
- pre-rebase review/fix/re-review loop across SQL/API, marimo
ergonomics, and concurrency/performance perspectives
- fresh exact-head approval from all three reviewers at
`ff35130197fcf69a10d42d195c8dd6324f6d5ed9`

Part of #169.

<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Make embedded regions a first-class, atomic session input in vNext.
Document edits now require the complete post-edit region set, masking
happens before analysis, and cache reuse is tied to a separate source
sequence. Part of #169.

- **New Features**
- Embedded regions are accepted on open and update; document mutations
must include the full resulting `embeddedRegions`. Region-only and
context-only updates are supported.
- Region ranges use resulting-document UTF-16 and include full non-SQL
delimiters (e.g., marimo `{df}`); masking is length-preserving and runs
before statement analysis.
- Unchanged text+regions reuse the immutable source and statement index
via a separate source sequence; only identity-to-identity edits reuse
incrementally. Changed masked analysis invalidates the cache unless
analysis text is equal.
- Inputs are structural: only declared own data fields are read; host
metadata and extras stay opaque. Context accessors and non-enumerable
properties are rejected. Stale revisions are rejected before payload
inspection; disposal dominates hostile/reentrant failures.
- Optional `document`/`embeddedRegions`/`context` fields: `undefined` is
treated as omission at runtime for compatibility with and without
`exactOptionalPropertyTypes`.

- **Migration**
  - Update `session.update` calls:
- Context-only: `{ baseRevision, context }` (no `kind`; `context` must
be defined by types).
- Document mutation: `{ baseRevision, document: {...}, embeddedRegions:
[...] }` (regions required).
    - Region-only: `{ baseRevision, embeddedRegions: [...] }`.
- Open with regions: `service.openDocument({ text, context,
embeddedRegions })`.
- Use `SqlEmbeddedRegion` and `SqlDocumentUpdate` from
`@marimo-team/codemirror-sql/vnext`; stop importing `SqlEmbeddedRegion`
from `./source`.

<sup>Written for commit db6eeee.
Summary will update on new commits.</sup>

<a
href="https://cubic.dev/pr/marimo-team/codemirror-sql/pull/184?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>

<!-- End of auto-generated description by cubic. -->
## Summary

- extract dialect lexical profiles and shared UTF-16 identifier, quote,
block-comment, and dollar-quote scanners from the statement index
- preserve statement-index behavior while adding explicit upper bounds
needed by the parser-independent query-site recognizer
- make bounded dollar-quote opener/closer classification
prefix-deterministic and keep partial close search bounded
- add direct boundary regressions for quotes, block comments, dollar
quotes, UTF-16 identifiers, and SQL whitespace

This is a private prerequisite for ADR 0005 step 3; it adds no public
package export.

## Validation

- `pnpm run typecheck` (strict and loose optional-property modes)
- `pnpm exec oxlint`
- `pnpm run test:integrity`
- 1,272 Node tests passed + 1 expected failure
- 7 Chromium tests passed
- packed-package smoke passed
- worker-placement/runtime evidence passed
- demo build passed
- changed coverage: 98.51% statements, 96.75% branches, 100% functions,
98.50% lines
- three independent exact-head adversarial approvals at `652b108`

## Review history

Adversarial review found a dollar-opener read beyond an explicit scan
limit. The final head guards the opener before inspecting a suffix and
includes bounded-prefix equivalence coverage. No additional Copilot
request will be made after the one request for this PR.

<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Shares SQL lexical primitives and adds explicit scan limits to prevent
over-reads while keeping statement-index behavior. Also preserves fast,
bounded ASCII word scans and fixes dollar-quote opener detection.

- **Refactors**
- Moved scanners for quotes, block comments, dollar quotes, UTF‑16
identifiers, and SQL whitespace into `src/vnext/lexical.ts` with
explicit `limit` handling; preserved fast ASCII word scanning in
`statement-index.ts` for performance.
- Centralized dialect profiles and helpers; `statement-index.ts` now
imports these and drops duplicate logic.

- **Bug Fixes**
- Dollar-quote opener classification is now prefix-bounded; no suffix
reads beyond the scan limit.
- Quote and block comment scanners respect limits, including line-break
and backslash cases.
- Dollar-quote tags over 256 chars return `delimiterTooLong` instead of
scanning unbounded.

<sup>Written for commit 3600269.
Summary will update on new commits.</sup>

<a
href="https://cubic.dev/pr/marimo-team/codemirror-sql/pull/185?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>

<!-- End of auto-generated description by cubic. -->
## Summary

- add a private parser-independent partial `SELECT` relation-site
recognizer
- authenticate full relation paths and statement-relative UTF-16
replacement ranges
- enforce dialect-owned identifier/path decoding and path depth under a
global safety ceiling
- recognize base `FROM`, qualified prefixes, aliases, joins, same-depth
commas, nested queries, and dialect-owned `NATURAL` joins
- authenticate the bounded `USING(identifier [, identifier ...])`
grammar before crossing a join constraint
- deliberately fail closed on `ON` until a parser-backed or separately
specified expression recognizer can prove its boundary
- preserve frame-local nested-query recognition after proven relation
transitions and valid `USING` clause exits

## Safety and performance

- active statement: 65,536 UTF-16 units
- lexemes: 16,384
- nesting: 128
- path: dialect limit under global 32
- decoded identifier segment: 256 UTF-16 units
- exact 10 KiB statement: about 0.56 ms mean
- 1,000 classified aliases: about 0.36 ms mean
- 1,000 authenticated `USING` columns: about 0.21 ms mean
- recognizer state remains bounded per query frame and per active
`USING` constraint

## Verification

- 1,537 tests passed plus 1 expected failure
- changed coverage: 96.84% statements, 95.76% branches, 100% functions,
96.83% lines
- repository coverage: 95.31% statements, 92.04% branches, 96.14%
functions, 95.30% lines
- source, test, loose-optional, and demo typechecks pass
- repository oxlint, test-integrity, and diff checks pass
- browser, package, worker-placement, demo, and benchmark gates pass
- three independent adversarial reviewers approved exact commit
`01cd8d29bf99a7c07f6a72ca746da328847c6dfb`

Part of #169.
## Summary

- extract the streaming bounded SQL lexer from the relation-site state
machine into one package-private module
- preserve the exact PostgreSQL, DuckDB, BigQuery, and Dremio lexical
profiles, UTF-16 offsets, embedded-region barriers, quote/comment
behavior, one-token pushback, and 16,384-lexeme ceiling
- keep query-site keyword, comment-cursor, region, and resource
semantics local to the consumer
- translate generic lexer resource evidence through an exhaustive
package-owned map
- add direct boundary tests without exposing tokens or lexer APIs from
the package

This is a zero-semantics prerequisite for the separate bounded CTE
layout/visibility recognizer. The recognizers will initially use
separate streaming traversals over the same lexical implementation; any
traversal fusion remains benchmark-driven.

## Performance

An initial broader helper extraction caused a reproducible Vite SSR
namespace-call regression on the hot path. The boundary was narrowed
before commit.

Stable means at the exact head are back at the PR #186 baseline:

- exact 10 KiB statement: about 0.56–0.59 ms
- 1,000 classified aliases: about 0.36–0.38 ms
- 1,000 authenticated `USING` columns: about 0.21 ms

The lexer remains streaming and does not allocate a token tape.

## Verification

- 1,543 tests passed plus 1 expected failure
- changed coverage: 97.05% statements, 95.79% branches, 100% functions,
97.04% lines
- bounded lexer coverage: 98.92% statements/lines, 98.78% branches, 100%
functions
- repository coverage: 95.34% statements, 92.05% branches, 96.15%
functions, 95.33% lines
- source, test, loose-optional, and demo typechecks pass
- repository oxlint, test-integrity, and diff checks pass
- browser, package, worker-placement, demo, and benchmark gates pass
- 20,000 deterministic differential lexer comparisons passed across
dialects, masked regions, subranges, UTF-16, comments, quotes,
punctuation, and pushback
- independent SQL/API and concurrency/performance reviewers approved
exact commit `ed079df0f68aadaf8957a7ca5e6c497e91b74860`

Part of #169.

<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Refactored vNext to share a streaming bounded SQL lexer and the
embedded-region lookup, and switched `query-site` to use them. Behavior
is unchanged across PostgreSQL, DuckDB, BigQuery, and Dremio; this
unblocks the bounded CTE recognizer in #169.

- **Refactors**
- Moved the lexer into package-private `src/vnext/bounded-sql-lexer.ts`.
- Centralized `findSqlEmbeddedRegionAtOrAfter` in `src/vnext/source.ts`
and reused it in the lexer and `query-site` (with tests).
- Preserves lexical profiles, UTF-16 offsets, embedded-region barriers,
quote/comment rules, one-token pushback, and the 16,384-lexeme cap.
- Kept consumer-specific semantics in `query-site`; mapped lexer
resource signals to local `query-site` resources.
- Removed duplicated lexer and region-lookup code from
`src/vnext/query-site.ts` and wired it to the shared modules.

<sup>Written for commit 76190f9.
Summary will update on new commits.</sup>

<a
href="https://cubic.dev/pr/marimo-team/codemirror-sql/pull/187?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>

<!-- End of auto-generated description by cubic. -->
## Summary

- add a private, cursor-independent bounded CTE layout and visibility
index for PostgreSQL, DuckDB, BigQuery, and Dremio grammar subsets
- preserve committed declarations separately from unfinished-body
drafts, with correct nonrecursive order, nested shadowing, recursive
withholding, duplicate blocking, and source-faithful insertion evidence
- use dialect-owned symmetric tri-state identifier comparison rather
than generic folding or a second nullable comparison-key model
- preserve exact proven prefixes across lexer exhaustion and model
cursor positions correctly at EOF, closing delimiters, barriers, and
scope boundaries
- fail closed on hostile dialect callbacks/data, embedded regions,
malformed syntax, unknown equivalence, and every checked resource
boundary
- extend ADR 0005 and the provisional public relation-completion type
contract for tri-state equality/prefix behavior and CTE-scope
uncertainty

## Bounds and performance

- active statement: 65,536 UTF-16 units
- shared lexical tokens: 16,384
- parenthesis/query depth: 128
- CTE frames: 256
- CTE declarations: 256
- identifier segment: 256 UTF-16 units

Representative local means:

- ordinary 10 KiB statement: ~0.37 ms
- 256 declarations with pairwise equivalence validation: ~3.0 ms
- 128 nested CTE frames: ~1.0 ms
- 256 sequential incomplete frames: ~0.15 ms
- cached 256-declaration projection: ~0.022 ms

## Verification

- 1,587 tests passed, plus 1 governed expected failure
- changed runtime coverage: 96.96% statements, 95.88% branches, 100%
functions, 96.94% lines
- all source, test, vNext exact/loose-optional, and demo typechecks pass
- oxlint and test-integrity gates pass
- package smoke, production build, demo build, and 7 Playwright browser
tests pass
- three independent exact-head adversarial reviewers approved
`8a1572369a171f49d3e23aeed4993aceb88a2cb2`

## Deferred follow-up

The bounded grammar currently authenticates `SELECT` query leaders.
Dialect-owned support for PostgreSQL `VALUES`/data-modifying CTE bodies,
DuckDB `FROM`-first queries, and additionally parenthesized BigQuery
recursive terms remains an explicit follow-up before relation completion
is feature-complete.

Part of #169.

<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Adds a bounded CTE layout and visibility index for vNext to improve
relation completion across PostgreSQL, DuckDB, BigQuery, and Dremio, and
now rejects invalid CTE cursor positions to avoid bogus suggestions.
Introduces tri-state CTE identifier comparison and strict, fail-closed
resource limits; part of #169.

- **New Features**
- Private, cursor‑independent CTE index with correct order, shadowing,
duplicate blocking, and recursive withholding.
- Closed, dialect‑owned grammar per engine with a documented acceptance
matrix; no cross‑dialect borrowing.
- Tri‑state equality and prefix matching through the dialect runtime;
preserves exact prefixes at EOF and scope boundaries.
- Fast, bounded visibility via `visibleSqlCtesAt`; now rejects invalid
cursor positions and the lexer reports limit hits with `resourceAt`,
failing closed on malformed input.

- **Migration**
- In `SqlRelationCompletionDialectRuntime`, replace
`cteIdentifiersEqual` with `compareCteIdentifiers` returning `"equal" |
"distinct" | "unknown"`.
- Implement `cteIdentifierMatchesPrefix` returning `"match" | "no-match"
| "unknown"`.

<sup>Written for commit 7302de4.
Summary will update on new commits.</sup>

<a
href="https://cubic.dev/pr/marimo-team/codemirror-sql/pull/188?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>

<!-- End of auto-generated description by cubic. -->
## Summary

- add one package-owned relation dialect runtime for PostgreSQL, DuckDB,
BigQuery, and Dremio
- unify identifier decoding, CTE equality/prefix rules, query-path
decoding, role-aware rendering, reserved words, and CTE/query recognizer
policy
- authenticate each runtime through the opaque built-in dialect handle
while keeping callbacks private
- add hostile-input bounds and fail-closed behavior, exact dialect
corpora, production-backed recognizer tests, and bundle budgets

## Correctness and performance

- changed production coverage: 97.10% statements, 96.18% branches, 100%
functions, 97.05% lines
- exact packed core: 15,028 gzip / 47,141 raw bytes under 16 KiB / 52
KiB limits
- exact packed worker output: 125,937 gzip / 572,982 raw bytes under 128
KiB / 570 KiB limits
- comparator hot paths use bounded allocation-free ASCII loops; private
path scratch arrays are not copied or frozen

## Verification

- 1,646 tests passed, 1 governed expected failure
- all five TypeScript configurations passed
- oxlint and test-integrity checks passed
- browser suite passed in Chromium
- exact tarball package smoke and SSR import passed
- worker placement, strict CSP, lazy loading, and parser isolation
passed
- query-site and CTE benchmarks passed
- exact head 6e80f2f approved
independently by three adversarial reviewers

Part of #169.

<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Unifies the relation dialect runtime across PostgreSQL, DuckDB,
BigQuery, and Dremio with a single, package-owned policy for
identifiers, CTEs, query paths, and role-aware rendering. Tightens the
public API and enforces strict size budgets and hostile-input
boundaries. Part of #169.

- **New Features**
- Added a unified `relation-dialect` runtime for completion, CTE layout,
query-site policy, reserved words, and rendering across all built-ins.
- Introduced fail-closed decoding with hostile-input bounds and exact
corpora; added adversarial/production-backed tests.
- Enforced bundle budgets (core ≤16 KiB gzip/52 KiB raw; worker ≤128 KiB
gzip/570 KiB raw) and a smoke check to prevent dialect policy leaks.

- **Refactors**
- Public dialect handles (`bigQueryDialect()`, `dremioDialect()`,
`duckdbDialect()`, `postgresDialect()`) now expose only `displayName`
and `id`; callbacks are private and authenticated in `session`.
- Migrated `cte-layout` and `query-site` to `..._SQL_RELATION_DIALECT`
constants; added `MAX_CTE_QUOTED_IDENTIFIER_LENGTH`.
- Simplified and hardened tests by removing ad-hoc dialects; updated
worker placement and docs to report core/worker sizes.

<sup>Written for commit 6e80f2f.
Summary will update on new commits.</sup>

<a
href="https://cubic.dev/pr/marimo-team/codemirror-sql/pull/189?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>

<!-- End of auto-generated description by cubic. -->
## Summary

- authenticate bounded CTE main-query entrypoints before the relation
query-site recognizer consumes them
- unify source, statement-index, slot, layout, and built-in runtime
provenance so mixed or stale evidence fails closed
- keep the low-level query-site recognizer independent of CTE and
aggregate runtime modules through a one-way orchestration layer
- preserve independent old/new statement contexts when incremental
indexes reuse immutable slot identities
- validate real ready paths in the CTE/query-site benchmarks

## Correctness and trust boundaries

- package-created sources, statement indexes, exact slots, CTE layouts,
and coherent dialect runtimes are authenticated by identity
- each statement index privately owns its exact analysis text, frozen
lexical-profile scalar snapshot, and bounded slot membership
- foreign sources, indexes, slots, profiles, layouts, mixed runtimes,
mutable structural copies, and hostile proxies return unavailable
- incomplete and invalid CTE headers remain fail-closed while valid main
queries work across PostgreSQL, DuckDB, BigQuery, and Dremio

## Verification

- 1,671 tests passed and 1 expected failure remained expected
- changed coverage: 96.99% statements, 95.95% branches, 100% functions,
96.96% lines
- all five TypeScript configurations passed
- oxlint passed with zero warnings or errors
- test-integrity and diff checks passed
- exact tarball package smoke, SSR import, strict CSP, worker placement,
and bundle budgets passed
- Chromium browser suite passed: 4 files / 7 tests
- statement-index, CTE-layout, and query-site benchmarks passed
- exact SHA c096a16 received three
independent adversarial approvals after five review/fix loops

Part of #169.

<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Authenticate CTE main‑query entrypoints and only recognize relation
query sites when the source, statement index, slot, and dialect all
match. Ambiguous evidence fails closed, keeping the core recognizer
independent; part of #169.

- **New Features**
- Authenticated CTE layouts: `analyzeSqlCteLayout(source, index, slot,
dialect)` records provenance and binds main‑query entrypoints to the
exact source/index/slot/dialect;
`resolveAuthenticatedSqlCteEntrypoints(...)` exposes them safely.
- Orchestration: `recognizeSqlRelationQuerySiteWithCteLayout(...)`
validates runtime/source/slot via `isSqlRelationDialectRuntime`,
`isSqlSourceSnapshot`, and `isSqlStatementSlotSnapshot`, then feeds
authenticated entrypoints into the query‑site recognizer; runtimes are
registered with `registerSqlRelationDialectRuntime`.
- Entrypoint‑aware query‑site:
`recognizeSqlRelationQuerySiteWithEntrypoints(...)` matches SELECTs at
the exact depth/offset for nested CTEs.
- Statement index provenance: `buildSqlStatementIndex` snapshots the
lexical profile; `isExactSqlStatementSlotSnapshot(For)` ensures slots
belong to the index and text/profile; `updateSqlStatementIndex` rebuilds
when text or lexical profile changes.

- **Migration**
- Pass the statement index into `analyzeSqlCteLayout` (new signature:
`(source, index, slot, dialect)`).
- Use `recognizeSqlRelationQuerySiteWithCteLayout` when combining CTE
layout with relation query‑site; keep `recognizeSqlRelationQuerySite`
for non‑CTE cases.
- Use built‑in registered runtimes from `relation-dialect` and authentic
sources/slots produced by our builders.

<sup>Written for commit 9ca185f.
Summary will update on new commits.</sup>

<a
href="https://cubic.dev/pr/marimo-team/codemirror-sql/pull/190?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>

<!-- End of auto-generated description by cubic. -->
## Summary

- add a package-private prepared statement handle that composes
authenticated query-site and CTE-visibility evidence
- preserve qualified, inactive, ambiguous, opaque, and resource-limited
states without inventing local candidates
- authenticate complete CTE layout results so active-statement resource
failures survive orchestration
- add four-dialect integration coverage and cold/warm performance
baselines

## Why

The relation-completion session needs one immutable artifact it can
cache per
source, statement slot, and dialect. Keeping preparation separate from
position projection avoids rebuilding CTE layout state as the cursor
moves,
while the opaque handle prevents stale or independently mixable evidence
from
crossing sessions.

This remains package-private until the catalog and end-to-end completion
slice
prove the public API described by ADR 0005.

## Evidence

- 1,691 passing unit tests plus one governed expected failure
- all five TypeScript configurations, oxlint, integrity, package smoke,
worker placement, and browser suites pass
- changed coverage: 97.05% statements, 95.77% branches, 100% functions,
97.04% lines
- warm projection: approximately 0.65 ms for a 10 KiB statement and 0.32
ms for 256 CTEs

Roadmap: #169


<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Introduce a package-private prepared statement that authenticates
query-site and CTE visibility to power local relation completion. It
preserves qualified/inactive/opaque/ambiguous/resource-limited states
and adds four-dialect coverage; supports #169.

- **New Features**
- Added `prepareSqlLocalRelationStatement` and
`analyzeSqlLocalRelationSite` for deterministic, cacheable local
evidence (results are frozen).
- Propagated authenticated CTE layout through `relation-query-site`,
including active-statement resource failures.
- Added `isSqlStatementSlotSnapshotFor` and authenticated layout
registration/lookup to validate provenance.
- Added `bench:local-relation-site` plus tests and benches across
PostgreSQL, DuckDB, BigQuery, and Dremio.

<sup>Written for commit 74e9edf.
Summary will update on new commits.</sup>

<a
href="https://cubic.dev/pr/marimo-team/codemirror-sql/pull/191?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>

<!-- End of auto-generated description by cubic. -->
## Summary

- add an authenticated, package-private catalog-provider boundary
- decode hostile request, response, invalidation, and epoch data into
bounded frozen values
- validate canonical and completion paths through authenticated dialect
runtimes
- define provider closure ownership, alias copying, page atomicity, and
epoch semantics in ADR 0005
- add boundary contracts and worst-case performance benchmarks

## Why

Catalog metadata crosses an asynchronous host boundary and cannot be
trusted as typed data at runtime. This slice gives the upcoming
coordinator a small, deterministic input surface without coupling
catalog providers to sessions, CodeMirror, DOM state, or
provider-supplied SQL.

## Validation

- 1,727 unit tests passed plus one governed expected failure
- changed coverage: 95.61% statements, 95.10% branches, 100% functions,
95.55% lines
- strict and loose optional type configurations, lint, integrity,
package smoke, browser, and worker-placement checks passed
- three independent adversarial reviews approved exact SHA
b9f6d3e
- million-unit hostile text rejects in about 0.003 ms; near-limit Dremio
response decodes in about 0.27 ms

Part of #169.
Part of #169.

- Add a package-private provider/scope epoch gate so catalog responses
and invalidations cannot publish against mixed catalog state.
- Share one subscription per scope with two-phase membership activation,
single-use authenticated captures, monotonic arbitration, and exact
revision fan-out.
- Bound callback storms, FIFO admissions, memberships, scopes, and
reentrant provider cleanup with fail-closed quarantine.
- Retire failed targets atomically and sever provider/session closure
graphs before external cleanup or retained-handle disposal.
- Record the lifecycle, ordering, and resource contracts in ADR 0005.

<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Introduces a catalog epoch coordinator that gates responses and
invalidations per scope to prevent mixed catalog state and ensure
deterministic revision fan‑out, and isolates hostile cleanup promises.
Part of #169.

- **New Features**
- One subscription per scope with two‑phase membership and
authenticated, single‑use epoch captures.
- Monotonic arbitration and exact revision fan‑out across sessions
sharing a scope.
- Bounds for callback storms and cleanups, FIFO admissions, and
fail‑closed quarantine for misbehavior.
- Drains async provider/session cleanup settlement, isolates hostile
cleanup promises, and atomically retires failed targets with
reentrant‑safe cleanup.
- Updated ADR‑0005 to document lifecycle and ordering; added extensive
tests and a benchmark with `bench:catalog-coordinator`.

- **Migration**
- `SqlRelationCatalogProvider.subscribe` now returns a this‑free cleanup
function `SqlCatalogSubscriptionCleanup` (may be async) instead of a
`SqlDisposable`; update providers to return `() => void |
PromiseLike<void>`.
- `SqlDisposable.dispose` is now this‑free: change to `dispose(this:
void): void` and avoid using `this` inside dispose.

<sup>Written for commit 3d66bd4.
Summary will update on new commits.</sup>

<a
href="https://cubic.dev/pr/marimo-team/codemirror-sql/pull/193?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>

<!-- End of auto-generated description by cubic. -->
Part of #169. Follows #193.

- Add a package-private synchronous epoch-transition hook so shared
catalog work can retire before session revision listeners observe an
accepted epoch.
- Preserve deterministic prepare/commit/dispatch ordering for provider
invalidations and higher response epochs.
- Tighten provider cleanup and transition dispatch to an exact
`undefined` contract, with fail-closed quarantine for invalid returns.
- Dispose before inspecting invalid thenables, closing the hostile
getter reentrancy window identified after #193 merged.
- Keep the no-hook and null-transition paths allocation-free and add a
configured-hook storm benchmark.
- Extend ADR 0005, type fixtures, lifecycle tests, and adversarial
Promise/thenable coverage.

<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Adds a package-private, synchronous epoch-transition hook that runs
after epoch install to retire catalog work before session listeners.
Enforces exact-return contracts and fail-closed handling to harden
reentrancy, cleanup, and poisoned-thenable edge cases; supports #169.

- **New Features**
- Added `SqlCatalogEpochTransitionTarget` that may return a dispatch
closure or `null`; dispatch must return exactly `undefined` (sync only).
- Preserved strict ordering: transition-prepare → revision-prepare →
producer settle → transition-dispatch → revision-dispatch; reentrant
dispatch queues behind current dispatch.
- Snapshots the revision audience before transition; producers/aborts
see prepared revisions; listeners see already-retired work.
- Rejects non-function transition targets during coordinator creation
(`reason: "invalid-transition-target"`); any thrown preparation, thrown
dispatch, or non-`undefined` return disposes fail-closed and discards
response decisions.
- Drains detached Promise/thenable results for cleanup and transition
returns after disposal, avoiding hostile getter reentrancy; no-hook and
`null`-dispatch paths allocate nothing. Updated ADR 0005, added a
configured-hook storm benchmark, and expanded adversarial tests.

- **Migration**
- Update `SqlCatalogSubscriptionCleanup` to be synchronous and return
`undefined` only (no Promises or other return values).

<sup>Written for commit 9d7c9c3.
Summary will update on new commits.</sup>

<a
href="https://cubic.dev/pr/marimo-team/codemirror-sql/pull/194?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>

<!-- End of auto-generated description by cubic. -->
## Summary

- add the package-private bounded catalog search-work coordinator
- compose provider authentication, epoch authority, latest-wins
ownership, cancellation, deadlines, and response publication
- harden hostile and reentrant lifecycle boundaries, including exact
disposal hooks and captured Promise intrinsics
- document the scheduler contract and deferred cache/session/UI
responsibilities in ADR 0005
- add strict API fixtures, invariant-heavy unit coverage, and
capacity/performance benchmarks

## Invariants

- at most 8 provider searches are active and 64 are queued
- owners join only exact structural request keys and supersede
independently
- scope epoch changes retire same-scope work without crossing scope
boundaries
- failed captures, invalid input, cancellation, disposal, overload, and
deadlines settle promptly and exactly once
- provider calls, timers, clocks, thenables, callbacks, and response
decoding may be hostile or reentrant without reviving retired work
- the authenticated dialect runtime is the sole dialect identity
authority

## Validation

- `vitest`: 1,856 passed, 1 expected failure
- changed coverage: 97.29% statements, 96.23% branches, 99.46%
functions, 97.73% lines
- search coordinator: 97.03% statements, 95.09% branches, 100%
functions, 97.84% lines
- epoch coordinator: 98.31% statements, 97.42% branches, 98.21%
functions, 98.89% lines
- strict source, tests, vNext API fixture, loose-optional fixture, and
demo typechecks
- zero-warning `oxlint`
- test-integrity gate
- 4 browser files / 7 browser tests
- exact-tarball package smoke test
- worker placement and bundle budgets
- production dependency audit: no known vulnerabilities
- catalog search-work benchmark suite
- two independent adversarial exact-head approvals

Part of #169.

<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Adds a package-private, bounded catalog search-work coordinator that
composes provider auth with epoch authority to run searches safely,
dedupe by exact keys, and enforce deadlines. Also centralizes catalog
scope validation to a shared boundary utility. Progress toward #169.

- **New Features**
- Added `createSqlCatalogSearchWorkCoordinator` with 8 active and 64
queued limits, exact-key in-flight sharing, and latest-wins per owner.
- Owners capture scope and dialect; the authenticated dialect runtime
defines the provider ID and epoch authority.
- Independent cancellation, queue and execution deadlines, and a small
synchronous budget; outcomes include usable, superseded, cancelled, and
unavailable.
- Safe response decoding and epoch publication; first baseline re-keys
unobserved work in the same scope.
- Benchmarks and strict unit/type tests for lifecycle, concurrency,
deadlines, and adversarial scenarios.
- ADR 0005 updated to document scheduler/deadlines and package-owned
disposal semantics.

- **Refactors**
- Epoch coordinator now accepts a package-owned disposal target, invokes
it exactly once, and drains non-undefined returns with captured Promise
intrinsics (resilient to a replaced global Promise).
- Centralized scope validation into `isValidSqlCatalogScope` in the
boundary; adopted by epoch and search-work paths with new tests.
- Hardened lifecycle boundaries and cleanup; exact disposal and hostile
thenable handling.
- Dialect runtime exposes a stable `id`; tests assert coherence and
deep-freeze properties.

<sup>Written for commit 061a3c6.
Summary will update on new commits.</sup>

<a
href="https://cubic.dev/pr/marimo-team/codemirror-sql/pull/195?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>

<!-- End of auto-generated description by cubic. -->
## Summary

- add a bounded exact-key ready-page cache with epoch-scoped
invalidation
- add fail-closed loading barriers and retry gates for subscribed and
unsubscribed providers
- add atomic refresh-observer transfer with reentrancy-safe availability
dispatch
- document marimo connection-incarnation and unresolved-metadata
semantics
- codify the accelerated candidate-boundary delivery cadence

## Why

Catalog completion needs to reuse proven results without allowing stale
pages, same-epoch loading transitions, remounted editors, or cache
pressure to bypass epoch authority. This keeps the package-private
scheduler, policy state, and observer lifecycle coherent before session
composition and the public adapter are added.

## Verification

- 1,895 tests passed; 1 expected failure
- changed coverage: 98.02% statements, 95.86% branches, 99.47%
functions, 98.49% lines
- full typecheck, oxlint, test-integrity, browser, demo, and package
smoke passed
- two independent exact-head adversarial reviews approved
- catalog scheduler benchmark passed


<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Adds a bounded, epoch-aware cache for catalog search to reuse “ready”
pages without serving stale data, and introduces refresh leases to
prevent duplicate provider work.

- **New Features**
- Added `SqlCatalogSearchPolicyStore`: exact-key cache for ready pages
with epoch-scoped invalidation.
- Bounded by `MAX_CATALOG_POLICY_STORE_ENTRIES` (256) and
`MAX_CATALOG_POLICY_STORE_RETAINED_BYTES` (2 MiB).
- Integrated the policy store into `relation-catalog-search-work` with
fail-closed loading/retry gates.
- Added refresh leasing (`retainForRefresh`) and single-shot
availability dispatch with reentrancy safety.
  - New default `DEFAULT_CATALOG_REFRESH_LEASE_MS = 1000`.
  - Exposed `hasLiveSubscription(scope)` on the epoch coordinator.
- Updated ADR and implementation docs; added comprehensive unit and type
tests.

- **Migration**
- If you provide a custom `SqlCatalogEpochCoordinator`, implement
`hasLiveSubscription(scope)`.
  - Availability targets must be synchronous and return `undefined`.
- Optional: tune `refreshLeaseMs` via search-work options; no other
changes required.

<sup>Written for commit 803afd1.
Summary will update on new commits.</sup>

<a
href="https://cubic.dev/pr/marimo-team/codemirror-sql/pull/196?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>

<!-- End of auto-generated description by cubic. -->
## Summary

- expose one framework-independent completion lifecycle through
`SqlDocumentSession.complete()` and `onDidChange()`
- compose visible CTEs with one bounded catalog page using deterministic
ranking, proven shadowing, original-document UTF-16 edits, and closed
incomplete reasons
- share catalog scheduling/cache/epoch ownership at service scope while
keeping request, refresh intent, and terminal-loading lifecycle
session-local
- make the public completion result extensible with a `kind: "relation"`
item discriminant
- document the consumer contract and add cold/warm local plus
cold/cached catalog benchmarks

## Why

The lower catalog scheduler and parser-independent query-site work were
not yet usable through the public session. This slice connects those
layers without exposing coordinator identities, epochs, timers, or
CodeMirror state. It gives adapters a bounded local-first response and
an explicit revision event when catalog evidence becomes usable.

Catalog scope is treated as a live connection incarnation. Loading,
partial, paginated, failed, overloaded, and timed-out evidence remains
explicit, so unresolved marimo metadata cannot be mistaken for a
complete empty catalog.

## Evidence

- 1,989 unit tests pass with one expected failure
- changed production files: 98.02% statements, 95.13% branches, 100%
functions, 98.23% lines
- strict and loose-optional vNext type fixtures pass
- source, test, and demo typechecks pass
- oxlint and test-integrity checks pass
- 10 KiB completion benchmark: cold p99 about 1.5 ms; warm p99 below 0.8
ms
- two independent exact-head reviews approved the final lifecycle, API,
timer, and consumer semantics

<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Exposes a session-based, framework-independent relation completion API
with deterministic CTE + catalog suggestions and clear change events.
Aligns CI bundle budgets for both the core and the worker fixture to
match the new relation service.

- **New Features**
- `SqlDocumentSession.complete(request)` returns `SqlCompletionResult`
with `kind: "relation"` items.
- `SqlDocumentSession.onDidChange(listener)` emits
`SqlSessionChangeEvent` when catalog evidence becomes usable.
- Deterministic ranking for local CTEs plus a bounded catalog page;
supports cancellation and response budgets.
- `createSqlLanguageService({ catalog, completion: {
catalogResponseBudgetMs } })` to configure a catalog and timing.
- Docs updated in `@marimo-team/codemirror-sql/vnext`; added unit tests
and a 10 KiB session completion benchmark.
- CI: set core bundle allocation to 48 KiB gzip (180 KiB raw) and raised
worker fixture ceiling to 160 KiB gzip (700 KiB raw); updated worker
README and capability charter.

- **Migration**
- Rename `SqlRelationCompletionItem` → `SqlCompletionItem` and
`SqlRelationCompletionList` → `SqlCompletionList`.
  - Update CodeMirror resolver signatures to accept `SqlCompletionItem`.

<sup>Written for commit c66cffc.
Summary will update on new commits.</sup>

<a
href="https://cubic.dev/pr/marimo-team/codemirror-sql/pull/197?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>

<!-- End of auto-generated description by cubic. -->
## Summary

- add an opaque completion refresh token that correlates loading
results, follow-up catalog events, and the originating completion task
- make completion tasks expose their refresh token synchronously so
CodeMirror consumers can safely latch intent before caller-controlled
reentrancy
- define precise token lifetimes for soft and terminal catalog-loading
leases, including expiry, cancellation, update, and disposal
- harden `AbortSignal` handling against reentrant and throwing
getters/listener methods without allowing an older invocation to erase
newer work

## Why

The upcoming CodeMirror adapter must refresh completion only for the
request that originally produced a loading result. Revision checks alone
cannot distinguish multiple requests at the same document revision, and
asynchronous token publication leaves a race where catalog events can
arrive before the consumer knows what to match. This contract makes that
identity explicit and keeps latest-request-wins behavior correct across
hostile caller boundaries.

## Validation

- 2,003 tests pass; 1 intentional expected failure
- changed-file coverage: 97.92% statements, 96.01% branches, 100%
functions, 98.01% lines
- all strict and loose-optional TypeScript configurations pass
- oxlint and test-integrity checks pass
- session completion benchmarks remain within budget
- two independent exact-commit adversarial reviews approved `a0522c4`


<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Adds an opaque completion refresh token to correlate loading results,
follow-up catalog events, and the originating request.
`session.complete()` now returns a `SqlCompletionTask` that exposes the
token synchronously, and `onDidChange` events include the token when
relevant.

- **New Features**
- Introduced `SqlCompletionRefreshToken` and `SqlCompletionTask`
(`complete()` returns a task with `refreshToken`).
  - `SqlSessionChangeEvent` now carries `refreshToken`:
- `catalog-availability`: always includes the exact token for the active
soft intent.
- `catalog`: includes the matching token during an active intent lease,
otherwise `null`.
    - `provider-configuration`: `refreshToken` is always `null`.
- Ready results include `refreshToken` when a `catalog-loading` lease is
active; otherwise `null`.
- Hardened `AbortSignal` and timer handling to avoid reentrancy issues
and prevent stale callbacks from erasing newer work.

- **Migration**
  - Update callers to use the new task:
    - `const task = session.complete(...); const result = await task;`
    - Use `task.refreshToken` immediately to latch intent.
  - Update `onDidChange` listeners:
- Compare `event.refreshToken` to the latched `task.refreshToken` before
refreshing.
- Treat `catalog` events with `refreshToken: null` as unrelated to the
current intent.
  - Adjust types:
    - `complete()` now returns `SqlCompletionTask` (still awaitable).
- Handle the refined `SqlSessionChangeEvent` union with per-reason
`refreshToken` semantics.
  - Do not serialize or introspect tokens; compare by identity only.

<sup>Written for commit a0522c4.
Summary will update on new commits.</sup>

<a
href="https://cubic.dev/pr/marimo-team/codemirror-sql/pull/198?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>

<!-- End of auto-generated description by cubic. -->
## Summary

- add an explicit `@marimo-team/codemirror-sql/vnext/codemirror` entry
point with one caller-owned service and one session per `EditorView`
- translate composite CodeMirror document, context, and embedded-region
effects into one atomic session update
- map current relation results to exact CodeMirror edits with revision,
document, selection, context, and embedded-region guards
- coalesce exact-token catalog refreshes across active menus and empty
loading results without synchronous provider-driven dispatch
- contain Escape, close, blur, visibility, expiry, service-first
disposal, stale rejection, and repeated teardown races

## Why

The framework-independent service now has the identity and lease
contracts needed for a thin editor boundary. This adapter makes those
contracts usable without leaking CodeMirror into the core, while
preserving marimo's external completion sources and treating
transformed-document regions explicitly rather than guessing their
mapping.

## Validation

- 2,028 tests pass; 1 intentional expected failure
- adapter coverage: 97.70% statements, 95.86% branches, 100% functions,
99.01% lines
- all strict and loose-optional TypeScript configurations pass
- oxlint and test-integrity checks pass
- packed-consumer source covers the new package subpath; hosted package
CI will run the isolated install
- two independent exact-commit adversarial reviews approved `8d72a4c`


<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Adds a CodeMirror 6 adapter for the vNext SQL language service, exposed
as `@marimo-team/codemirror-sql/vnext/codemirror`. This enables exact,
guarded completion edits and atomic document/context/region updates
without leaking CodeMirror into the core.

- **New Features**
- New `sqlEditor` adapter with one document session per `EditorView`;
caller owns the shared `service`.
- Atomic updates: merges document changes with `support.contextEffect`
and `support.embeddedRegionsEffect`.
- Exact completion edits with revision/context/selection guards; maps
unrelated embedded regions through its own edit; ignores overlaps.
- Coalesced refresh intents keyed by service tokens; cancels on Escape,
blur (configurable), visibility loss, selection change, or lease expiry;
no synchronous provider-driven dispatch.
- Single `autocompletion` configuration; supports `externalSources` for
extra providers.
- New docs: `docs/vnext/codemirror-adapter.md`; subpath export added in
`package.json`; smoke test updated.

- **Migration**
- Import from `@marimo-team/codemirror-sql/vnext/codemirror`, create a
service from `@marimo-team/codemirror-sql/vnext`, then add
`support.extension` to the editor.
- Do not install a second `autocompletion` extension; pass extra
providers via `externalSources`.
- Update context/regions via `support.setContext` or by dispatching
`support.contextEffect` and `support.embeddedRegionsEffect`. If embedded
regions exist, include the complete resulting set on every
document-changing transaction.

<sup>Written for commit 8d72a4c.
Summary will update on new commits.</sup>

<a
href="https://cubic.dev/pr/marimo-team/codemirror-sql/pull/199?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>

<!-- End of auto-generated description by cubic. -->
Light2Dark and others added 7 commits July 26, 2026 01:40
## Summary

- expose an opt-in, type-safe completion info resolver on the vNext
CodeMirror adapter
- give every resolver an AbortSignal and require explicit DOM resource
cleanup
- abort pending work and destroy resolved UI on option, document,
context, region, or view changes
- contain resolver/cleanup failures and reject cleanup reentrancy
- document the React-root integration pattern and export the public
resolver types

## Verification

- 43 test files; 2,036 passed and 1 expected failure
- changed coverage: 98.15% statements, 95.90% branches, 100% functions,
99.20% lines
- all strict/loose/demo TypeScript configurations pass
- oxlint and test-integrity checks pass
- build and runtime export smoke pass
- two independent exact-head adversarial reviews approve
`e07f8e525d6e6f2c7f73e24acd4e1f0b1ff90cc0`

Stacked on #199, now merged into `dev-refactor`.

<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Adds opt-in rich completion info to the vNext CodeMirror adapter.
Introduces a type-safe `infoResolver` that returns a disposable DOM
panel, with automatic abort and cleanup on selection or editor changes.

- **New Features**
- `autocomplete.infoResolver(item, { signal })` lets you render rich
info and return `{ dom, destroy }`; pending work is aborted and resolved
resources are destroyed on option selection changes,
document/context/region updates, or view disposal.
- Stale results are ignored; null results omit the panel; resolver and
cleanup failures are contained; reentrancy during cleanup is rejected.
- Docs updated with a React root example; exported
`SqlCompletionInfoResolver`, `SqlCompletionInfoResolverContext`, and
`SqlDisposableCompletionInfo` from `src/vnext/codemirror/index.ts`.

- **Migration**
  - Opt in by passing `sqlEditor({ autocomplete: { infoResolver } })`.
- Your resolver should use the provided `AbortSignal` and return `{ dom,
destroy }` or `null`.

<sup>Written for commit e07f8e5.
Summary will update on new commits.</sup>

<a
href="https://cubic.dev/pr/marimo-team/codemirror-sql/pull/200?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>

<!-- End of auto-generated description by cubic. -->
## Summary

- expose synchronous, revision-stamped `statementBoundaryAt` and
`statementBoundariesIntersecting` session queries
- preserve exact/no-code/opaque lexical states without leaking the
private statement index
- add scanner-owned `code` spans that exclude separator trivia and form
a strict `hasCode` discriminated union
- validate request envelopes as own data properties without invoking
host accessors
- retain incremental index reuse and shift code spans with exact UTF-16
coordinates
- add public type, package smoke, hostile-input, affinity, opacity,
masking, intersection, and documentation coverage

## Verification

- 43 test files; 2,045 passed and 1 expected failure
- changed coverage: 97.92% statements, 96.12% branches, 100% functions,
98.07% lines
- all source/test/strict/loose/demo TypeScript configurations pass
- oxlint, test integrity, build, and runtime export smoke pass
- cold point lookup measured 3.59 ms at 1 MiB and 42.67 ms at the 16 MiB
source ceiling; warm viewport intersection measured 0.075–0.096 ms
- two independent exact-head adversarial reviews approve
`c901544ff41480bb1e7ea2ddcab3af477dc8103f`

<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Expose synchronous, revision-stamped statement boundary queries in the
vNext session API so editors and runners can locate executable SQL
without re-lexing. Adds an exact/opaque boundary model with precise
UTF-16 ranges and a `code` span for execution.

- **New Features**
- Added `session.statementBoundaryAt({ affinity, position })` and
`session.statementBoundariesIntersecting({ from, to })`; results are
frozen and include the current `revision`.
- Exact boundaries expose `extent`, `source`, optional `terminator`,
lexical `endState`, and a `code` span that excludes separator trivia;
discriminated by `hasCode`.
- Opaque boundaries report a `reason` for non-executable regions
(procedural blocks, custom delimiters, resource limits).
- All ranges map to the original document’s UTF-16 positions and respect
masked embedded regions.
- Inputs are strictly validated (own data properties only); invalid
requests throw `SqlSessionError` with
`invalid-statement-boundary-request`.
- Exported new types via `@marimo-team/codemirror-sql/vnext`:
`SqlStatementBoundary*`, `SqlStatementAffinity`,
`SqlStatementLexicalEnd`, and related request/result shapes.

<sup>Written for commit c901544.
Summary will update on new commits.</sup>

<a
href="https://cubic.dev/pr/marimo-team/codemirror-sql/pull/201?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>

<!-- End of auto-generated description by cubic. -->
## Summary

Completes the final batched vNext SQL language-service overhaul
milestone.

- adds authenticated parser-neutral query binding models and bounded
  `node-sql-parser` normalization in the isolated worker protocol
- adds public batched column and namespace catalog providers with stable
provenance, epochs, bounded caches, cancellation,
partial/loading/failure
  states, and hostile-response validation
- integrates relation, namespace, and physical-column completion into
document
  sessions and the CodeMirror adapter
- adds exact statement gutter behavior and insertion-point completion
gating
  for embedded marimo expressions while preserving external sources
- adds correlated outer-scope column completion with conservative
derived-table
  isolation
- expands the marimo compile-time migration fixture and
architecture/authority
  documentation

## Review hardening

All 27 Cubic comments were reproduced and addressed. Two final
adversarial
reviews found and closed seven additional issues:

- revoked proxies, decoder exceptions, exact response variants,
structural
  identity comparisons, and blank namespace path components
- generation-linearized cancellation and disposal in both catalog
coordinators,
  including reentrant abort listeners
- source-authenticated identifiers, aliases, CTE scope, derived ranges,
compound
  blocks, and `ON`/`USING` visibility
- exact statement bounds, one end-to-end response budget, the
64-relation
deterministic partial cap, incomplete aliases, and line-comment
boundaries
- stale completion-gate callbacks, external-source preservation, and
  failure-safe browser cleanup

CTE and derived-table output-column inference remains an explicit
next-major
cutover gap; vNext does not incorrectly route those logical relations to
the
physical catalog provider.

## Correctness and performance

- original-document UTF-16 ranges and exact replacement edits
- explicit partial/unsupported results instead of guessed semantics
- revision, cancellation, owner disposal, scope, dialect, and epoch
checks
- no raw parser AST crosses or persists beyond the adapter/worker
boundary
- complete-only bounded catalog caches
- deterministic ordering and deduplication
- maximum-shape query-model validation reduced from about 888 ms to
about
  6.4 ms
- framework-independent packed core: 187,989 raw bytes and 50,590 gzip
bytes,
  within the unchanged 184 KiB raw and 50 KiB gzip limits

## Verification

- 2,286 unit tests passed; 1 intentional expected failure
- repository coverage:
  - 96.58% statements
  - 96.71% lines
  - 98.01% functions
  - 94.43% branches
- changed vNext coverage:
  - 97.79% statements
  - 98.08% lines
  - 99.46% functions
  - 96.62% branches
- every changed runtime file passes the 95% per-file
  statements/branches/functions/lines gate
- strict TypeScript configurations, oxlint, and test-integrity checks
pass
- 14 browser tests pass in Chromium
- build, demo build, packed-consumer smoke, parser-isolation/CSP checks,
and
  isolated-worker placement audit pass

Advances the next-major implementation milestone tracked in #169.
@github-actions

github-actions Bot commented Jul 26, 2026

Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 97.83% (🎯 97%) 8392 / 8578
🔵 Statements 97.63% (🎯 97%) 8680 / 8890
🔵 Functions 99.62% (🎯 99%) 1064 / 1068
🔵 Branches 96.35% (🎯 96%) 6732 / 6987
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/bounded-sql-lexer.ts 100% 100% 100% 100%
src/column-catalog-batch-coordinator.ts 99.37% 95.95% 96.96% 99.33% 530-533
src/column-catalog-boundary.ts 100% 100% 100% 100%
src/column-catalog-types.ts 0% 0% 0% 0%
src/column-completion.ts 100% 97.56% 100% 100%
src/column-query-site.ts 98.16% 95.73% 100% 99.48% 416, 515, 534, 543
src/cte-layout.ts 96.44% 95.02% 100% 96.42% 393, 548, 562-564, 784, 879-881, 924, 1334, 1380, 1599-1602, 1694, 1776, 1824-1826
src/index.ts 0% 0% 0% 0%
src/lexical.ts 99.17% 98.29% 100% 99.15% 71
src/local-relation-site.ts 100% 100% 100% 100%
src/namespace-catalog-boundary.ts 96.84% 96.77% 100% 99.38% 105, 160, 265, 275, 291, 496
src/namespace-catalog-coordinator.ts 98.46% 98.88% 96.42% 98.34% 153, 463-466
src/namespace-catalog-types.ts 0% 0% 0% 0%
src/namespace-completion.ts 100% 100% 100% 100%
src/node-module.d.ts 0% 0% 0% 0%
src/node-sql-parser-adapter.ts 96.42% 96.49% 100% 96.36% 81, 108, 153, 245-249
src/node-sql-parser-backend.ts 100% 100% 100% 100%
src/node-sql-parser-browser-executor.ts 97.73% 96.52% 100% 97.72% 475, 560, 657, 683, 917, 963-967, 1071
src/node-sql-parser-browser-worker-endpoint.ts 98.14% 96.55% 100% 98.14% 184, 335
src/node-sql-parser-query-bindings.ts 96.23% 95.57% 100% 96.12% 98, 105, 280, 434, 732, 776, 939, 951, 978, 1040, 1082, 1095, 1103, 1139-1143, 1223-1225, 1249
src/node-sql-parser-wire.ts 96.39% 97.72% 100% 96.36% 92, 225, 236, 378-380
src/query-binding-model.ts 99.05% 98.25% 100% 99.02% 356, 830, 836
src/query-site.ts 96.55% 95.25% 100% 96.54% 391, 544-545, 571, 658, 777, 799, 863, 949-952, 1004, 1007, 1012-1015, 1113, 1205, 1291-1294, 1332, 1340-1343
src/relation-catalog-boundary.ts 96.17% 96.09% 100% 96.12% 285-286, 294-295, 383, 421, 446, 457, 514, 571, 609, 713, 719, 795
src/relation-catalog-epoch-coordinator.ts 98.26% 97.26% 98.21% 98.86% 245, 341, 397-398, 430, 544, 1005, 1049
src/relation-catalog-search-policy-store.ts 99.52% 95.59% 100% 99.49% 674
src/relation-catalog-search-work.ts 97.48% 95.22% 100% 98.01% 568, 580-581, 908, 1068, 1089, 1148-1149, 1283, 1297, 1374, 1389, 1450-1459, 1640, 1725, 1973-1977, 2060-2065
src/relation-completion-types.ts 100% 100% 100% 100%
src/relation-completion.ts 98.46% 95.74% 100% 99.19% 174, 286
src/relation-dialect.ts 96.72% 96.47% 100% 96.63% 144, 295, 323, 380, 386, 425, 632, 733, 747, 809, 822, 828, 836, 881, 1038, 1048, 1086, 1349
src/relation-query-site.ts 100% 100% 100% 100%
src/relation-runtime-auth.ts 100% 100% 100% 100%
src/session.ts 96.92% 95.35% 98.88% 97.26% 196, 686, 798, 841, 1316-1320, 1359, 1397, 1493, 1530, 1558, 1602-1605, 1905-1911, 1914-1917, 1933-1937, 1970-1973, 2018-2021, 2045-2049, 2126-2129, 2138-2144, 2151-2154, 2158-2162, 2240-2244, 2276-2279, 2315-2318, 2858-2861
src/source.ts 99.09% 98.57% 100% 99.07% 191-194
src/statement-boundary-types.ts 0% 0% 0% 0%
src/statement-index.ts 97.97% 96.15% 100% 97.94% 286, 690, 889, 910, 1023, 1088-1090, 1112
src/syntax.ts 97.91% 95.16% 100% 97.9% 650-653, 680-683, 688-691, 965-968, 1194-1197, 1240-1242
src/types.ts 100% 100% 100% 100%
src/codemirror/index.ts 0% 0% 0% 0%
src/codemirror/relation-completion-types.ts 0% 0% 0% 0%
src/codemirror/sql-editor.ts 98.8% 96.53% 100% 99.35% 481, 655, 659, 733
src/codemirror/statement-gutter.ts 96.61% 96.36% 100% 98.18% 104, 136
Generated in workflow #774 for commit 8773014 by the Vitest Coverage Report Action

Comment thread demo/index.ts Fixed
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