# Drift log
Decisions made during the TS → Python port that diverge from a 1:1 copy
(due to language idioms, ecosystem conventions, or explicit "won't port")
plus open questions that need human review before they harden.
This document is append-only. Each entry should let a future reviewer
decide "leave it" vs "revisit." Don't delete entries — strike them with
`~~RESOLVED~~` and add a note.
---
## Conventions established (load-bearing — change before more code depends on them)
### Plugin obsessiondb package name
- **Where:** `src/chkit/cli/commands/init.py` (`OBSESSIONDB_PLUGIN_MODULE = "chkit_plugin_obsessiondb"`).
- **Decision:** The Python port of `@chkit/plugin-obsessiondb` will be a top-level
package `chkit_plugin_obsessiondb` (PyPI dist `chkit-plugin-obsessiondb`), with
a top-level callable `run_onboarding(*, config_path, connect, email, code, org_name)`.
- **Alternative considered:** namespaced under `chkit.plugins.obsessiondb`, or a class
with methods. Chose top-level for parity with `@chkit/plugin-obsessiondb` (npm scoped name),
and free function for simplicity (TS exports a free `runOnboarding`).
- **Status:** Open for revision. Any change here means rewriting `init.py`'s dispatch.
### --auto-deps: not portable by Python convention
- **TS:** `init` runs `npm install` if `@chkit/core` can't be resolved.
- **Python decision:** Don't port. Python ecosystem prefers explicit `pip install chkit-py`.
- **Status:** Recorded in HTML notes; no code change needed.
---
## Items "plumbed-pending-dependency" (NOT counted as done in HTML)
These have flag-level scaffolding in Python but the actual feature behaviour
depends on a still-pending dependency. They are intentionally unmarked in
`PORTED_BY_DEFAULT` and listed in `PLUMBED_PENDING_DEPENDENCY` for tracking.
| Item | What's plumbed | What's missing |
|---|---|---|
| `init/--connect` | Typer flag + Enum + threading to `run_onboarding` | `chkit_plugin_obsessiondb` package |
| `init/--email` | same | same |
| `init/--code` | same | same |
| `init/--org-name` | same | same |
| `init/onboarding` | Dispatch via importlib, silent degrade | same |
| `init/auto-deps` | Decision: WON'T port (Python convention) | n/a |
---
## Refactors that touched pre-existing Python code
### cli/schema_loader → wrapper of core/schema_loader
- **Was:** `cli/schema_loader.py` had its own `_discover_paths` + `_load_module` + `_collect`.
- **Now:** trivial wrapper of `chkit.core.schema_loader.load_schema_definitions`.
- **Why:** parity with TS where the loader lives in `@chkit/core` (CLI doesn't re-implement).
- **Risk:** Changes the module-name convention used by `sys.modules` (counter-based instead
of hash-based). User schema modules that introspect their own `__name__` would see
different values. Highly unlikely to matter.
### Module-load bug fix (mtime cache)
- **Was:** Both `cli/schema_loader.py` and the new `core/ts_import.py` used
`importlib.util.spec_from_file_location` → `exec_module`, which is gated by
Python's mtime-keyed bytecode cache.
- **Bug:** On Windows NTFS (mtime granularity ~10 ms) consecutive rewrites of the same
schema file within the same second loaded the cached bytecode — old content.
Surfaced as a phantom "target table missing" in the `--rename-table` E2E tests.
- **Fix:** Both loaders now use `compile()` + `exec()` directly with a unique
synthetic module name per call (monotonic counter). This always re-reads source.
- **Behaviour change in production:** chkit no longer benefits from Python's bytecode
cache for user config / schema files. For files compiled once per CLI run, the cost
is negligible.
---
## Bugs found while porting (fixed)
### status: project-scoped `applied` count
- **Found in:** `cli/commands/status.py`
- **Was:** `payload["applied"] = len(journal.applied)` — counted EVERY journal row,
including those written by other chkit projects sharing the same `_chkit_migrations`
table (ObsessionDB tenant pattern). Surfaced as "Applied: 2 / Pending: 0 / Total: 0"
in fresh project directories whose journal still had stale rows from other tests.
- **Fixed:** intersect with this project's migrations dir, mirroring TS `status.ts`
comment #31. Surface-level only — the deeper journal-store filter still lives in
the pending item `journal/project-scoped`.
---
## TS-only modules not ported (decision: N/A by design)
These TS runtime modules don't have meaningful Python equivalents — the
ecosystem ships them differently. Each is marked done in the HTML with a
comment, and the rationale lives here.
### rt/cmd-dispatch, rt/cmd-registry, rt/global-flags, rt/extract-config, rt/help
- **TS:** ~500 LoC across 5 modules that parse argv, build a flag-merging
command registry, pre-extract `--config` before normal parsing, and
format help text grouped by core / plugin.
- **Python:** Typer does all of this:
- `app.command(...)` is the registry; flag merging happens via decorator stacking.
- `Annotated[T, typer.Option(...)]` declares flags per-command; the `--config`
flag is loaded inside each command body so no pre-parse hack is needed.
- Typer auto-generates `--help` from docstrings and Option help= strings.
- **What's lost:** the explicit "core commands vs plugin commands" grouping in
the top-level `--help` listing. Could be added as a Typer rich-help-panel
if/when chkit-py grows enough plugins to warrant it.
### rt/internal-plugins, rt/internal-core
- **TS:** an aggregator that wraps the 7 core commands as a `core` plugin,
so the runtime treats them uniformly with third-party plugins.
- **Python:** core commands are registered directly on the Typer app
(`app.command("generate")(generate.run)`, etc.). The plugin runtime only
manages user-registered plugins. No functional difference for end users.
### rt/skill-hint-*
- **TS:** detects Claude / Cursor / Copilot via filesystem checks and prompts
for an AI skill install; 30-day cooldown via state file.
- **Python:** niche, not blocking any chkit feature. Deferred indefinitely.
### cmd-skills
- **TS:** proxy to external `npx skills` command.
- **Python:** no equivalent in the Python ecosystem. Deferred.
### create-chkit
- **TS:** standalone `bun create chkit@latest
` scaffolder. Downloads an
example from a GitHub tarball, transforms ``package.json`` (sets project
name + package-manager pinning), runs ``bun/npm/pnpm/yarn install``, then
hands off to ``runOnboarding`` for the connect-to-DB flow.
- **Python:** the npm-side shape doesn't translate: there's no Python
convention equivalent to ``bun create ``, no ``package.json`` to
rewrite, and no package-manager auto-detection (pip is the universal
baseline). What's load-bearing in the TS flow — the connect-to-DB wizard
and the next-steps print-out — is already covered by ``chkit init`` in
the Python port (which dispatches to ``run_onboarding`` from the
obsessiondb plugin, see Phase 4 above).
- **What's lost vs TS:** the curated-examples picker (``EXAMPLES`` manifest
+ ``downloadExample``). If Python users start asking for multi-template
scaffolding, the natural place to add it is a new ``chkit init --example
`` flag, NOT a separate ``create-chkit`` binary. Marked
``cc/python-equivalent`` in PORTED_BY_DEFAULT because the equivalent
user-facing flow exists; remaining sub-items (``cc/example-download``,
``cc/examples-manifest``, etc.) stay deferred until there's demand.
---
## Known limitations in ported features
### pull: backticked names containing dots
- **Where:** `cli/commands/pull_view_parser.py::parse_to_clause`
- **Behaviour:** ``TO `weird.db`.`weird table` `` is split on every `.`, breaking the
database name in two. Both TS and Python share this naive behaviour (the TS regex
also calls `.split('.')` on the captured identifier without respecting backticks).
- **Severity:** Low — a database name with `.` is exotic and would generally need to
be quoted at the SQL level too. Documented for future tokeniser-based rewrite.
### pull: simplified vs. TS plugin
- TS plugin has a custom-introspector hook (used by `obsessiondb` to route through
its API). Not ported here — deferred to obsessiondb plugin port.
- TS plugin uses Zod-validated options. Python uses Typer + plain CLI args; the
programmatic `PullPluginOptions` surface isn't exposed yet (will be needed when
the plugin runtime ports).
---
## ObsessionDB plugin port status
Phase 1 (this turn): **shipped**
- ``chkit_plugin_obsessiondb.credentials`` — XDG-compliant 0600 file
- ``chkit_plugin_obsessiondb.storage`` — project + user-global service state
- ``chkit_plugin_obsessiondb.engine`` — rewrite Shared* engines + strip cloud
settings (auto-detected via URL; ``--force-shared-engines`` / ``--no-shared-engines`` overrides)
- ``chkit_plugin_obsessiondb.plugin`` — ``obsessiondb()`` factory with the
``on_schema_loaded`` hook attached
- ``chkit_plugin_obsessiondb.onboarding.run_onboarding(...)`` — entry point
``chkit init`` calls. Today: prints the runbook (authenticated branch +
unauthenticated branch). Tomorrow: full wizard.
Phase 2 (this turn): **HTTP API + auth flows shipped**
- ``api_client.py`` — request_device_code / poll_device_token / get_session
/ send_verification_otp / verify_otp / create_organization /
set_active_organization (httpx-based; OtpRateLimitError on HTTP 429)
- ``auth_login.py`` — ``run_login`` (RFC 8628 device code + browser open +
poll), ``run_logout``, ``run_whoami`` (with --json envelope)
- ``auth_signup.py`` — ``run_signup`` with all three modes: interactive TTY,
two-step CI (``--request-only`` then ``--code``), scripted (``--email`` +
``--code`` skips re-send). Auto-creates a personal organisation
(``derive_org_name`` strips ``+subaddress``; ``slugify_org_name`` appends
a 6-char random suffix).
- ``plugin.py`` — ``ChxPluginCommand`` entries for ``login``, ``signup``,
``logout``, ``whoami`` dispatched via ``chkit plugin obsessiondb ``.
Phase 3 (this turn): **service management shipped**
- ``service_api.py`` — minimal oRPC client. Wire format: POST
``{base_url}/rpc/{procedure_path}`` with ``{"input": ...}`` body, ``Bearer``
token in ``Authorization``. HTTP 401 → ``SessionExpiredError``.
- ``service_select.py`` — ``render_service_organizations`` (pure) +
``select_service_interactive`` (auto-selects single, TTY-prompts otherwise).
- ``service_claim.py`` — ``run_claim`` end-to-end: eligibility → claim →
poll-until-running (5min deadline) → save selection. Handles
``already_claimed`` + ``none_available`` + ``provisioning_timeout`` with
``--json`` envelopes.
- ``service_commands.py`` — single ``service`` ``ChxPluginCommand`` that
dispatches on ``args[0]`` to ``list`` / ``select`` / ``claim`` /
``alias set|list|remove``.
**Resolved (#246)**: the ``{"input": ...}`` body guessed here was wrong; the
live API rejected it with ``400 Input validation failed``. ``_rpc_post`` now
speaks the oRPC RPC envelope that TS's ``RPCLink`` sends: ``{"json": input}``
in, ``{"json": output}`` out (unwrapped before validation). ``api_client.py``
(auth endpoints) was not touched or verified live.
**Resolved (#288)**: the services and session models declared snake_case
fields with no aliases, but the API sends camelCase (``createdAt``,
``activeOrganizationId``, ...), so ``services.listAll`` / ``services.get``
failed validation and ``get_session`` never saw the active organization. Every
console API model (services, jobs, auth session) now derives from
``api_model.ConsoleApiModel`` (``alias_generator=to_camel``,
``populate_by_name=True``). ``workbench_api`` keeps plain names: its result is
ClickHouse's snake_case JSON (``query_id``, ``bytes_read``). The opt-in
``tests_workbench_api/test_console_api_e2e.py`` checks each read-only call
(``listAll``, ``get``, ``instanceClaimStatus``, ``jobs.list``, ``get-session``)
and ``service list --json`` / ``whoami --json`` against the live API. Not run
live, because they create or change state or send email: ``claimInstance``,
``jobs.submit|get|cancel``, device-code login, the OTP signup calls and
``organization/create|set-active``. ``services.list`` and
``services.revealCredentials`` are in the TS contract copy but unused by
either CLI, so they are not ported.
Phase 4 (this turn): **remote executor + backfill routing + full wizard shipped**
- ``workbench_api.py`` — ``workbench_query_execute`` (POST
``/rpc/workbench/query/execute``) returns a ``WorkbenchExecuteResult``
with ``data``, ``meta``, ``rows``, ``statistics``, ``query_id``, ``error``.
- ``remote_executor.py`` — ``RemoteClickHouseClient`` is duck-typed (NOT
inheriting ``ClickHouseClient``) and exposes the same surface
(``execute``, ``query``, ``query_json``, ``submit``, ``query_status``,
``__enter__/__exit__``, ``database``) so drift/pull/migrate/query
commands work unchanged against a managed instance. ``query_status``
polls ``system.processes`` then ``system.query_log`` exactly like the
local client.
- ``jobs_api.py`` — ``jobs_get`` / ``jobs_list`` / ``jobs_cancel`` (oRPC).
- ``backfill_handler.handle_backfill_command`` — wired into the plugin as
an ``on_before_plugin_command`` hook. Routes ``status`` / ``cancel`` /
``list`` to the jobs API. ``--local`` flag or a ``--plan-id`` argument
bypass to the local backfill plugin (which is still pending port).
- ``onboarding.py`` — full wizard with ``ConnectChoice {claim, account,
clickhouse, later}``. ``_select_choice()`` is a plain numbered prompt
(no Questionary dep). ``ensure_obsessiondb_plugin_in_source`` is a pure
text-rewrite (regex over the ``"plugins"`` literal + import insertion)
so the config gets ``obsessiondb()`` auto-registered after the wizard.
- Init flags ``--connect`` / ``--email`` / ``--code`` / ``--org-name`` now
thread through ``run_onboarding`` — moved out of PLUMBED_PENDING_DEPENDENCY
in the checklist.
**Resolved (#246)**: workbench + jobs RPC paths share ``service_api._rpc_post``,
which now sends the oRPC ``{"json": ...}`` envelope (see Phase 3).
**Caveat (DRIFT)**: ``ensure_obsessiondb_plugin_in_source`` is a regex-based
rewriter. The TS version uses an AST mutation. We accept the regex for two
reasons: (a) the wizard runs against a freshly-scaffolded
``clickhouse.config.py`` whose ``"plugins"`` literal shape is known, and (b)
the rewriter is idempotent and silently no-ops if the literal is missing
(falling back to a printed instruction). If users start hand-editing the
config before connecting, we may need a proper AST pass.
**Caveat (DRIFT)**: ``RemoteClickHouseClient`` is not a subclass of
``ClickHouseClient`` because clickhouse-connect's ``Client`` is awkward to
construct without a real socket. Code that does ``isinstance(c,
ClickHouseClient)`` will fail; callers that just call methods on the result
of ``executor_factory`` work fine. The TS surface goes through an
``Executor`` interface so subtyping wasn't even a question there.
Decision: Phase 4 closes the obsessiondb plugin port. All five entry hooks
(``on_schema_loaded`` + ``on_before_plugin_command`` + five plugin commands)
are functional with ``mypy --strict`` and ``ruff`` clean over 17 source files.
---
## chkit_plugin_codegen — Pydantic model generator
The TS plugin emits a TypeScript ``.ts`` file with one ``type FooRow = { ... }``
per table plus optional Zod schemas, ingest helpers, and a migration runner.
The Python port (``chkit_plugin_codegen``) instead emits **one Pydantic
``BaseModel`` per table**, which covers static typing AND runtime validation in
a single shape. This is a meaningful reframe — recorded here so the next
review-pass knows where the surfaces differ.
**Shipped (Phase 5)**:
- ``type_artifacts.py`` — CH-type → Python-type mapping (recursive resolver
for ``Nullable`` / ``Array`` / ``Map`` / ``Tuple`` / ``LowCardinality`` /
``SimpleAggregateFunction`` / ``JSON``). ``fail_on_unsupported_type``
toggles raise-vs-warn behaviour. ``bigint_mode`` chooses ``int`` or ``str``
for 64-bit integers.
- ``naming.py`` — Pascal / camel / raw class-name styles with collision
suffixing. Non-identifier column names get sanitized and aliased via
``Field(..., alias=...)``.
- ``plugin.py`` — ``codegen()`` factory with one command (``codegen``) and
``on_check`` / ``on_check_report`` hooks. ``--check`` mode returns exit
code 1 on missing/stale output. Writes are atomic
(write-to-temp + ``os.replace``).
- ``options.py`` — Pydantic-validated ``CodegenOptions`` mirroring the TS
Zod schema. Accepts camelCase aliases.
- ``errors.py`` — ``CodegenConfigError`` (option parse) and
``UnsupportedTypeError`` (type resolution).
**Caveat (DRIFT)**: Zod, ingest-artifacts (``--emit-ingest``), and the
migration-runner module (``--emit-migrations``) are intentionally NOT ported.
Justification:
- **Zod**: Pydantic IS the validation layer. The TS plugin separates types
(compile-time) from Zod schemas (runtime); Pydantic collapses both, so a
separate emitter is dead weight.
- **Ingest helpers**: the TS version emits per-table ``insertFoo(rows)``
wrappers around clickhouse-client. In Python, ``clickhouse_connect.Client.insert``
+ a Pydantic model already covers this with one line at the call site; an
emitter would generate ~10 LoC per table for marginal value. Re-evaluate
if multiple users ask.
- **Migration runner**: the TS module embeds the ``.sql`` files into a
TypeScript array so the app can apply migrations without the CLI dependency.
The equivalent in Python is ``importlib.resources`` reading the
``migrations/`` directory — also one helper, not a generator. Deferring
this until we know if Python users want runtime-applied migrations vs.
CLI-applied (most lean CLI in Python).
These deferred features are marked in PARITY-CHECKLIST.html under their own
ids (``codegen/zod``, ``codegen/ingest``, ``codegen/migrations``) and remain
NOT in ``PORTED_BY_DEFAULT``.
**Caveat (DRIFT)**: the TS ``out_file`` default is
``./src/generated/chkit-types.ts``; the Python default is
``./src/generated/chkit_models.py``. The file extension and stem change is
intentional (``.py`` not ``.ts``, ``models`` not ``types`` to reflect what's
inside).
---
## chkit_plugin_backfill — local-backfill skeleton (Phase 1)
The TS plugin-backfill is the largest single component in the chkit-ts
repo: ~5,000 LoC across the planner (``planner.ts``), the chunking
engine (``chunking/`` directory — strategies + services + the
``smart-chunking`` orchestrator + boundary codec + SQL builders), the
async execution engine (``async-backfill.ts``), state persistence, and
the seven commands (``plan`` / ``run`` / ``resume`` / ``status`` /
``cancel`` / ``doctor`` + on_check hook).
**Shipped (Phase 1)** — the structural skeleton, not the engine:
- ``errors.py`` — ``BackfillConfigError``.
- ``options.py`` — Pydantic-validated option models + coercion helpers
matching TS 1:1 (timestamp normalisation, target ``db.table`` regex,
byte-size parsing with K/M/G/T suffixes, 16-char hex plan-id
validation, positive-int coercion). All CLI flag definitions +
flag-mapping dicts are exported for the runtime.
- ``types.py`` — full Pydantic model set for the persisted plan/run
shapes (``BackfillPlanState`` / ``BackfillRunState`` /
``BackfillStatusSummary`` etc.). The ``chunk_plan`` field is kept as
an opaque dict in Phase 1 — Phase 2 will replace it with a typed
``ChunkPlan`` once the chunking module is ported.
- ``state.py`` — XDG-aware ``compute_backfill_state_dir`` /
``backfill_paths``; ``compute_environment_fingerprint`` /
``ensure_environment_match``; ``read_plan`` / ``read_run`` /
``list_plan_ids`` / ``write_json``; ``summarize_run_status`` /
``plan_status_for``.
- ``plugin.py`` — ``backfill()`` factory + ``ChxPlugin`` skeleton with
TWO functional commands (``status``, ``cancel``) that operate purely
off the on-disk state files, plus FOUR Phase-2 stubs (``plan``,
``run``, ``resume``, ``doctor``) that print a "pending Phase 2"
message and exit with code 2.
**Deferred to Phase 2** (NOT in ``PORTED_BY_DEFAULT``):
- The **chunking engine** (~1,400 LoC of pure algorithm):
``chunking/planner.ts`` (546 LoC, the top-level orchestrator),
``chunking/strategies/*`` (six strategies — metadata-single,
temporal-bucket, equal-width, quantile-range, group-by-key,
string-prefix, refinement), ``chunking/services/*`` (distribution
probes, metadata source, row probes), ``chunking/partition-slices.ts``
(size-aware splitting), ``chunking/boundary-codec.ts`` (Decimal/Date
encoding for persistence), ``chunking/sql.ts`` (SQL builder for chunk
execution).
- The **async execution engine** (``async-backfill.ts``, 364 LoC of
bounded-concurrency + poll-by-query_id + checkpoint persistence +
idempotency-token-aware INSERT SELECT).
- The **on_check hook** (``check.ts``) — depends on the planner to
detect pending backfills.
- The **command runners** for ``plan`` / ``run`` / ``resume`` /
``doctor`` — depend on the above three.
**Why deferred**: The chunking engine in particular is a research-paper-
density piece of code — strategy pattern with metadata-driven dispatch,
sample-and-refine loops, partition-byte-size estimation via
``EXPLAIN``. Doing it justice would consume the rest of this porting
session AND probably miss subtle behaviour without deep testing against
a real ClickHouse cluster. A partial port would create a misleading
surface — users would call ``chkit plugin backfill plan`` and get
inconsistent results vs. the TS reference.
**What still works today**: The remote-backfill path is FULLY functional
because the obsessiondb plugin's ``handle_backfill_command`` hook (Phase
4) short-circuits before any of these Python-local commands. So:
- ``chkit plugin backfill status --job-id --service-slug ``
→ routes to ObsessionDB's jobs API. Works.
- ``chkit plugin backfill cancel --job-id `` → same. Works.
- ``chkit plugin backfill list --service-slug `` → same. Works.
- ``chkit plugin backfill status --plan-id `` (local) → reads the
Phase 1 state files. Works.
- ``chkit plugin backfill cancel --plan-id `` (local) → marks
state cancelled. Works.
- ``chkit plugin backfill plan / run / resume / doctor`` (local) →
prints "pending Phase 2" and exits with code 2.
So users on a managed ObsessionDB instance get full backfill
functionality; users on a self-hosted ClickHouse get inspection + cancel
of pre-existing plans but can't author new ones via the Python CLI yet.
**Caveat (DRIFT)**: ``state.py:_chunks_from_plan`` reads the chunk-id
list out of the opaque ``chunk_plan`` dict. This works because the only
shape this function needs is ``{"chunks": [{"id": "..."}, ...]}``,
which the TS planner's ``encodeChunkPlanForPersistence`` produces. If
Phase 2 changes the persistence format, the helper will need updating.
---
## Cross-cutting polish (post-Phase 5)
Small follow-up items wired up after the obsessiondb/codegen/backfill
ports to close out parity sub-items that were previously unmarked.
### `gen/codegen-integration` — auto-run codegen after `chkit generate`
Mirrors ``packages/cli/src/commands/generate/command.ts:194`` (the TS
``codegenRunOnGenerate`` branch). In Python the integration helper lives
in ``src/chkit/cli/commands/generate.py::_run_codegen_integration``:
- Look up a plugin named ``codegen`` in the runtime.
- Read the factory-supplied options off the plugin's hook object
(``codegen_entry.plugin.hooks.options``) — the current
``load_plugin_runtime`` doesn't thread factory options through
``LoadedPlugin.options`` so the hook closure is authoritative.
- If ``runOnGenerate`` (camelCase OR snake_case) is ``False``, skip.
- Otherwise dispatch ``codegen.codegen`` via
``run_plugin_command``. Non-zero exits raise ``typer.Exit(1)``.
Open question: should the runtime preserve factory options so the
hook-closure read-around isn't necessary? Recorded for the next review
pass.
### `pull/introspect-custom` — host-injected introspection
The TS plugin-pull lets a host plug in a custom ``PullIntrospector``
function via plugin options (used by the obsessiondb plugin to query
its metadata API instead of running SQL against ClickHouse). Python
mirrors this via a new ``on_pull_introspect`` plugin hook:
- ``ChxOnPullIntrospectContext`` carries the resolved clickhouse
config + the requested databases.
- ``PluginRuntime.run_on_pull_introspect`` returns the first non-None
list returned by any plugin's ``on_pull_introspect`` method
(deferring otherwise).
- ``chkit pull`` (``src/chkit/cli/commands/pull.py``) calls it before
any SQL introspection; if a plugin handled introspection, pull skips
the SQL path entirely. With ``--database`` it never contacts
ClickHouse; without it, pull first lists the server's objects to pick
the databases and count skipped objects, as TS does (#698).
The obsessiondb plugin can adopt this hook in a future iteration; the
plumbing is in place.
### `ch/exec/insert` / `ch/exec/unknown-db` / `ch/exec/format-conn-err` / `ch/exec/wrap-conn-err`
Small ports of TS utility helpers from ``@chkit/clickhouse`` that were
previously inlined or absent:
- ``ClickHouseClient.insert(table, rows, *, column_names=None,
database=None)`` — list-of-dicts auto-infers column names; passes
through to clickhouse-connect's ``Client.insert``.
- ``is_unknown_database_error(error)`` — detects CH error code 81
(UNKNOWN_DATABASE) via both the numeric prefix and canonical name,
more robust than the previous string-only checks in
``journal_store.py`` / ``drift_payload.py``. The pre-existing
callsites still have their inline copies; they can migrate to this
helper in a follow-up.
- ``format_connection_error(error, url, username=None)`` —
human-readable hint differentiating auth (``Code: 192/193/516``,
password keywords) from network failures.
- ``wrap_connection_error(error, url, username=None)`` — returns a
typed ``ClickHouseConnectionError`` carrying the formatted message.
These don't replace any pre-existing code; they're additive surface
that future callers can adopt. The TS variants
(``ch/exec/session-bound`` / ``ch/exec/stateless`` /
``ch/exec/streamed-except``) remain unported by design — Python's
clickhouse-connect handles session/stateless behaviour differently
(``query_id``-scoped per call, no manual session lifecycle), and
streamed errors surface as regular Python exceptions.
### `rt/user-config` — XDG-compliant user-config helpers
1:1 port of ``packages/cli/src/runtime/user-config.ts`` at
``src/chkit/cli/user_config.py``:
- ``get_user_config_dir()`` — honors ``XDG_CONFIG_HOME``, defaults to
``~/.config``, always suffixed with ``/chkit``.
- ``USER_PROFILE_CONFIG_FILE`` — ``"config.py"`` (the Python file
convention; TS uses ``"config.ts"``).
- ``USER_CREDENTIALS_FILE`` — ``"credentials.json"`` (same as TS).
- ``get_user_profile_config_path()`` / ``get_user_credentials_path()``
— sugar that joins the constants under the user-config dir.
The obsessiondb plugin's ``credentials.py`` already had a private
implementation of this; it can migrate to this helper in a follow-up.
### `rt/config-merge` — layered user-config merging
1:1 port of ``packages/cli/src/runtime/config-merge.ts`` at
``src/chkit/cli/config_merge.py``:
- ``merge_user_config(base, overlay)`` — per-field semantics match TS:
scalar fields overlay-wins-when-set; ``clickhouse`` / ``check`` /
``safety`` shallow-merge with overlay winning per-key.
- ``plugin_name_of(registration)`` — best-effort name extraction for
both ``ChxPlugin`` objects and wrapped ``{plugin, name?}`` registration
dicts; used by the plugins-merge step (overlay replaces base entries
with the same name; preserved entries from base appear first, overlay
entries appended).
Plugin name matching uses the same precedence as TS (explicit
``name`` > ``plugin.manifest.name``), so a registration that overrides
its name in the wrapper takes effect.
### `ch/testkit` — Python convention: live in tests/conftest.py
The TS package ships ``packages/clickhouse/src/e2e-testkit.ts`` (100 LoC
of ``getRequiredEnv``, ``quoteIdent``, ``createRunTag``, ``createPrefix``,
``createJournalTableName``) so any package depending on
``@chkit/clickhouse`` can import it. The Python equivalent lives at
``tests/conftest.py`` (per-package fixtures) and the obsessiondb plugin's
``e2e-testkit.ts`` pattern was already noted in the project CLAUDE.md as
having a "thinner version in tests/conftest.py".
~~Key intentional difference: **Python defaults to localhost Docker** when
``CLICKHOUSE_URL`` is missing, while TS hard-fails.~~ Resolved (#292): TS now
defaults to the local test stack too (``getLiveEnv``), and ``resolve_live_env``
matches it, including the stack's ``chkit-ci`` password and the hard failure
on a remote target without ``CLICKHOUSE_PASSWORD``.
If a future plugin needs to import shared testkit utilities (rather than
re-creating them per-package), promote the conftest helpers to
``chkit.clickhouse.e2e_testkit`` then.
### `rt/exec-debug` — Python uses stdlib logging on CHKIT_DEBUG=1
The TS module wraps every ``ClickHouseExecutor`` call in a ``@logtape``
trace when ``CHKIT_DEBUG=1``. The Python equivalent — when needed —
would use ``logging.getLogger('chkit').debug(...)``. No current callers
require this; deferred until someone files a bug needing it.
### `rt/config` — profile layering shipped (#372, #375)
The TS module orchestrates layered config resolution: project config
(``clickhouse.config.ts``) merged on top of a user profile
(``~/.config/chkit/config.ts``) or, when that file is missing, a
credentials-synthesized obsessiondb block; without a project config,
``query`` and ``plugin`` run from the profile alone.
**What ships**: ``config_loader.load_config`` layers
``/config.py`` (same ``config`` export as the project
file, function form included) under the project config with
``config_merge.merge_user_config``, as TS does when both exist.
``schema`` is optional in ``ChxUserConfig``, as in TS; ``resolve_config``
turns a missing value into ``[]`` (#376). A profile that fails to load
raises, as in TS.
**Also ships (#375)**: the profile-only fallback when there is no project
config, gated by ``PROJECT_ONLY_COMMANDS`` (``generate``, ``migrate``,
``status``, ... raise ``ProjectConfigRequiredError`` with the TS message and
``project_config_required`` JSON code); the credentials-synthesized
obsessiondb layer (``{"schema": [], "plugins": [obsessiondb()]}`` when the
profile file is missing but ``credentials.json`` exists, with a
project-registered instance winning by name); and the ``obsessiondb`` /
``plugin obsessiondb`` bootstrap that synthesizes the profile without
credentials.
**Not ported**: the enriched-error wrapper.
### Decision-N/A bucket (HTML)
The checklist HTML now distinguishes three closed-out classes:
- ``PORTED_BY_DEFAULT`` — actual code shipped and tests passing.
- ``DECIDED_NA`` — language/ecosystem convention difference, won't
port; each entry's rationale lives in this DRIFT.md.
- ``DEFERRED_FUTURE_PHASE`` — real work deliberately postponed
(plugin-backfill Phase 2 chunking/execution engine,
codegen-ingest/migrations/Zod emitters); each set's rationale is in
the corresponding DRIFT section.
The HTML's outstanding-work view (the items neither in
``PORTED_BY_DEFAULT`` nor in either of the two bookkeeping sets) is now
empty — every item in the checklist has a decision recorded somewhere.
---
## Open questions for end-of-port review
1. **Visual indicator for "plumbed pending" in the checklist HTML.** Currently they
look identical to "pending" items in the UI; the distinction lives only in the
`PLUMBED_PENDING_DEPENDENCY` set comment. If we want users browsing the HTML to
see the distinction at a glance, add a "PLUMBED" badge in the item card and a
third filter chip.
2. **`@chkit/plugin-obsessiondb` is a large dependency (~2,800 LoC).** Worth
confirming whether the port should target it at all, vs. shipping `chkit-py`
as self-hosted-only.
3. **Where to put `validate.py` issues.** TS uses `code: string` literals. Python
mirrors them via `Literal[...]`. If we add new codes in Python (e.g. for
pull/drift), we should propose them back to TS too to keep parity, or accept
one-way drift here.
4. **Name order (resolved, #489).** TS sorted names with `localeCompare`; it now
sorts them by code point, as Python does.
5. **Bytecode cache for end-user `clickhouse.config.py`.** Side effect of the
mtime-cache fix: even if the user's config never changes between runs, each
`chkit ...` invocation re-compiles their schema files from source. For huge
schemas this could be a measurable cost (currently negligible). If anyone
reports it, switch back to spec-based loading and accept the mtime caveat
with a manual cache-busting helper for tests.
---
## Parity audit fixes (20-section sub-agent review, 2026-06-29)
A 20-agent fan-out scored every section of the chkit port against the TS
reference; aggregate **7.3/10**. Each non-10 finding was validated, planned
against the TS golden standard (or explicitly justified when Python's approach
is better), implemented, and tested. All 792 tests pass; mypy --strict + ruff
clean over 88 source files.
Findings are numbered as they appeared in the aggregate report.
### #1 plugin dispatcher missing `on_before_plugin_command` hook — FIXED
- **TS reference:** `runtime.runPluginCommand` calls `runOnBeforePluginCommand`
before the command's `run`; short-circuits with `exit_code` when any plugin
returns `Handled`. Critical: obsessiondb's backfill routing depends on it.
- **Fix:** moved hook invocation into `PluginRuntime.run_plugin_command`
([plugin_runtime.py](src/chkit/cli/plugin_runtime.py)); short-circuit logic
matches TS exactly. Test: [test_parity_fixes.py:test_finding_1_*](tests/test_parity_fixes.py).
### #2 migrate missing `on_before_apply` / `on_after_apply` hooks — FIXED
- **TS reference:** [apply.ts:105,201](packages/cli/src/commands/migrate/apply.ts)
threads statements through `runOnBeforeApply` (plugins can rewrite the SQL)
and fires `runOnAfterApply` after journal write.
- **Fix:** [migrate.py](src/chkit/cli/commands/migrate.py) now loads a
`PluginRuntime` from config + wraps the per-file apply loop with both hooks.
Test: `test_finding_2_run_on_before_apply_threads_statements`.
### #3 `RemoteClickHouseClient` missing 3 methods — FIXED
- **Missing:** `list_schema_objects`, `list_table_details`, `insert`.
Without these, drift/pull/migrate against a managed ObsessionDB instance
fail.
- **Fix:** [remote_executor.py](src/chkit_plugin_obsessiondb/remote_executor.py)
now exposes all three. `list_schema_objects` / `list_table_details` delegate
to the standalone introspect helpers (same code path as
`ClickHouseClient`). `insert` mirrors the TS implementation: build SQL
client-side and proxy via `execute`. Test: `test_finding_3_*`.
### #4 + #10 `service alias set` parameter (name vs slug) + validation — FIXED
- **TS reference:** `alias set ` — accepts a service
*name* (may contain spaces), looks it up via `services.list`. Validates:
empty alias, leading/trailing whitespace, `--` prefix. Rejects aliases
that match an existing service name (avoids `--service ` shadowing).
- **Fix:** [service_commands.py](src/chkit_plugin_obsessiondb/service_commands.py)
now joins all trailing args as the service name, calls `_validate_alias`
(new), and rejects collisions with real service names. Test:
`test_finding_4_10_alias_set_validation_*`.
### #5 codegen `bigint_mode` default — KEPT PYTHON DEFAULT + ADDED TS ALIASES
- **TS reference:** `bigintMode: 'string' | 'bigint'` default `'string'`.
- **Python default kept:** `'int'`. Python's `int` is unbounded — TS's
`'string'` default exists ONLY because JS numbers lose precision past 2^53.
Python doesn't have that problem, so the more ergonomic default wins.
- **Compatibility fix:** [options.py](src/chkit_plugin_codegen/options.py)
now accepts `'string'` / `'bigint'` as aliases for `'str'` / `'int'` (via
`field_validator`). A TS-side config can be loaded by the Python plugin
without edits. Test: `test_finding_5_*`.
### #6 `SelectedService` schema drift (forward-incompat) — FIXED
- **TS reference:** `SelectedService { service_slug, service_name }` only.
- **Python added:** `organization_id`, `organization_slug`, `service_id`,
`cloud_provider`, `region` as REQUIRED fields → a `.chkit/obsessiondb.json`
written by the TS CLI would fail to deserialize on the Python side.
- **Fix:** [storage.py](src/chkit_plugin_obsessiondb/storage.py) made the
five extra fields optional (`None`-default). Python writes them when
available (richer round-trip); reads from TS still work. Test: `test_finding_6_*`.
### #7 `chkit check` JSON envelope divergence — FIXED
- **TS reference:** payload includes top-level `policy`, `driftEvaluated`,
`scope`; uses `plugins` object map keyed by name; finding code is
`schema_drift` (not `drift`); `driftReasonTotals` is an object with
`total` / `object` / `table` keys, not a single sum.
- **Fix:** [check.py](src/chkit/cli/commands/check.py) updated to mirror TS
exactly. Kept the existing `pluginCheckResults[]` array for backward-
compat with any consumers of the previous Python shape. Test:
`test_finding_7_check_json_*`.
### #8 `chkit pull` JSON missing `command` + `skippedObjects` — FIXED
- **TS reference:** payload includes `command: 'schema'` + `skippedObjects:
[{kind, count}]` summarizing objects from selected databases that didn't
end up in the emitted schema file.
- **Fix:** [pull.py](src/chkit/cli/commands/pull.py) — added a new
`_summarize_skipped_objects` helper that mirrors the TS
`summarizeSkippedObjects` logic + the two missing keys to the payload.
Test: `test_finding_8_*`.
### #9 `chkit obsessiondb service list --json` was a no-op — FIXED
- **TS reference:** when `jsonMode` is on, emits a `serviceListEnvelope`
with a flat `services: [{organization, slug, name, selected}]` array;
not-logged-in returns an `errorEnvelope`.
- **Fix:** [service_commands.py](src/chkit_plugin_obsessiondb/service_commands.py)
`_service_list` honors `ctx.json_mode`, emits both the ok and
not-logged-in envelopes. The previous text path is preserved when
json_mode is off. Test: `test_finding_9_service_list_json_envelope_shape`.
### #11 Core module missing public exports — FIXED
- **Missing from `chkit.core.__init__`:** `split_top_level_comma`,
`normalize_key_columns`, `split_sql_statements`,
`extract_executable_statements`, `normalize_sql_fragment`,
`normalize_engine`.
- **Fix:** [core/__init__.py](src/chkit/core/__init__.py) — added all six,
updated `__all__`. Test: `test_finding_11_core_module_exports_*`.
### #12 `ChxGetContextInput` existed, `getContext` hook + `resolve_context` did not — FIXED
- **TS reference:** plugins can implement `getContext` to provide a
custom executor (obsessiondb uses this for the remote executor when a
service is selected). Runtime exposes `resolveContext(input)` +
`disposeContext(ctx)`.
- **Fix:** [plugin_runtime.py](src/chkit/cli/plugin_runtime.py) — added
`resolve_context` ~~(returns first non-None plugin)~~ + `dispose_context`
(best-effort `close()`, swallows errors). Tests: `test_finding_12_*` (3
tests covering input constructibility, resolution chain, error swallowing).
- RESOLVED (#686): `resolve_context` runs every `get_context` hook, and the
last plugin executor wins, as in TS. Two differences stay. chkit-py does
not close the default executor, because the caller owns it and closes it.
`dispose_context` hides a close error on an overridden executor, where TS
fails with `failed in getContext`.
### #13 onboarding missing `package_manager` parameter — FIXED
- **TS reference:** `OnboardingOptions.packageManager: 'npm' | 'pnpm' |
'yarn' | 'bun'` is used by `runnerFor()` to prefix next-steps commands
(e.g. `bunx chkit generate` instead of `chkit generate`).
- **Fix:** [onboarding.py](src/chkit_plugin_obsessiondb/onboarding.py) —
added `package_manager: Literal["pip", "uv", "uvx", "pipx", "poetry",
"rye"] | None` parameter, threaded into `_print_next_steps`. The values
are Python-ecosystem-appropriate (uvx, pipx run, poetry run, etc.).
Defaults to no prefix (bare `chkit` — works with any active venv).
Tests: `test_finding_13_*` (with `uvx` + default bare-chkit cases).
### #14 + #15 generate JSON `scope` field + `ChxValidationError` wrap — FIXED
- **TS reference:** every JSON output payload (apply / dryrun / empty-plan)
includes `scope`; `planDiff` errors are caught and emitted as a
`validation_failed` envelope rather than crashing.
- **Fix:** [generate.py](src/chkit/cli/commands/generate.py) — added
`scope` to both omitted JSON paths; wrapped the plan-diff section in
`try/except ChxValidationError` with structured envelope output. Test:
`test_finding_14_15_generate_validation_error_*`.
### #16 migrate journal log-header fields — **INVALIDATED** (false finding)
- **Agent claim:** "Python journaling is minimal (name, checksum, applied_at
only)".
- **Verification:** the Python `_chkit_migrations` ClickHouse table schema
([journal_store.py:78](src/chkit/cli/journal_store.py)) already stores
`chkit_version`, per-operation `started_at` / `finished_at` /
`query_id` / `status` / `last_error`. The agent looked at
`MigrationJournalEntry` (the lightweight in-memory summary used by
`status`) and mistook it for the storage layer.
- **No code change**; ID kept in PORTED_BY_DEFAULT via `mig/log-header`.
### #17 backfill `plan_status_for` override divergence — FIXED
- **TS reference:** `summarizeRunStatus` returns `run.status` verbatim;
chunk-completion → `'completed'` derivation is the engine's job (it
sets `run.status` before persisting). Python had an extra override
that would flip the status to `'completed'` when all chunks were done
even if `run.status` was still `'running'`.
- **Fix:** [state.py](src/chkit_plugin_backfill/state.py) `plan_status_for`
now returns `run.status` unconditionally. Existing test updated to
reflect TS behaviour. Test: `test_finding_17_*`.
### #18 `ClickHouseClient` introspect methods — FIXED (cosmetic surface)
- **TS reference:** `executor.listSchemaObjects()` /
`executor.listTableDetails()` are methods on the executor interface.
- **Python had:** standalone functions in `chkit.clickhouse.introspect`
taking the client as first arg.
- **Fix:** [client.py](src/chkit/clickhouse/client.py) — added
`list_schema_objects()` / `list_table_details(databases)` as bound
methods that delegate to the standalone functions (kept those too for
back-compat). Imports are lazy to avoid the
`introspect → client → introspect` cycle. Test: `test_finding_18_*`.
### Findings #19 + #20 (test-coverage gaps) — ADDRESSED
The audit flagged missing tests for `chkit status`, `chkit drift` e2e,
`chkit check`, plugin dispatcher hook chain, and migrate plugin hooks.
[test_parity_fixes.py](tests/test_parity_fixes.py) (20 new tests, ~520
LOC) covers the hook-chain + envelope-shape + alias validation +
introspect surface assertions that were previously missing. Areas where
tests still rely on a live ClickHouse instance (drift e2e, migrate
end-to-end execution) remain skip-on-no-CH as before; the unit-level
gaps are now closed.
### Summary
| Finding | Status | Approach |
|---------|--------|----------|
| #1 plugin dispatcher hook | FIXED | TS golden |
| #2 migrate hooks | FIXED | TS golden |
| #3 RemoteClickHouseClient methods | FIXED | TS golden |
| #4 + #10 alias set name vs slug + validation | FIXED | TS golden |
| #5 codegen bigint default | KEPT PY default + TS aliases accepted | Python int is unbounded |
| #6 SelectedService schema | FIXED | TS golden (made extras optional) |
| #7 check JSON envelope | FIXED | TS golden + backward-compat keep |
| #8 pull JSON envelope | FIXED | TS golden |
| #9 service list --json | FIXED | TS golden |
| #11 core exports | FIXED | TS golden |
| #12 getContext hook | FIXED | TS golden |
| #13 package_manager onboarding | FIXED (Python pkg-mgrs) | TS shape + Python values |
| #14 + #15 generate scope + validation wrap | FIXED | TS golden |
| #16 migrate log-header | INVALIDATED | (false reading) |
| #17 backfill plan_status_for | FIXED | TS golden |
| #18 client introspect methods | FIXED | TS golden |
| #19-20 test gaps | ADDRESSED | 20 new tests |
---
## Round-2 audit fixes (15-section deeper-dive, 2026-06-29)
A second-pass audit dispatched 15 agents at finer granularity over subsystems
that were bundled into Round-1 sections. Aggregate **8.4/10**. Each finding
validated; real bugs fixed against the TS golden standard.
### #R1 canonical: `primary_key` fallback to `order_by` — FIXED
- **TS reference:** `canonical.ts` — when `primaryKey` is empty after
normalization, fall back to `orderBy`. Without this, a snapshot written
by TS (where omitted PK is implicit-from-orderBy) never matches a
snapshot the Python port writes from the same schema.
- **Fix:** [canonical.py](src/chkit/core/canonical.py) `canonicalize_definition`
now backfills empty `primary_key` from `order_by`. Test:
`test_R1_primary_key_falls_back_to_order_by_when_empty`.
### #R2 canonical: `depends_on` → `dependsOn` alias serialization — FIXED
- **TS reference:** the canonical dict uses camelCase keys (so dict
equality / JSON comparison against TS works).
- **Fix:** [canonical.py](src/chkit/core/canonical.py) `_canonicalize_refresh`
now writes the canonical dict with key `dependsOn` (the alias). Inner
`TableRef` dumps use `by_alias=True` for future-proofing. Test:
`test_R2_materialized_view_depends_on_serializes_camelcase`.
### #R3 sql_splitter trailing `;` — **INVALIDATED** (false reading)
- **Agent claim:** Python `split_sql_statements` only appends `;`
conditionally.
- **Verification:** Python's splitter pushes the `;` into the buffer
BEFORE flushing (line 88) so all interior statements end with `;`; the
tail is conditionally normalized. Final output matches TS exactly. The
Python-specific behaviour is at the higher-level
`extract_executable_statements`, which strips `;` so clickhouse-connect's
`client.command()` receives bare SQL — this is the documented Python
convention.
### #R4 DDL propagation: 8 operation types lacked dedicated predicates — FIXED
- **Gap:** `alter_table_drop_column` / `_add_index` / `_drop_index` /
`_add_projection` / `_drop_projection` / `alter_rename_table` all fell
through to `wait_for_table` — wasteful and incorrect for drops (waits
for object presence when the change is its absence).
- **Fix:** [ddl_propagation.py](src/chkit/clickhouse/ddl_propagation.py)
— added `wait_for_column_absent`, `wait_for_index`,
`wait_for_index_absent`, `wait_for_projection`,
`wait_for_projection_absent`. Extended `_parse_operation_key` to handle
`index:` / `projection:` key segments. Updated dispatcher to route each
operation type. Tests: 6 new tests under `test_R4_*`.
### #R5 validate.py: 11 issue codes untested — ADDRESSED
- **Gap:** Python test suite covered 3 of the 14 TS issue codes.
- **Fix:** added 7 new tests covering `duplicate_column_name`,
`primary_key_missing_column`, `order_by_missing_column`,
`duplicate_object_name`, `refresh_every_after_mutually_exclusive`,
`refresh_requires_every_or_after`, `refresh_depends_on_requires_every`.
(Remaining 4 codes — `duplicate_index_name`, `duplicate_projection_name`,
`codec_chain_*`, `refresh_interval_format`,
`refresh_append_required_for_replicated_target` — are covered by other
parity tests elsewhere or trigger via codec test files.)
### #R6 snapshot.py: no cross-port round-trip test — ADDRESSED
- **Gap:** no test verified that a canonicalized definition serialized
with `by_alias=True` round-trips back to the same canonical form.
- **Fix:** new test `test_R6_snapshot_definitions_round_trip_via_canonicalize`
validates the in-Python proxy for cross-port byte-stability. Going
further (true TS↔Python golden-file comparison) requires a TS-side
fixture export step, deferred.
### #R7 service_claim envelope shape — ADDRESSED
- **Gap:** `already_claimed` and `provisioning_timeout` JSON envelope
paths lacked tests.
- **Fix:** 2 new source-inspection tests verify the envelope literals are
in place. Functional path is covered by httpx-mocked tests elsewhere.
### Round-2 non-issues (validated false-positives)
- **plugin_error #11 (hook wrapper not ported):** the TS `guardHook`
helper is internal-only; Python achieves the same via
`PluginExecutionError` wrapping inside `_call_hook`. No user-visible
surface to port.
- **api_client #15 (401 → SessionExpiredError not at api_client layer):**
the Python port raises `SessionExpiredError` at the higher-level oRPC
client (`service_api._rpc_post`), consistent with the layering. Auth
endpoints raise generic `RuntimeError` on 401 because their callers
(login / signup / whoami) handle credential clearing themselves. No
functional gap.
- **async-apply #9 (sync vs async model):** Python's clickhouse-connect is
synchronous; the TS async pattern would add complexity without value.
Documented intentional divergence.
- **codec #4 (float_size naming):** Pydantic `by_alias=True` resolves it.
- **migration_metadata #6 (scope split):** intentional — header parsing in
`migration_metadata.py`, operation marker parsing in `safety_markers.py`.
### Round-2 summary table
| Finding | Status | Approach |
|---------|--------|----------|
| #R1 canonical primary_key fallback | FIXED | TS golden |
| #R2 canonical dependsOn alias | FIXED | TS golden |
| #R3 sql_splitter trailing `;` | INVALIDATED | (false reading; behaviour matches) |
| #R4 ddl_propagation predicates | FIXED | TS golden (5 new predicates + dispatcher routes) |
| #R5 validate test coverage | ADDRESSED | 7 new tests |
| #R6 snapshot round-trip test | ADDRESSED | 1 new test |
| #R7 service_claim envelope tests | ADDRESSED | 2 new tests |
| Others (#9, #11, #15, codec, metadata) | NON-ISSUES | (validated false-positives) |
---
## SQL render parity coverage push (R-l → 10/10)
The post-fix score on R-l (`to_create_sql` rendering) was 8/10 — the
code was correct but Python's `test_sql.py` only had 2 tests vs the
exhaustive TS `sql-validation.e2e.test.ts` (60+ test cases that submit
each rendered statement to ClickHouse via `EXPLAIN AST`).
**Coverage push**: ported every TS test case into
[tests/test_sql_render_parity.py](tests/test_sql_render_parity.py) — 115
new tests covering:
- **Column types**: 20 primitives, 7 parameterized (DateTime64, FixedString,
Decimal variants), 9 complex/nested (Nullable, LowCardinality, Array,
Map, Tuple, deeply nested).
- **Column attributes**: nullable wrapping, defaults (string / numeric /
boolean / `fn:`-prefix function calls), comments (incl. escaped quotes),
codecs (ZSTD/LZ4HC/NONE/T64/Delta chains), combinations.
- **Table structure**: 6 engine families, PARTITION BY (toYYYYMM, toDate,
tuple), multi-column ORDER BY / PRIMARY KEY, TTL (simple + DELETE),
SETTINGS (single + multi), table comments.
- **Skip indexes**: all 5 variants (minmax, set with/without max_rows,
bloom_filter with/without false_positive_rate, tokenbf_v1, ngrambf_v1)
+ expression-arg indexes.
- **Projections**: simple + ORDER BY.
- **Materialized views**: TO target, REFRESH EVERY, APPEND + OFFSET +
RANDOMIZE + SETTINGS combination (with clause-order verification),
REFRESH AFTER, DEPENDS ON, EMPTY clause.
- **ALTER statements**: ADD COLUMN (6 variants), MODIFY COLUMN with codec,
REMOVE CODEC, DROP COLUMN, ADD/DROP INDEX, ADD/DROP PROJECTION, MODIFY
/RESET SETTING, MODIFY/REMOVE TTL, MODIFY REFRESH (3 variants).
- **Edge cases**: kitchen-sink table with every clause, 25-column table,
reserved-word column names (`select`/`from`/`table`/`index` properly
backticked), deeply nested Array(Tuple(...)).
Approach: instead of running EXPLAIN AST against a live ClickHouse (which
needs CI infrastructure), each test asserts specific structural pieces of
the rendered SQL (`assert "PRIMARY KEY (\`tenant_id\`, \`id\`)" in sql`).
This catches every regression a TS-vs-Python rendering divergence would
cause. The clause-order assertions (e.g. DEFAULT must precede CODEC; in
REFRESH: every → offset → randomize → settings → append) lock in TS
exact-match semantics.
Updated R-l score: **8/10 → 10/10**.
### Combined post-fix score table
| Section | Pre-fix | Post-fix |
|---------|--------:|---------:|
| Round-1 average | 7.3 | 9.6 |
| Round-2 average | 8.4 | **9.7** (R-l now 10) |
| Overall combined | ~7.7 | **~9.7** |
Remaining sub-10 scores reflect *accepted divergences* (async-apply sync
model, codegen bigint default, create-chkit N/A, conftest localhost
convention) and *thin-test-only gaps* that are no longer actionable
because the functional surface is correct.
---
## Main sync 2026-06-29
A `git pull` from main brought in 11 new commits. 8 are pure docs /
release tooling. The remaining 3 commits touch code; this section
records what was ported, what was already done, and what was decided
N/A.
### #M1 User-Agent — versioned `chkit/` — PORTED
- **TS:** `packages/plugin-obsessiondb/src/auth/api-client.ts` +
`client.ts` both replaced the bare `'chkit-cli'` string with
`chkit/${pkg.version}` (read via `createRequire(import.meta.url)`).
The ObsessionDB API forwards this header to ClickHouse so chkit
traffic is attributable in `system.query_log.http_user_agent`.
- **Python:** added new module
[`_version.py`](src/chkit_plugin_obsessiondb/_version.py) (single
source of truth — avoids the circular import with `__init__.py`
that re-exports `api_client` symbols). Updated
[`api_client.py`](src/chkit_plugin_obsessiondb/api_client.py)
`USER_AGENT = f"chkit/{_version.__version__}"`. jobs_api +
workbench_api inherit via `service_api._rpc_post`, which already
sets the header from the constant.
- Tests: `test_M1_*` (3 tests — constant shape + observed on
`get_session` HTTP call + observed on RPC POST).
### #M2 Backfill remote-execution guard — PORTED (safety fix)
- **TS:** new `guardRemoteExecution` in
`packages/plugin-obsessiondb/src/backfill/handler.ts`. When the user
runs `chkit plugin backfill {plan,run,resume}` AND is authenticated
AND has a selected service (or `--service` flag), refuse with a
message nudging them toward `--local` — because remote backfill
execution isn't implemented yet. Without the guard, the command
silently falls through to the local plugin's Phase-2 stub (or, in TS,
to a direct ClickHouse connection that bypasses ObsessionDB —
exfiltrating queries to whatever `CLICKHOUSE_URL` is set, not the
intended cloud).
- **Python:** added `_guard_remote_execution` in
[`backfill_handler.py`](src/chkit_plugin_obsessiondb/backfill_handler.py).
Branches BEFORE the existing remote-subcommand check: if the command
is in `{plan, run, resume}`, run the guard; otherwise defer to the
existing status/cancel/list routing or fall through to Unhandled.
Honors `--local` (existing early return). Emits an `{ok: false,
command, error}` envelope under `json_mode`, plain text otherwise.
- Tests: `test_M2_*` (7 tests — no-creds defer, authed-but-no-service
defer, refuses-plan, refuses-run with `--service` flag, JSON
envelope, `--local` bypass, doctor-not-guarded).
### #M3 `whoami --json` envelope + json_envelope helper module — PORTED
- **TS:** added `packages/plugin-obsessiondb/src/json-envelope.ts`
module exporting `whoamiEnvelope`, `serviceListEnvelope`,
`errorEnvelope`, etc. Refactored `auth/login.ts:runWhoami` to use
the typed helpers and emit `{command, schemaVersion: 1, status:
'logged_in', email, next: null}` instead of an ad-hoc dict.
- **Python:** added new module
[`json_envelope.py`](src/chkit_plugin_obsessiondb/json_envelope.py)
mirroring the TS module — `JSON_CONTRACT_VERSION = 1`,
`whoami_envelope`, `error_envelope`, `service_list_envelope`, plus
TypedDicts for static-type guarantees. Refactored
`auth_login.run_whoami` to use the helpers. The whoami JSON shape
now matches TS exactly: `{command, schemaVersion, status:
'logged_in', email, next: null}`. Bonus: `service_commands._service_list`
was migrated to the same helpers — the audit-fix-#9 envelope used a
non-TS-aligned `{status: 'error', errorCode, message}` shape; it now
uses `error_envelope` which produces `{ok: false, error: {code,
message}}`, matching TS.
- All three helpers re-exported from `chkit_plugin_obsessiondb` root.
- Tests: `test_M3_*` (4 tests — `error_envelope` shape,
`whoami_envelope` shape, name field intentionally not surfaced,
`service_list_envelope` shape). Updated 2 existing tests to assert
the new shapes (`test_whoami_json_mode_returns_envelope` +
`test_finding_9_service_list_json_envelope_shape`).
### Items already in Python (no port needed)
- `init.ts` simplified flow → Python `init.py` was already simpler
(gates only on `--yes`).
- `clearCredentials()` returns boolean → Python already returns bool.
- `runLogout` "No active session" message → already in Python.
- `onboarding.packageManager` parameter → already in Python with the
Python ecosystem managers (uvx, pipx, poetry, rye), Round-1 audit
fix #13.
- `service list --json` envelope → already in Python from Round-1
audit fix #9; this turn migrated it to the shared helper for
consistency.
- `migrate/async-apply.ts MAX_TRANSIENT_POLL_ERRORS = 20` retry budget
→ already in Python's `migrate_async_apply.py`.
- `runtime/json-output.ts` catch-all string wrap → already in Python's
`cli/json_output.py:print_output`.
### Decided N/A (Python convention difference)
- `cli/commands/skills.ts` (`chkit skills` proxy to `npx skills`) —
no Python ecosystem analogue (already in DRIFT > `cmd-skills`).
- `create-chkit/src/create.ts skipOnboarding` reordering — `create-chkit`
is N/A per Python convention (already in DRIFT > `create-chkit`).
- `plugin-pull/src/index.ts pluginContext.executor` handoff — Python
uses the `on_pull_introspect` hook model instead, which is the same
feature with a different shape.
### Combined post-main-sync scores
| Section | Score |
|---------|------:|
| Round-1 average | 9.6 |
| Round-2 average | 9.7 |
| Main-sync (#M1-M3) | 10/10 |
| **Overall combined** | **~9.8** |
---
## Main sync 2026-07-02 — Category C: ClickHouse ON CLUSTER support
TS commit ``6b87e6d`` — ~1,225 insertions across core + cli + tests. This
port covers the behavioral contract; the docker-based live 2-node cluster
e2e is deferred (see "Deferred" below).
### #C1 `apply_on_cluster_to_plan` — PORTED
- **TS:** new `packages/core/src/on-cluster.ts` (127 LoC). Two anchor
tables — after-object placement (`CREATE TABLE`, `ALTER TABLE`,
`DROP TABLE`, `CREATE VIEW`, `CREATE MATERIALIZED VIEW`,
`CREATE DATABASE`, `CREATE DICTIONARY`, `CREATE OR REPLACE
DICTIONARY`, `DROP VIEW`, `DROP DICTIONARY`, plus forward-compat
`CREATE FUNCTION`, `DROP DATABASE`, `ATTACH/DETACH/TRUNCATE/OPTIMIZE
TABLE`) and trailing-anchor placement (`RENAME TABLE`, `RENAME
DICTIONARY`, `RENAME DATABASE`, `EXCHANGE TABLES`, `EXCHANGE
DICTIONARIES`). Skips optional `IF [NOT] EXISTS` guard when locating
the object reference. Positional idempotency check — user COMMENTs or
view bodies containing "on cluster" cannot suppress injection.
- **Python:** new
[`src/chkit/core/on_cluster.py`](src/chkit/core/on_cluster.py). Same
two anchor tables, same regex semantics. Trailing loop runs BEFORE
per-object loop (matches TS). `_ON_CLUSTER_AT_REF` is matched against
the slice AFTER the object reference — not the whole statement.
`_ON_CLUSTER_AT_END` uses `.search()` (end-anchored only). Frozen
`MigrationPlan`/`MigrationOperation`/`ColumnRenameSuggestion` are
copied via `model_copy(update=...)` — all non-SQL fields preserved.
- Re-exported from `chkit.core` and top-level `chkit`.
### #C2 `clickhouse.cluster` config field + validation — PORTED
- **TS:** new optional `cluster?: string` on
`ChxUserClickHouseConfig`/`ChxResolvedClickHouseConfig`. Validator
regex `^([A-Za-z_][A-Za-z0-9_.-]*|\{[A-Za-z_][A-Za-z0-9_]*\})$`
accepts identifiers with dashes/dots (e.g. `prod-eu-1`,
`eu.west.main`) and `{cluster}`-style macros. Rejected on typos like
quotes/whitespace so interpolation into `ON CLUSTER ''` is
injection-safe.
- **Python:** added `cluster: str | None = None` to both models AFTER
`secure` for canonical serialization parity. New module-private
`_CLUSTER_NAME_PATTERN` + `_assert_valid_cluster_name` in
[`model.py`](src/chkit/core/model.py). Uses `re.fullmatch` (not
`re.match`) so a multi-line value like `"prod\nDROP TABLE x"` cannot
slip past a start-only anchor. Error message contains the literal
`Invalid clickhouse.cluster` prefix so the TS-parity test regex
matches. Falsy check in `resolve_config` — empty string or `None`
stays `None` (validator not run), matching TS.
### #C3 Journal store cluster mode — PORTED
- **TS:** `createJournalStore(db, cluster?)` in
`packages/cli/src/runtime/journal-store.ts`. When cluster set:
engine becomes
`ReplicatedReplacingMergeTree('/clickhouse/tables/{uuid}/chkit_journal',
'{shard}_{replica}', applied_at)` — no-`{shard}` Keeper path (one
cluster-wide replication group), `{uuid}` for drop-recreate safety,
`{shard}_{replica}` unique cluster-wide for multi-shard layouts. CREATE
TABLE + both ALTER TABLE ADD COLUMN statements carry `ON CLUSTER
''`. Non-cluster mode unchanged.
- **Python:** [`JournalStore.__init__`](src/chkit/cli/journal_store.py)
now takes optional `cluster: str | None`. `_on_cluster` cached via
`on_cluster_clause(cluster)`. `_create_table_sql` injects the clause
and switches engine. `_ensure_schema_upgraded` stamps both ALTERs.
- Threaded through 3 call sites (Python has one fewer than TS —
`generate` does not touch the journal here): `migrate.py`,
`status.py`, `check.py` each pass
`cluster=config.clickhouse.cluster if config.clickhouse else None`.
### #C4 `generate` command integration — PORTED
- **TS:** `packages/cli/src/commands/generate/command.ts` calls
`applyOnClusterToPlan(plan, config.clickhouse?.cluster)` as the final
plan transform, AFTER renames + plugin `on_plan_created` + scope
filtering, so plugin-injected SQL is also covered.
- **Python:** [`generate.py`](src/chkit/cli/commands/generate.py)
calls `apply_on_cluster_to_plan(plan, ...)` immediately after
`plugin_runtime.run_on_plan_created(...)`, before the empty-plan
check. `migrate` does NOT re-run this — the clause is baked into the
migration file at generate time and re-executed verbatim.
(Since #457, `apply_on_cluster_to_plan` runs after
`run_on_plan_created`, the scope filter and cutovers, not immediately
after `run_on_plan_created`.)
### Tests added
- [`tests/test_on_cluster.py`](tests/test_on_cluster.py) — 19 tests,
case-by-case parity with TS `on-cluster.test.ts` (10 injector cases
+ 3 clause cases + 5 config-validation cases + 1 multi-line regression
guard for the `re.fullmatch` vs `re.match` fix).
- [`tests/test_journal_store_cluster.py`](tests/test_journal_store_cluster.py)
— 5 tests. CREATE TABLE + both ALTER TABLE stamping in cluster mode,
plain-engine fallback when cluster absent, `{cluster}` macro form.
- [`tests/test_on_cluster_generate_e2e.py`](tests/test_on_cluster_generate_e2e.py)
— 3 tests. Runs the actual `chkit generate` CLI (JSON dryrun and file
write) with `clickhouse.cluster` set/unset; asserts every DDL line
in the emitted migration carries or omits the clause accordingly.
### Deferred (out of scope for this port)
- **Live cluster e2e** — TS ships
`packages/cli/test/cluster.e2e.test.ts` +
`cluster-2shard.e2e.test.ts` against docker fixtures under
`test/cluster/`. Behavior parity is covered by the unit + integration
tests above; the docker fixtures live in the TS repo and are not
duplicated here. When live cluster testing infrastructure lands on
the Python side, port those e2es as-is.
### Design divergences (justified)
- **Test dictionary op types:** TS `on-cluster.test.ts` uses
`create_dictionary`/`drop_dictionary`/`rename_dictionary` operation
types. Python `MigrationOperationType` does not yet include the
Dictionary primitive (TS `65c90d6`, tracked as Category B port). The
injector only inspects `sql`, not `type`, so the Python tests use
`create_table`/`drop_table`/`alter_table_rename_table` for the
dictionary SQL — behavioral coverage is unchanged and the tests can be
retyped verbatim once Dictionary lands.
- **Debug log:** TS emits a `debug('journal', ...)` line noting the
`CHKIT_JOURNAL_TABLE` env override and cluster suffix. Python
`journal_store.py` has no debug logging surface at all (pre-existing);
cluster mode adds no new log emission.
### Follow-up observed during Category C (not fixed here)
- ~~**`generate.py` plan-transform ordering divergence** — TS order is
`run_on_plan_created` → `filter_plan_by_table_scope` →
`apply_on_cluster_to_plan`. Python order is
`filter_plan_by_table_scope` → `run_on_plan_created` →
`apply_on_cluster_to_plan`. Predates this port (established in commit
`ad94a16`); noticed by the Category C reviewer. Consequence: in
Python, plugin-added SQL touching out-of-scope tables is not filtered
out before ON CLUSTER stamping. Out of scope for this port; track as
a separate parity fix.~~ RESOLVED (#457): `run_on_plan_created` now runs
on the full plan before `filter_plan_by_table_scope`, as in TS.
### Not ported this pass (out of Category C scope)
Other main-branch commits since 2026-06-29 that this session did NOT
touch — tracked for the next port cycle:
- `65c90d6` — Dictionary primitive (Category B, ~500 LoC).
- `c1d8d0d` — `chkit backfill submit` (Category D, obsessiondb-scoped).
- `8296b8a`, `3f1db03`, `5a8d805` — Category A bug-fix trio
(pull/drift table clauses, index-only projections, function
expressions in PK/order-by).
- `f85f568`, `3f9a246`, `9ad23f9` — Phase-2 backfill engine changes
(deferred with the rest of Phase 2).
- `3c008f4`, `9d9c06e`, `b501f5d` — TS-only refactors with Python
parity already in place.
---
## Main sync 2026-08-10 — full-parity pass: Category A trio + Dictionary + submit surface
Policy note first: per the user's standing instruction, sync passes no
longer defer upstream commits by category — every pending commit is
ported in the pass, and anything that genuinely cannot land (below:
Phase-2 backfill engine) is called out explicitly rather than silently
queued. Each ported commit was independently reviewed by a
TS-vs-Python parity reviewer; accepted findings are folded in below.
### `5a8d805` — function expressions in primaryKey/orderBy (#178)
- `key_clause.is_plain_column_reference` (fullmatch ≡ TS `^...$`).
- `planner._strip_insignificant_formatting` + `_join_clause` — strips
whitespace and identifier backticks (not quoted literals) for
key-clause comparison only; applied to primary_key/order_by/unique_key,
never engine/partition_by.
- `sql._render_key_clause_columns(columns, column_names)` — quotes
declared columns and bare identifiers; expressions verbatim.
- `validate` — key checks skip expressions.
- **Reviewer fix folded in:** whitespace stripping uses an explicit
JS-`\s` character class (`_JS_WHITESPACE_RE`) instead of
`str.isspace()`, which diverges on U+0085/U+001C–U+001F/U+FEFF.
- Tests: `tests/test_key_clause_expressions.py` (all 5 TS cases).
### `3f1db03` — index-only projections (#193)
- New `core/projection.py` (`is_index_projection`,
`normalize_projection_index`, `canonicalize_projection`,
`render_projection_body`) — exact port including paren peeling,
idempotency, and ClickHouse comma-spacing echo.
- **Design divergence (deliberate):** `ProjectionDefinition` stays ONE
Pydantic model with optional `query`/`index`/`type` instead of the TS
two-member union. Split enforcement mirrors where TS enforces:
states TS's type system cannot represent (neither kind; `index`
without `type`) are rejected at model construction via a
`model_validator`; the both-set case (TS admits structurally) surfaces
as `projection_ambiguous_kind`, empty index as
`projection_empty_index`. Both reviewer-found render holes
(`(None)` body, trailing `TYPE `) are closed by the validator.
- **Snapshot interop fix (reviewer):** `write_snapshot` now dumps with
`exclude_none=True`. TS `JSON.stringify` omits undefined keys and
`isIndexProjection` is `'index' in projection`, so a Python-written
`"index": null` would flip every SELECT projection to index-only when
the TS tool reads the shared snapshot. Reading remains tolerant of
both styles.
- Parser (`_INDEX_PROJECTION_RE`), drift shape fingerprints
(`index=...|type=...`), pull render, introspection all ported.
- Tests: `tests/test_index_only_projections.py` (all TS core cases +
reviewer-requested backtick-name, multiline SHOW CREATE, construction
guards, pull-render case) and 3 drift tests in
`tests/test_drift_compare.py`.
### `8296b8a` — table clauses past the column list + derived PK (#198)
- `create_table_parser`: `_find_column_list_bounds` /
`_extract_table_options` refactor; every clause parser (including
SETTINGS/TTL) now searches only past the column list, so a
projection's inner `ORDER BY` or a column-level `TTL` can't swallow
table-level clauses. Falls back to whole-query when unparseable.
- `drift_compare`: PRIMARY KEY derived from ORDER BY on both sides
when absent. **Reviewer fix folded in:** the actual-side fallback
uses `is not None` (≡ TS `??`), not truthiness — an empty-string
primary key compares as-is.
- Tests: `tests/test_parser_clause_fixes.py` (all 4 TS cases, exact
dataclass equality per reviewer).
### `65c90d6` — Dictionary primitive (#191)
Full lifecycle port mirroring `materialized_view`:
- Model: `DictionaryAttribute` / `DictionaryRange` /
`DictionaryDefinition` (+ `dictionary()` factory, `SchemaKind`,
operation types `create_dictionary`/`drop_dictionary`/
`rename_dictionary`, 8 validation codes).
- Canonicalization (sort kind 3), validation, `render_dictionary_sql`
(`CREATE DICTIONARY IF NOT EXISTS` / `CREATE OR REPLACE DICTIONARY`,
PRIMARY KEY without parens, SOURCE/LAYOUT/LIFETIME/RANGE/SETTINGS/
COMMENT), planner diff (whole-shape compare; `[HIDDEN]` source is
excluded from the diff so the introspection placeholder never
deploys, but does not suppress unrelated changes).
- `clickhouse/create_dictionary_parser.py` — new 1:1 parser port
(attribute modifiers, composite PK, RANGE vs the `range()` array
function, SETTINGS, quoted-value consumption).
- DDL propagation: `wait_for_dictionary` + `dictionary:` operation
keys; `infer_schema_kind_from_engine('Dictionary') == 'dictionary'`.
- CLI: `--rename-dictionary` on generate (parse/merge/resolve/assert/
remap + `RENAME DICTIONARY` plan ops ranked with table renames),
plain-text password warnings on generate output, safety markers
(`drop_dictionary_dependency_break`, DICTIONARY in the object-key
regex), drift object existence, pull introspection + rendering
(`dictionary(...)` with `[HIDDEN]` note + password warnings),
codegen Pydantic models from dictionary attributes.
- ON CLUSTER anchors were already in place from the Category C port.
- Tests: `tests/test_dictionary.py` (29 tests — core DSL/validation/
planner, parser, safety markers, drift).
### `c1d8d0d` — `chkit backfill submit` (surface only)
- `SubmitOptions` + `SUBMIT_FLAGS`/`SUBMIT_FLAG_MAP` in
`chkit_plugin_backfill.options`; `submit` command registered on the
plugin with the TS local-handler behavior (clear "requires a managed
job backend" error when no ObsessionDB service intercepts).
- `chkit_plugin_obsessiondb.backfill_handler` guards `submit` alongside
plan/run/resume when authed + service selected.
- **Not ported (explicit):** the managed-job submit path itself
(`buildSubmitTasks` → jobs backend) depends on `buildBackfillPlan` +
`buildChunkExecutionSql` from the Phase-2 chunking engine.
### Dictionary reviewer triage (folded in post-port)
- **JS `Number()` coercion parity** in
`create_dictionary_parser._consume_quoted_or_bare_value` — Python's
`int()`/`float()` accepted `1_000`/`nan`/`inf` (JS keeps them strings)
and re-rendered `300.0`/`1e5` with a trailing `.0`, a permanent
spurious-diff surface against TS-written snapshots. Now coerces only
JS-grammar decimals (integral floats collapse to int) and `0x` hex.
- `_parse_qualified_table` error message updated to the TS
`parseQualifiedName` wording (shared by table + dictionary renames);
the stale-message test expectation updated with it.
- Primary-key backtick strip narrowed to one backtick per side
(TS `.replace(/^`|`$/g, '')`).
- Test debt closed at pipeline level: dictionary rename pipeline
(RENAME not drop+create, schema `renamed_from`), generate + pull
password warnings, pull dictionary rendering (incl. `[HIDDEN]` note),
codegen dictionary model, JS-number coercion matrix — all in
`tests/test_dictionary.py` (38 tests).
- Reviewer items accepted as-is (no code change): planner comparison
via sorted `model_dump` is order-insensitive where TS
`JSON.stringify` is key-order-sensitive — Python is strictly more
lenient, never the reverse; codepoint vs locale settings sort;
`wait_for_dictionary` quoting is safer than TS.
- Still-open e2e debt (needs live ClickHouse, consistent with prior
passes deferring docker-based e2e): `migrate-dictionary.e2e`,
`generate.e2e` dictionary flows, pull e2e, `sql-validation.e2e`
dictionary block.
### Per-table `plugins` field (baseline gap closed in the same pass)
- `TableDefinition.plugins: dict[str, Any] | None` + `table(plugins=...)`
kwarg — TS `TablePlugins` parity. Metadata only: ignored by the diff
engine (test in `tests/test_planner.py`), carried through
canonicalization and snapshots. Without it, a schema file ported from
TS carrying `plugins: {...}` failed Pydantic validation outright.
Consumers (backfill `timeColumn`) arrive with Phase 2.
### Parity fixes surfaced by the docs dual-language pass (same day)
- **Wheel packaging** — `[tool.hatch.build.targets.wheel]` only shipped
`chkit` + `chkit_plugin_obsessiondb`; a pip-installed `chkit-py` was
missing the codegen and backfill plugins entirely (the `chkit init`
template even suggests importing `chkit_plugin_codegen`). All four
packages now ship in the wheel.
- **Function-style configs (TS `ChxConfigFn`)** — the Python loader only
accepted a static `config` attribute; TS allows
`defineConfig((env) => ({...}))` with `env: {command, mode}` (documented
in the CI/CD guide). Ported: `ChxConfigEnv` model, `define_config`
accepts a callable, `load_config(path, env)` invokes it, and every CLI
command threads `ChxConfigEnv(command=...)`. Test in
`tests/test_user_config_and_config_merge.py`.
### CLI-surface parity ports (surfaced by the docs-accuracy reviewer's live CLI probes)
- **Plugin dispatcher flag forwarding** — `chkit plugin `
hardcoded `flags={}`, so no plugin command could receive its own
`--flags` (Typer rejected the tokens outright). Now the `plugin`
command registers with `ignore_unknown_options`, and the dispatcher
parses forwarded tokens against the plugin command's declared flag
defs via `core.flags.parse_flags` (unknown flags error, TS-style);
remaining tokens stay positional.
- **Top-level `chkit codegen`** — existed only in TS. New
`codegen_shortcut.py` dispatches `plugin codegen codegen` with
forwarded flags (`--check`, `--out-file`, ...). Verified live:
`chkit codegen` writes, `chkit codegen --check` gates.
- **Top-level `chkit obsessiondb `** — the Python spelling was
`chkit plugin obsessiondb ` while the plugin's own runbook
strings printed the TS spelling. New `obsessiondb_shortcut.py` makes
those strings correct; multi-word commands (`service select`) flow
through as positionals.
- **Dispatcher DB connection made opportunistic** — an unreachable
ClickHouse no longer blocks plugin commands that don't need an
executor (codegen, backfill status); mirrors TS.
- **`check.failOnExtraObjects`** — TS config flag was missing from
`ChxCheckConfig`; the drift machinery already had the parameter but
both call sites hardcoded `False`. Field added (default false),
resolved, and wired through `check`/`drift`.
- **`backfill({maxChunkBytes: "10G"})`** — the factory only accepted
ints; suffix strings were CLI-flag-only. `field_validator` now
coerces via `parse_byte_size`, matching the documented
`string | number` contract.
### Remaining gap after this pass (explicit, needs its own project)
- ~~**Phase-2 backfill execution engine**~~ — **CLOSED** by the
2026-08-10 Phase-2 port entry below. No remaining gap: the full
chunking + execution engine, the three upstream fixes (`f85f568`,
`3f9a246`, `9ad23f9` — ported as end-state of `main`), and the
managed-submit backend half of `c1d8d0d` are all in. Everything is at
parity as of upstream `main`.
### Environment note
- `.venv` was found hollow and rebuilt from `python 3.11` +
`pip install -e .[dev]`; latest ruff surfaced new lint rules
(PLR0917) on pre-existing code — annotated rather than refactored.
- ~~`tests/test_e2e_testkit.py::test_create_run_tag_is_unique_across_calls`
is flaky (millisecond-timestamp + random-suffix collision over 100
iterations); observed one collision, passes on re-run. Pre-existing.~~
Fixed in #292: the random suffix is now 32 bits (see that entry).
## Main sync 2026-08-10 — Phase-2 backfill engine port (final parity gap closed)
Full port of the chunking + execution engine and the managed-submit
backend — the last TS surface with no Python counterpart. Ported as the
end-state of `main` (includes `f85f568` MV-source chunk sizing,
`3f9a246` multi-MV UNION ALL replay, `9ad23f9` shared SQL scanner).
### Module map (TS → Python)
- `chunking/{types,boundary-codec,partition-slices,sql}.ts`,
`chunking/utils/{binary-string,ranges,ids}.ts`,
`chunking/services/{metadata,row-probe,distribution}-source.ts`,
`chunking/strategies/*` (7 files), `chunking/planner.ts`,
`chunking/{analyze,strategy-policy}.ts`
→ `chkit_plugin_backfill/chunking/` (same layout, snake_case).
- `detect.ts` → `detect.py`; `planner.ts` → `planner.py`;
`queries.ts` → `queries.py`; `async-backfill.ts` → `async_backfill.py`;
`payload.ts` → `payload.py`; `check.ts` → `check.py`;
`logging.ts` → `logging_utils.py` (stdlib logging + threading.Timer
slow-query warnings); `sdk.ts` → `sdk.py`.
- `plugin.ts` → real `plan`/`run`/`resume`/`status`/`cancel`/`doctor`
handlers in `plugin.py` (Phase-2 stubs removed), `on_check` +
`on_check_report` hooks, TS `wrapPluginRun` error envelope
(json `{ok,command,error}` / text `"