Skip to content

Coded vector DDL follows the codec settings this user can have on - #115

Merged
pufit merged 2 commits into
mainfrom
pufit/codec-probe-readonly
Oct 22, 2026
Merged

pufit merged 2 commits into
mainfrom
pufit/codec-probe-readonly

Conversation

@pufit

@pufit pufit commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in a release)

Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

On a ClickHouse server that holds enable_quantized_codec at 0, as ClickHouse Cloud does until the operator enables the codec for the service, a fresh install creates its vector tables plain instead of failing its migration with code 452. Where allow_suspicious_codecs is held at 0, as on ClickHouse Cloud, entity_vectors is coded without its LZ4 chain instead of failing to create.

Why

Loom took the Quantized codec for available whenever system.settings listed enable_quantized_codec, and sent SETTINGS enable_quantized_codec = 1 with every coded CREATE. ClickHouse Cloud lists the setting but holds it read-only: its default is 0, and the operator enables it per service with a settings-profile override. Where it is held at 0 the server refuses that statement (Code: 452 SETTING_CONSTRAINT_VIOLATION: Setting enable_quantized_codec should not be changed), so a fresh install failed at its first coded table instead of creating the plain layout that docs/architecture/clickhouse.md describes for a server without the codec. With the codec enabled (held at 1), allow_suspicious_codecs stays held at 0, and the entity_vectors CREATE, whose CODEC(Quantized(...), LZ4) needs it, failed: code 36 without the setting, 452 with it.

Every path that creates a coded table now reads each codec setting's value, readonly, min, max and disallowed_values before it sends anything, through one object (CodecSettings in server/core/schema/vector_codec_ddl.py), the way _nlp_available already reads allow_experimental_nlp_functions. A setting is settable when this user may set it to 1, and held otherwise: readonly = 1 (a <readonly/> constraint), or a <max>0</max> or <disallowed>1</disallowed> constraint, which system.settings shows with readonly = 0.

State enable_quantized_codec allow_suspicious_codecs
settable coded; sent with each coded CREATE LZ4 chain kept; sent with the chained CREATE
held at 1 coded; not sent chain kept; not sent
held at 0 plain layout entity_vectors coded with Quantized alone; not sent
absent (before 26.8) plain layout as held at 0

A held setting is left out even at 1. ClickHouse skips an unchanged value of a read-only setting (SettingsConstraints::getNewValueToCheck, the same in the Cloud build), and clickhouse-connect 1.9 drops one before sending it; leaving it out depends on neither.

Scope and risk

Every caller goes through the same object:

  • the migration runner (server/core/schema/migrate.py): the fresh-install layout and each coded CREATE's settings; the layout line says why tables are plain or lose their chain;
  • server/core/vectors/codes_state.py: codec_available counts a codec held at 0 as unavailable;
  • the provider rebuild's candidate table (server/insights/store/provider_prepared.py): refused before its CREATE where the codec cannot be on (an owned stale candidate is dropped first), its chain dropped where it must be; on 26.7 the allow_experimental_codecs gate follows the same rule;
  • scripts/ops/vector_codec_rebuild.py: refuses to run where the codec cannot be on, and refuses --chain where allow_suspicious_codecs cannot be; a held setting goes with no statement, the copy, the deltas and --rollback included;
  • dev/restore_loom.py: refuses a backup that holds coded tables before anything is written, --dry-run included and again under the restore lock, where the settings cannot be read (reported as a failed read) or the codec cannot be on; drops the chain on an explicit CREATE.

Untouched: stored rows, existing tables, the migration files (byte-identical), the read-side vector_search_use_quantized_codes probe, wire ops, auth and tenant isolation. The change only decides the DDL and the settings sent with it.

Storage cost: without the chain, entity_vectors.entity_embedding loses the LZ4 that compresses its repeated vectors about 4x (the figure CODED_TABLES records), so that column takes about four times the space. The operator either enables allow_suspicious_codecs for Loom's user and runs scripts/ops/vector_codec_rebuild.py --table entity_vectors --columns entity_embedding --chain LZ4, or accepts the larger column. docs/architecture/clickhouse.md and docs/operations/deployment.md say so.

Known gaps:

  • Follow-up: codes_state.codec_available stays False until restart (server/core/vectors/codes_state.py, probe and _has_codec). The documented Cloud path, enable the codec and then run the rebuild online, leaves a running Loom at False after the swap; refuse_width then skips its fresh-read wait and served_model_writes_coded() answers False when there is no reading. Widths still refresh every 60 s. Fix: ask again while the answer is False, or document a restart.
  • Follow-up: in the migration runner, a failed system.settings read still falls back to "no Quantized codec here (it needs 26.8 or later)" (_codec_settings; the pattern predates this change). A row the parser cannot read now raises instead of reading as no codec, and the restore reports a failed read as such.
  • Follow-up: _new_table_layout returns before _install_vector_width when the codec is held at 0, so an install that already holds coded tables gets new vector tables plain: a mixed layout, against that function's rule, where the old code failed with 452. The layout line is printed, so it is not silent.
  • Test coverage: the provider rebuild's 26.7 path with the chain held at 0 or absent; staging_ddl in states other than settable; the rebuild tool across all 16 state pairs (each axis's four states are covered on their own).
  • Predates this change and unreachable today: _apply_file hands rebuild-if-empty targets to table_rebuild.apply before the coded rewrite and the probe run; no migration uses that directive now.
  • The restore's staging copy (CREATE TABLE … AS) carries the target table's codecs and cannot drop a chain: a target table coded with the chain, on a server that now holds allow_suspicious_codecs at 0, fails at its staging copy after earlier tables were restored. The up-front refusal covers the backup's recorded DDL only.
  • The probe reads system.settings on the replica that answers; replicas with different profiles are not compared.
  • The integration suite was not run locally: it needs ClickHouse 26.8 or later.

Compatibility, rollout and rollback

  • Wire: none. No op, field or default changed.
  • Operator steps: none on a self-hosted server, where both settings are settable and the layout and the settings sent are as before. On ClickHouse Cloud, coded tables need the operator to enable enable_quantized_codec for the service; an install made before that is plain, and scripts/ops/vector_codec_rebuild.py codes its tables once the setting is on. Servers before 26.8 keep the plain layout; the one difference there is that scripts/ops/vector_codec_rebuild.py on 26.7 refuses with the reason instead of failing on UNKNOWN_SETTING.
  • Rollback: reverting leaves no rows, migrations or generated files. Tables created plain, or entity_vectors created without the chain, keep that layout; the rebuild tool moves them.

Tests

  • tests/unit/test_vector_codec_ddl.py (88 cases): the four states and each constraint shape (<max>0</max> over 0 and over 1, <disallowed>1</disallowed>, <min>1</min>, <min>0</min><max>1</max>, a bound that is not a number); every pair of states through the migration runner (_apply_pending against a fake that answers system.settings), asserting the statements sent and their settings; each constraint shape through the runner; the layout line; the chain drop; a row of another shape raising.
  • tests/unit/test_provider_prepared.py (45): every state pair, each constraint shape on both settings, the 26.7 gate in four states, and a held-off enable_quantized_codec not replaced by the 26.7 gate.
  • tests/unit/test_vector_codes_state.py (42): codec_available for every state and shape.
  • tests/unit/test_vector_codec_rebuild_tool.py (24): the refusal in each state, the --chain refusal in each state, and the settings on the CREATE, the copy, the deltas and --rollback.
  • tests/unit/test_backup_restore_cli.py (63): every pair through check_codec and execute, the dry-run refusal (held at 0, absent, failed read), the second check under the lock (nothing but the lock written), and a restore that drops the chain.
  • Four deliberate regressions each fail between 14 and 28 of these tests: listed taken for usable, a held setting sent, the chain never dropped, and min / max / disallowed_values ignored.
  • At this head (8993167, on 982709b): ruff check and ruff format --check, the function-length and secrets gates, the mypy gate (0 errors) and mypy --strict sdk/python/loom, every generator's --check, Prettier on the changed docs; the touched tests under two -p randomly seeds (387 passed each); tests/unit once: 21,910 passed, 281 skipped, 1 xfailed, 4 failed. The 4 also fail on a clean main at b8cdcb3: test_profile_consolidation.py::test_default_fold_reads_stated_facts_only and ::test_folds_stale_identity_into_a_profile_section, test_profile_schema.py::test_the_prompt_fences_the_facts_and_names_each_property, test_erasure_cache_key_axis.py::test_redact_handler_reports_the_cache_and_precedent_rows_it_deleted. pytest bench: 191 passed.
  • On a private ClickHouse 26.6 server with <readonly/>, <max>0</max> and <disallowed>1</disallowed> constraints: a read-only setting sent at its current value is accepted, in a SETTINGS clause and as an HTTP parameter, and another value is refused with 452; <max>0</max> and <disallowed>1</disallowed> show readonly = 0 and refuse 1 with 452. clickhouse-connect 1.9.0 drops a read-only setting sent at the server's value, raises ProgrammingError for another value by default, and sends it (452) under invalid_setting_action = "send", which migrate.client() sets.
  • On a ClickHouse Cloud 26.8 service whose operator enabled the codec (enable_quantized_codec value 1, default 0, readonly 1; allow_suspicious_codecs value 0, readonly 1): the migration runner at this branch created entity_vectors coded without the chain and sent no codec setting, and the previous code failed the same CREATE with 452. A bare CODEC(Quantized('rabitq', 3072, 0)) CREATE succeeded with and without SETTINGS enable_quantized_codec = 1.
  • Not run: the integration suite (no ClickHouse 26.8 or later locally) and make test-mixed-version (no migration, row or wire change).

AI assistance in the code (leave one; writing this description with AI is fine):

  • AI-generated (an agent wrote most of the diff): a Claude agent run by Nerve. Checked: an independent agent review of the branch, the migration runner's path re-run on a ClickHouse Cloud 26.8 service, and the server and driver behaviour above on a private ClickHouse.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • make format-check, make lint, make typecheck and make test-unit pass; the integration suite passes if server behaviour changed. Ran locally: ruff, Prettier on the changed docs, the lint gates and generators, typecheck, and tests/unit (at 8993167 its only failures were the 4 tests main fixed in The tests behind main's red unit and integration jobs follow the code they exercise #116; none are expected at this head); Biome, taplo and shfmt (no files of theirs changed) and the integration suite did not run. Ticked once CI is green.
  • Generated files are regenerated in this PR, not by hand: the SDK op tables, docs/reference/configuration.md and the docs/reference/ tables (python scripts/codegen/docs_reference.py), the reach manifest, schemas/schema.sql (make schema-dump) and the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.py). None changed; every generator's --check passes.
  • (no migration) A new migration is additive and numbered after the latest on main; no merged migration is edited.
  • (no plugin file changed) A behaviour change to any file a plugin ships (hooks/, lib/, bin/, skills/, .mcp.json, the Codex plugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version.
  • (frontend not changed) The frontend builds (npm --prefix frontend run build) and its tests pass, if frontend/ changed.
  • Docs under docs/ describe the system as it now is, and this description names any operator steps and wire changes.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers; the history goes in this description (tests/unit/test_public_copy.py).
  • Commits are signed off (git commit -s), as CONTRIBUTING.md asks.

Generated by Nerve

Loom took enable_quantized_codec for available whenever system.settings
listed it. ClickHouse Cloud lists it but holds it read-only: its default
is 0, and the operator enables it per service with a settings-profile
override. Where it is held at 0, the coded CREATE sent
SETTINGS enable_quantized_codec = 1 and the server refused it (code 452),
so a fresh install failed instead of creating the plain layout. With the
codec enabled, allow_suspicious_codecs stays read-only at 0 there, and the
entity_vectors CREATE failed on its LZ4 chain (code 36 without the
setting, 452 with it).

Every path that creates a coded table reads value, readonly, min, max and
disallowed_values of the codec settings before it sends any
(vector_codec_ddl.CodecSettings). A setting is held when this user may not
set it to 1: readonly, or a <max>0</max> or <disallowed>1</disallowed>
constraint, which system.settings shows with readonly = 0.

  state           enable_quantized_codec   allow_suspicious_codecs
  settable        coded, sent              LZ4 chain kept, sent
  held at 1       coded, not sent          LZ4 chain kept, not sent
  held at 0       plain layout             Quantized alone, not sent
  absent          plain layout             Quantized alone, not sent

- the migration runner's fresh-install layout, and codes_state's
  codec_available;
- the provider rebuild's candidate table: refused before its CREATE where
  the codec cannot be on (an owned stale candidate is dropped first), its
  chain dropped where it must be; 26.7 keeps the allow_experimental_codecs
  gate under the same rule;
- scripts/ops/vector_codec_rebuild.py: refuses to run where the codec
  cannot be on, and refuses --chain where allow_suspicious_codecs cannot
  be; a held setting goes with no statement, the copy, the deltas and a
  rollback included;
- dev/restore_loom.py: refuses a backup with coded tables before anything
  is written, --dry-run included, where the codec settings cannot be read
  or the codec cannot be on (checked again under the restore lock), and
  drops the chain on an explicit CREATE.

Without the chain, entity_vectors.entity_embedding takes about four times
the space LZ4 gave it: the operator enables allow_suspicious_codecs and
rebuilds that table with --chain LZ4, or accepts the larger column.

The server accepts a held setting sent at its current value, and
clickhouse-connect drops a readonly one before sending; a held setting is
left out so neither is relied on. Servers where both settings are
settable, and servers before 26.8, take the same layout and settings as
before. The one difference on 26.7: scripts/ops/vector_codec_rebuild.py
refuses with the reason instead of failing on UNKNOWN_SETTING.

Unit tests cover every state pair and each constraint shape at the
migration runner and the provider rebuild, and each tool's refusal and
degrade branch.

Signed-off-by: pufit <[email protected]>
@pufit
pufit force-pushed the pufit/codec-probe-readonly branch from 8993167 to 5a15c0a Compare October 21, 2026 14:15
@zlareb1
zlareb1 requested a balanced review from Copilot October 21, 2026 20:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Negative capability caching bypasses width freshness checks, restore staging can retain forbidden chains, and chain rewriting alters quoted defaults.

3 open issues
What changed in this PR

Vector table creation now follows the codec settings permitted for the ClickHouse user, allowing plain installs when Quantized is unavailable.

Changes:

  • Centralizes codec constraint checks across migrations, rebuilds, and restore.
  • Omits held settings and removes unsupported codec chains.
  • Adds state-based regression tests and operator documentation.
File Description
tests/​unit/​test_vector_codes_state.py Tests codec availability states.
tests/​unit/​test_vector_codec_rebuild_tool.py Tests rebuild refusals and settings.
tests/​unit/​test_vector_codec_rebuild_runner.py Updates chained-codec assertions.
tests/​unit/​test_vector_codec_ddl.py Tests constraints and migration layouts.
tests/​unit/​test_provider_prepared.py Tests candidate creation across settings.
tests/​unit/​test_migrate_mutation_wait.py Updates codec probe mocks.
tests/​unit/​test_migrate_ledger_report.py Updates migration test fixtures.
tests/​unit/​test_migrate_lease.py Updates lease test probe mock.
tests/​unit/​test_migrate_keeper_lock.py Updates lock test probe mock.
tests/​unit/​test_ch_insert_vector_widths.py Updates codec settings fixture.
tests/​unit/​test_backup_restore_cli.py Tests restore codec preflight.
tests/​unit/​codec_states.py Adds shared settings fixtures.
server/​insights/​store/​provider_prepared.py Applies constraints to candidate creation.
server/​core/​vectors/​codes_state.py Checks usable codec availability.
server/​core/​schema/​vector_codec_ddl.py Centralizes settings and chain rewriting.
server/​core/​schema/​migrate.py Selects permitted vector layouts.
scripts/​ops/​vector_codec_rebuild.py Checks rebuild settings before writes.
docs/​operations/​maintenance.md Clarifies coded-width prerequisites.
docs/​operations/​deployment.md Documents Cloud codec configuration.
docs/​operations/​backup-and-recovery.md Documents restore codec checks.
docs/​guides/​performance-tuning.md Clarifies coded-storage prerequisites.
docs/​development/​migrations.md Documents constraint-aware migration DDL.
docs/​architecture/​provider-reconfiguration.md Describes candidate codec adaptation.
docs/​architecture/​failure-and-recovery.md Clarifies codec-dependent scan savings.
docs/​architecture/​clickhouse.md Documents settings and storage tradeoffs.
dev/​restore_loom.py Adds codec preflight and DDL adaptation.

Review effort: Balanced

log.info("codec probe failed: %s", str(e)[:160])
return None
return bool(rows and int(rows[0].get("n") or 0))
return CodecSettings.from_rows(rows).codec
Comment thread dev/restore_loom.py
return local, create_settings(source)
return f"CREATE TABLE {staging} AS `{database}`.`{table}`", create_settings(source)
return create_statement(local, codec)
return f"CREATE TABLE {staging} AS `{database}`.`{table}`", create_statement(source, codec)[1]
`CODEC(Quantized('rabitq', 1024, 0), LZ4)` becomes `CODEC(Quantized('rabitq', 1024, 0))`.
Only the compression of the stored codes changes; without
`allow_suspicious_codecs` the server refuses the chain (code 36)."""
return _CHAIN_RE.sub(r"\1)", stmt)
@pufit

pufit commented Oct 22, 2026

Copy link
Copy Markdown
Member Author

Re-opening to re-run CI against current main (the last run predates the fixes merged on main).

@pufit pufit closed this Oct 22, 2026
@pufit pufit reopened this Oct 22, 2026
@pufit

pufit commented Oct 22, 2026

Copy link
Copy Markdown
Member Author

Re-opening once more: the previous re-run was created before GitHub refreshed the test-merge commit and tested a stale merge (N-1 newer than N in the mixed-version gate).

@pufit pufit closed this Oct 22, 2026
@pufit pufit reopened this Oct 22, 2026
@pufit
pufit merged commit a8f4ee4 into main Oct 22, 2026
22 checks passed
@pufit
pufit deleted the pufit/codec-probe-readonly branch October 22, 2026 03:08
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.

3 participants