Skip to content

MEC-569: idempotent migration runner, systemd profile, just demo target - #53

Merged
fastrevmd-lab merged 7 commits into
mainfrom
agent/mec-569-migration-runner
Oct 4, 2026
Merged

fastrevmd-lab merged 7 commits into
mainfrom
agent/mec-569-migration-runner

Conversation

@fastrevmd-lab

@fastrevmd-lab fastrevmd-lab commented Oct 4, 2026 •

Copy link
Copy Markdown
Member

Summary

  • scripts/run_migrations.py: idempotent ClickHouse migration runner. Scans infra/clickhouse/*.sql, applies pending migrations in numeric order, records each in ssdf.migrations_applied, and is a no-op on rerun. Fails closed on an unresolved placeholder, a migration-number collision, or a ClickHouse client error.
  • infra/clickhouse/ssdf-clickhouse.service, ssdf-migrate.service, ssdf-single-host.target: single-host systemd profile. The target orders ClickHouse, the migration runner, and mcp-query via After=/Before=/Requires= rather than a wrapper process.
  • infra/clickhouse/README.md, scripts/MIGRATION_RUNNER.md: setup and usage documentation, including the full list of environment variables the migrations require.
  • justfile: adds fmt-check, migrate, and demo targets.
  • services/mcp-query/tests/test_run_migrations.py: unit tests for the runner, including a regression test that keeps the README's documented variable list in sync with the migrations' placeholders.

Acceptance Criteria

  • Runner applies all migrations present at merge time, in numeric order, and is a no-op on rerun
  • Single-host systemd profile starts ClickHouse, the migration runner, and the query service with no mandatory SaaS dependency (offline-first)
  • Documentation covers running SSDF single-host and the migration runner's usage, including adopting an existing deployment via --baseline
  • Single-host systemd profile completes a fresh install, including the readiness probe and per-migration secrets

Usage

export CH_HOST=<host>
export CH_NATIVE_PORT=<native-protocol-port>   # default 9000, not the HTTP port
export CH_USER=<user>
export CH_PASSWORD=<password>
python3 scripts/run_migrations.py

See infra/clickhouse/README.md for the systemd single-host profile and scripts/MIGRATION_RUNNER.md for full runner usage.

Testing

  • uv run pytest tests/test_run_migrations.py -q (services/mcp-query): all tests pass
  • uvx ruff@0.12.4 check / format --check: clean
  • Exercised the systemd unit's readiness probe and credential loading against a throwaway local systemd user-manager unit

References

Closes #28

Bors (Rust Engineer) and others added 7 commits September 29, 2026 13:16
… scorecards

_eval_reference_sql ran the predicate SQL against live ClickHouse and put the
result rows verbatim into predicate_detail, which score.py copies straight
into the committed scorecard. ssdf#24 hand-scrubbed the 22 existing files but
did nothing to stop the scorer from doing it again on the next sovereign run.

For a sovereign-tier manifest, reference_sql predicates now emit only counts,
an overlap count, and a sha256 of the sorted reference set (or a bare
within_tolerance bool for numeric_tolerance) instead of the raw agent/
reference values, and drop live numbers from the pass/fail reason text. The
unredacted detail is preserved as PredicateResult.raw_detail and, when
present, written by the CLI to a new gitignored results/.detail/ sidecar for
local debugging -- never next to the committed scorecard.

Also adds a CI guard (test_results_no_live_ips.py) that fails if any
committed services/evals/results/*.json contains a non-RFC5737 IPv4 address,
and a regression test that scores a synthetic sovereign manifest against a
fake ClickHouse client returning 10.0.0.1 and asserts it never reaches the
scorecard (only the sidecar). Both fail against pre-fix score.py.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Companion doc update for the predicate-detail redaction fix: explains what
a committed scorecard now withholds for tier: sovereign and where the raw
values (if needed for debugging) end up instead.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
- scripts/run_migrations.py: idempotent ClickHouse migration runner
- infra/clickhouse/021_migrations_tracking.sql: tracking table DDL
- infra/clickhouse/ssdf-clickhouse.service: ClickHouse systemd unit
- infra/clickhouse/ssdf-single-host.service: combined ClickHouse+MCP profile
- infra/clickhouse/README.md: documentation for ClickHouse setup
- scripts/MIGRATION_RUNNER.md: runner usage guide
- justfile: added 'fmt-check', 'migrate', and 'demo' targets

The runner applies all pending migrations in numeric order and records
applied migrations in ssdf.migrations_applied table. Safe to rerun.

The systemd profile starts ClickHouse and all SSDF services for single-host
deployment without mandatory SaaS dependency.

Refs #28
…st profile

Addresses review findings on the migration runner (MEC-569): substitutes
per-migration credential placeholders before anything is sent to the
database and fails closed if a required one is missing, creates its
tracking table directly instead of as a numbered migration so a fresh
install can bootstrap, refuses to run on a migration-number collision,
treats database errors while checking applied migrations as fatal instead
of assuming nothing is applied, stops passing the database password on the
command line, and corrects the client port default. Also replaces the
single-host systemd service with a target plus a bounded, credential-backed
migration unit, and hardens the ClickHouse unit's capabilities and resource
limits.

Adds unit tests for the runner's placeholder substitution, fail-closed
error paths, collision refusal, and password handling.

Refs #28

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…gration secrets file

Fixes two gaps from PR review (MEC-1672) that stopped the single-host
systemd profile from completing a fresh install:

- ssdf-migrate.service's ExecStartPre readiness probe ran without a
  password, so it always failed once the admin user required auth.
  It now loads the same credential as ExecStart and authenticates.
- The profile had no way to supply the per-migration *_PW /
  VIEW_PSEUDONYM_KEY_* variables the migrations reference, so a fresh
  install aborted at the first one. Adds EnvironmentFile= plus README
  documentation of every required variable, backed by a regression
  test that keeps the two in sync.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@fastrevmd-lab

Copy link
Copy Markdown
Member Author

Addressed the two remaining correctness findings from the MEC-1672 re-review (93e0a70):

  • A (unauthenticated readiness probe): ssdf-migrate.service's ExecStartPre now loads the same LoadCredential= secret as ExecStart and authenticates the SELECT 1 probe, instead of running clickhouse-client with no password.
  • B (no per-migration secrets path): added EnvironmentFile=/etc/ssdf/migrate-secrets.env to the unit, documented every required *_PW / VIEW_PSEUDONYM_KEY_* variable in infra/clickhouse/README.md with the matching install -m 0600 step, and added a regression test (test_readme_lists_every_required_placeholder) that fails if a future migration adds a placeholder the README doesn't document.
  • Also brought the PR description up to date (it still named a removed 021_migrations_tracking.sql file and ssdf-single-host.service, and had empty usage/testing blocks) and merged current main into the branch (clean, no conflicts).

Finding C (stale pre-squash commits from #39 already on main) is not addressed on this branch: the task scope for this fix explicitly excludes opening a new PR, and fixing it the way the reviewer suggested (fresh single-commit PR) would require that. Flagging for Kay to decide whether it's worth a follow-up given the content is a no-op duplicate of code already on main.

Verified:

  • uv run pytest -m "not integration" -q (services/mcp-query): 575 passed, 37 skipped, 10 deselected
  • uvx ruff@0.12.4 check services / format --check services: clean
  • systemd-analyze verify on the unit file: no errors
  • Exercised the ExecStartPre probe logic standalone against a fake clickhouse-client: succeeds with the right password, fails closed (bounded) with the wrong one

@fastrevmd-lab
fastrevmd-lab merged commit b780dd0 into main Oct 4, 2026
15 checks passed
@fastrevmd-lab
fastrevmd-lab deleted the agent/mec-569-migration-runner branch October 4, 2026 06:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

P4: Single-host quick start — idempotent migrations, one-host systemd profile, just demo with synthetic data

1 participant