Repository navigation
Coded vector DDL follows the codec settings this user can have on - #115
Merged
Merged
Conversation
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
force-pushed
the
pufit/codec-probe-readonly
branch
from
October 21, 2026 14:15
8993167 to
5a15c0a
Compare
zlareb1
approved these changes
Oct 21, 2026
There was a problem hiding this comment.
🟡 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 |
| 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) |
Member
Author
|
Re-opening to re-run CI against current main (the last run predates the fixes merged on main). |
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). |
Signed-off-by: pufit <[email protected]>
5 of 6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Changelog category (leave one):
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_codecat 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. Whereallow_suspicious_codecsis held at 0, as on ClickHouse Cloud,entity_vectorsis coded without itsLZ4chain instead of failing to create.Why
Loom took the
Quantizedcodec for available wheneversystem.settingslistedenable_quantized_codec, and sentSETTINGS enable_quantized_codec = 1with every codedCREATE. 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 thatdocs/architecture/clickhouse.mddescribes for a server without the codec. With the codec enabled (held at 1),allow_suspicious_codecsstays held at 0, and theentity_vectorsCREATE, whoseCODEC(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,maxanddisallowed_valuesbefore it sends anything, through one object (CodecSettingsinserver/core/schema/vector_codec_ddl.py), the way_nlp_availablealready readsallow_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, whichsystem.settingsshows withreadonly = 0.enable_quantized_codecallow_suspicious_codecsCREATELZ4chain kept; sent with the chainedCREATEentity_vectorscoded withQuantizedalone; not sentA 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:
server/core/schema/migrate.py): the fresh-install layout and each codedCREATE's settings; the layout line says why tables are plain or lose their chain;server/core/vectors/codes_state.py:codec_availablecounts a codec held at 0 as unavailable;server/insights/store/provider_prepared.py): refused before itsCREATEwhere the codec cannot be on (an owned stale candidate is dropped first), its chain dropped where it must be; on 26.7 theallow_experimental_codecsgate follows the same rule;scripts/ops/vector_codec_rebuild.py: refuses to run where the codec cannot be on, and refuses--chainwhereallow_suspicious_codecscannot be; a held setting goes with no statement, the copy, the deltas and--rollbackincluded;dev/restore_loom.py: refuses a backup that holds coded tables before anything is written,--dry-runincluded 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 explicitCREATE.Untouched: stored rows, existing tables, the migration files (byte-identical), the read-side
vector_search_use_quantized_codesprobe, 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_embeddingloses theLZ4that compresses its repeated vectors about 4x (the figureCODED_TABLESrecords), so that column takes about four times the space. The operator either enablesallow_suspicious_codecsfor Loom's user and runsscripts/ops/vector_codec_rebuild.py --table entity_vectors --columns entity_embedding --chain LZ4, or accepts the larger column.docs/architecture/clickhouse.mdanddocs/operations/deployment.mdsay so.Known gaps:
codes_state.codec_availablestays False until restart (server/core/vectors/codes_state.py,probeand_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_widththen skips its fresh-read wait andserved_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.system.settingsread 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._new_table_layoutreturns before_install_vector_widthwhen 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.staging_ddlin states other than settable; the rebuild tool across all 16 state pairs (each axis's four states are covered on their own)._apply_filehandsrebuild-if-emptytargets totable_rebuild.applybefore the coded rewrite and the probe run; no migration uses that directive now.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 holdsallow_suspicious_codecsat 0, fails at its staging copy after earlier tables were restored. The up-front refusal covers the backup's recorded DDL only.system.settingson the replica that answers; replicas with different profiles are not compared.Compatibility, rollout and rollback
enable_quantized_codecfor the service; an install made before that is plain, andscripts/ops/vector_codec_rebuild.pycodes its tables once the setting is on. Servers before 26.8 keep the plain layout; the one difference there is thatscripts/ops/vector_codec_rebuild.pyon 26.7 refuses with the reason instead of failing onUNKNOWN_SETTING.entity_vectorscreated 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_pendingagainst a fake that answerssystem.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-offenable_quantized_codecnot replaced by the 26.7 gate.tests/unit/test_vector_codes_state.py(42):codec_availablefor every state and shape.tests/unit/test_vector_codec_rebuild_tool.py(24): the refusal in each state, the--chainrefusal in each state, and the settings on theCREATE, the copy, the deltas and--rollback.tests/unit/test_backup_restore_cli.py(63): every pair throughcheck_codecandexecute, 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.min/max/disallowed_valuesignored.8993167, on982709b):ruff checkandruff format --check, the function-length and secrets gates, the mypy gate (0 errors) andmypy --strict sdk/python/loom, every generator's--check, Prettier on the changed docs; the touched tests under two-p randomlyseeds (387 passed each);tests/unitonce: 21,910 passed, 281 skipped, 1 xfailed, 4 failed. The 4 also fail on a cleanmainatb8cdcb3:test_profile_consolidation.py::test_default_fold_reads_stated_facts_onlyand::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.<readonly/>,<max>0</max>and<disallowed>1</disallowed>constraints: a read-only setting sent at its current value is accepted, in aSETTINGSclause and as an HTTP parameter, and another value is refused with 452;<max>0</max>and<disallowed>1</disallowed>showreadonly = 0and refuse 1 with 452. clickhouse-connect 1.9.0 drops a read-only setting sent at the server's value, raisesProgrammingErrorfor another value by default, and sends it (452) underinvalid_setting_action = "send", whichmigrate.client()sets.enable_quantized_codecvalue 1, default 0, readonly 1;allow_suspicious_codecsvalue 0, readonly 1): the migration runner at this branch createdentity_vectorscoded without the chain and sent no codec setting, and the previous code failed the sameCREATEwith 452. A bareCODEC(Quantized('rabitq', 3072, 0))CREATEsucceeded with and withoutSETTINGS enable_quantized_codec = 1.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 typecheckandmake test-unitpass; the integration suite passes if server behaviour changed. Ran locally: ruff, Prettier on the changed docs, the lint gates and generators, typecheck, andtests/unit(at8993167its only failures were the 4 testsmainfixed 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.docs/reference/configuration.mdand thedocs/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--checkpasses.main; no merged migration is edited.hooks/,lib/,bin/,skills/,.mcp.json, the Codexplugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version.npm --prefix frontend run build) and its tests pass, iffrontend/changed.docs/describe the system as it now is, and this description names any operator steps and wire changes.tests/unit/test_public_copy.py).git commit -s), as CONTRIBUTING.md asks.