Skip to content

feat: Wave 10 W10-1 to W10-4 onto main (stacked merges of #63, #64, #65) - #66

Merged
davdxpx merged 11 commits into
mainfrom
feat/wave-10-onto-main
Nov 4, 2026
Merged

davdxpx merged 11 commits into
mainfrom
feat/wave-10-onto-main

Conversation

@davdxpx

@davdxpx davdxpx commented Nov 4, 2026

Copy link
Copy Markdown
Owner

Why

The stacked Wave 10 PRs were merged into their stacked bases after #62 had already reached main, so their code never arrived on main:

This PR brings exactly that already-reviewed code to main so the release can be built from main. It adds no new change.

Content

  • W10-1/2: observed targets on hosted providers (ADR-0039), Control Store bundle 01M6HQW7JQYHC8YR9KNTQ4PFFZ_observed-targets
  • W10-3: E16 hotfix_without_evidence, E18 applied_not_in_source
  • W10-4: production plans on an observed target, stored denied by migration.observed-target

Check: git diff feat/wave-10-order feat/wave-10-e16-e18-detection equals git diff 8dd87b19 0be91566 (same sha256), and the merge into main is clean.

CI

The red jobs are the same failures as on main since e6f4c77: bun audit (seroval 1.6.9), the quickstart lab DATA_READ_NOT_PERMITTED (target_memory_unlimited), and a flaky design-system UI test. The image build itself passes.

Test plan

  • Redeploy on reos-01 from the merge commit: Control Store backup, migrate exits 0 with the new bundle, serve/gateway/worker healthy
  • staging and scratch targets stay healthy after the deploy

The design of W10-1 and W10-2: a target mode observed that writes nothing
to the database (no marker, no exponetdb schema), identity by the pinned
system identifier and the recorded database oid, a login suffix on
session-pooler endpoints, pooler-only clusters for observer sessions, the
new refusal TARGET_OBSERVED_ONLY and an observer-only bootstrap script.

Developed by `@davdxpx`
…ADR-0039)

Wave 10 W10-1 and W10-2 (ExponetDB side), under the owner's Wave 10 order
(W10-D3, W10-D4). A hosted production database is observed without any
write and reached through its session pooler only.

- Contracts (additive): EndpointRequest/EndpointView loginSuffix (pooler
  endpoints only, ^[a-z0-9]{1,40}$); TargetRegisterRequest mode
  (managed | observed, default managed); Target view mode; error code
  TARGET_OBSERVED_ONLY (409, not retryable); REGISTRY_CONFLICT reason
  cluster_pooler_only; bootstrap-sql query roles (all | observer).
  target_get at toolVersion 2 (pinned); the MCP catalog pins and the
  replay transcripts are re-recorded (the diff is the new member, the
  description and the digest).
- Control Store bundle observed-targets (01M6HQW7JQYHC8YR9KNTQ4PFFZ):
  registry.endpoints.login_suffix (pooler only), registry.targets.mode
  (NOT NULL DEFAULT managed); the endpoint and target guards are replaced
  (same signatures): both columns immutable, an observed target never
  active or suspended. Frozen bundles untouched.
- Registry: the login through a suffixed pooler endpoint is
  exponetdb_<role>.<suffix> (open and probeAddress); direct endpoints first,
  session poolers only for observer and reader and only when the cluster
  has no direct endpoint; other roles get cluster_pooler_only. A cluster
  of session poolers only may be registered. target.register mode observed
  needs the observer credential only, proves the database on an observer
  session (identifier, name, oid), records the target and placement, takes
  the registration snapshot as the observer, writes nothing and never
  activates; its analysis lists no writes; forTarget refuses every
  non-observer role on an observed target.
- Identity: requireIdentity and the health identity probe compare the
  database oid for observed targets (TARGET_IDENTITY_MISMATCH,
  details.reason database_oid); a mismatch is a critical finding, the
  health state unhealthy, never a suspension.
- Allowed on observed targets: health sampling, schema reads, drift (on
  demand and scheduled), statistics, sessions. Refused with
  TARGET_OBSERVED_ONLY: data reads, raw statements, cancel and terminate
  plans, drift acceptance, every migration plan, migration status and
  detail (the legacy-ledger view is left to W10-4), a managed
  registration of an observed target. The ledger watch skips them.
- Bootstrap: cluster bootstrap-sql --roles observer (API roles=observer)
  emits the observer only: the role, pg_monitor, its user-settable
  settings and CONNECT; proven as a non-superuser CREATEROLE administrator
  with pg_monitor admin on PostgreSQL 16, 17 and 18, run twice.
- CLI: target register --mode observed, cluster endpoint add
  --pooler-mode --login-suffix; cluster.yaml takes loginSuffix.
- Docs: registry.md §1 and §2.2.1, postgres-adapter.md §3,
  credentials-and-roles.md §8.1, onboard-external-cluster.md "A hosted
  provider: observe only", error-model.md, gates/10.md §3.

The login suffix is proven at the session specification only; no live
Supavisor was available (NOT PROVEN live).

Red against the source before:
    TypeError: sessionEndpoints is not a function
    AssertionError: exponetdb_ledger_owner: expected '-- ExponetDB bootstrap for an externa…' not to contain 'exponetdb_ledger_owner'
    error: column "mode" of relation "targets" does not exist
    RegistryError: The request does not match the contract. (a cluster of session poolers only)
    AssertionError: expected [] to include 'exponetdb_observer.ref123'
    AssertionError: expected [ 'active', undefined ] to deeply equal [ 'registered', 'observed' ]

Developed by @davdxpx
…pooler roles, refusals)

Two independent reviews of ed108c2.

- Docs: the Wave 11 path from an observed target to a managed one is not
  built and is open as OD-71 (a path is never reused, target_guard EXG10);
  options (a) one-way adoption onto a new placement (recommended, C-4) and
  (b) path reuse when every earlier target at it is observed and
  decommissioned. ADR-0039 Consequences name the residuals: a restored or
  forked provider project passes every pin (the owner confirms the login
  suffix against the live project, a step in the onboarding walkthrough),
  the optional --ledger part of the observer script, and one cluster per
  pooler host:port (shortcut).
- Pooler sessions are for the observer only (the reader is refused as
  cluster_pooler_only); every session whose server-side session_user is not
  exponetdb_<role> is refused (TARGET_CREDENTIAL_INVALID, session_user).
- Connector.forTarget compares the session's database oid with the
  placement's recorded oid for an observed target
  (TARGET_IDENTITY_MISMATCH, database_oid); health reads it as a mismatch.
- planMigrationVerify (bundle and baseline) and restore.plan refuse an
  observed target with TARGET_OBSERVED_ONLY; the route error lists name it.
- Health history: an observed registered target is sampled, so a stopped
  sampler shows its gaps.
- Bundle 01M6HQW7JQYHC8YR9KNTQ4PFFZ (not deployed, amended): the database
  guard keeps registry.databases.observed_oid once set.
- Tests: "writes nothing" compares owners and ACLs of schemas, relations,
  functions and the database, default privileges, extensions, ExponetDB's
  roles, the observer's memberships and the database's role settings
  before and after registration, a health sample and a drift check; data
  read, explain and restore refused over REST; verify, resume, rollback,
  baseline and import analysis refused; the suffixed login captured at the
  session seam while the server session is the plain role.
- Web test fixtures carry loginSuffix (a cached typecheck hid them).

Red against the source before:
    AssertionError: expected [ { …(12) }, { …(12) } ] to deeply equal []   (reader through a pooler)
    AssertionError: reader: expected { code: 'REGISTRY_CONFLICT', …(1) } to deeply equal { code: 'REGISTRY_CONFLICT', …(1) }
    + "verify": "QUERY_PARSE_ERROR"   (expected TARGET_OBSERVED_ONLY)
    + 404, "NOT_FOUND"   (restore plan of an observed target, expected 409 TARGET_OBSERVED_ONLY)
    AssertionError: expected [] to deeply equal [ { …(5) }, { …(5) }, { …(5) } ]   (health history gaps)
    AssertionError: expected undefined to be 'EXG09'   (observed_oid changed)

Developed by @davdxpx
…h a pooler (ADR-0039)

Review of ed108c2: a pooler may drop the startup options that pin a
session's settings, and nothing noticed. Every new connection now reads
the pinned settings back from pg_settings (search_path, TimeZone,
DateStyle, IntervalStyle, extra_float_digits, bytea_output,
standard_conforming_strings, quote_all_identifiers, lc_monetary, the
three timeouts, default_transaction_read_only and, for the read-only
roles, constraint_exclusion). Through a pooler endpoint (the connector
passes reapplySettings) a value that differs is set again with
set_config and read again; on any path a value that still differs fails
closed (CAPABILITY_UNAVAILABLE, session_settings). The read and the
re-set use the guard's protocol, so a health probe of a path whose
extended protocol hangs still opens. The comparison is unit tested; the
integration test drops the startup options at the pg.Client seam (a test
spy, no production option). postgres-adapter.md §3 guard 6.

Red against the source before:
    AssertionError: expected '"$user", public' to be '' // Object.is equality

Developed by @davdxpx
…a widened observer (ADR-0039)

Review of ed108c2. The script for a hosted provider's non-superuser
administrator now starts with \set ON_ERROR_STOP on (it stops at the first
error even without psql's flag) and runs the observer part in one
transaction, so a refusal leaves nothing behind; the optional --ledger
part follows after the commit (\connect ends the session). An existing
exponetdb_observer that is a member of any role other than pg_monitor is
refused like one with a privileged attribute, and ALTER ROLE ... RESET
ALL removes earlier role settings before the intended three are set. The
non-superuser integration test (PostgreSQL 16, 17, 18) adds a pre-existing
observer with an extra membership: the script stops and the database
gets no grant. Its cleanup now runs in finally (an earlier failing run
left administrator roles behind on the shared test servers; removed).
credentials-and-roles.md §8.1 and the onboarding walkthrough say so.

Red against the source before:
    AssertionError: expected +0 not to be +0 // Object.is equality   (the script did not stop)

Developed by @davdxpx
… its one edit

The database guard keeps registry.databases.observed_oid once it is set
(405e403, ADR-0039 §2). The ledger-integrity test simulated a dump
restored under the same name by editing the recorded oid as the
superuser, which the guard now refuses; the edit runs with
session_replication_role = replica for that one statement, as the auth
suites age their times. The behavior under test (a rollback plan refused
with TARGET_IDENTITY_MISMATCH, database_oid) is unchanged.

Red against the source before:
    error: a database keeps the oid recorded at its registration

Developed by @davdxpx
…(E18) (W10-3, OD-65 (a))

The G6 waivers of failure cases E16 and E18 expire in Wave 10; the owner
decided OD-65 (a): both detections are built now.

E16: the worker task ledger.watch (every 10 minutes) now also compares
each production target with its evidence target. Every migration in the
production target's Control Store mirror (origin exponetdb, not
reverted) that the evidence target has not applied with the same
checksum and verified with the same verify digest, read live as its
observer with planning's trust rules (evidenceOf, extracted from
collectEvidence unchanged), keeps one warning health finding
hotfix_without_evidence open on the production target, naming up to 64
migrations with what staging has of each; it clears when none is left.
An unreadable evidence target leaves the finding as it is (the task
fails visibly); a production target without an evidence environment is
not compared.

E18: a migration plan whose request says its bundles are the whole
source (new optional MigrationPlanRequest.sourceComplete; the CLI sets
it when it plans every local bundle) is compared by id with the
target's mirror before planning, so a plan refused because nothing is
pending still records it: one warning health finding
applied_not_in_source, cleared by a later whole source that has the
bundle again. A plan of named bundles and MCP plans are not compared.

Both findings are of kind health like ledger_divergence: a kind-C drift
check resolves every other open drift finding, and drift.accept adopts a
schema, which neither gives staging evidence nor restores a file. No
Control Store bundle; the contract change is additive (OpenAPI and SDK
regenerated, MCP tool versions unchanged). Not built: the ledger-row
mark evidence: break_glass and a finding resolution with a note.
gates/6.md §5 and §10.3, gates/10.md (built, awaiting the owner),
staging-production-policy.md §3, failure-and-recovery.md, ledger.md,
drift-detection.md, OD-65, the review index.

Red against the source before:
    TypeError: hotfixesWithoutEvidence is not a function   (4 failed, hotfix-and-source.int.test.ts)
    TypeError: recordMigrationFinding is not a function    (3 failed, diagnostics.int.test.ts)
    AssertionError: expected [] to have a length of 1 but got +0   (http-migrations.int.test.ts "E18: ...")

Developed by @davdxpx
…findings, an isolated E16 watch

An independent review of #64 found two High, three
Medium and six Low items.

H1: E18 compared the submitted directory names before ingest. The
planner now hands the ids to the comparison (onSourceValidated) only
after ingest validated every bundle (manifest, directory name, checksum
against what is applied); the use case records the finding after the
plan's transaction, so a plan refused afterwards (nothing pending) still
counts and a refused bundle records nothing.

H2: E18 followed whichever plan came last. Migration ids are ULIDs:
only an applied migration older than the source's newest bundle opens or
keeps the finding; a newer one means the source is behind and is shown
in the plan's analysis.sourceCheck.behind only (additive contract field
MigrationPlanAnalysis.sourceCheck). The finding clears only when a whole
source has every migration it names that is still applied. The mirror
read and the finding write are one transaction under a per-target
advisory lock; the details name the caller and the source's newest id.
Residual (documented): a feature branch cut before an older bundle was
merged still opens it.

M1: opening and resolving both findings are audited in the same
transaction (ledger.hotfix_without_evidence.detected/.cleared with the
worker, ledger.applied_not_in_source.detected/.cleared with the caller);
audit.md lists them.

M2: hotfixesWithoutEvidence returns a typed result. Without an evidence
target (none named, decommissioned, observed) the finding is resolved
superseded; an unreadable evidence target (TargetError, RegistryError,
identity mismatch) leaves it as it is and does not fail the round.
apps/server/test/hotfix-watch.int.test.ts runs ledger.watch itself (the
server tests may now reuse the engine and registry test worlds,
graph.json).

M3: a diverging staging ledger is said as such (details.cause
evidence_divergent, its own summary), not as every migration missing.

L1 one evidence read per evidence target and round; L2 the 64 shown are
the newest; L3 an unreadable production ledger no longer skips E16;
L4, L5 the 50-bundle limit and the excluded legacy-import and baseline
rows are stated; L6 needs no change: an exponetdb row has a null verify
digest only for a bundle without verify.sql, whose verification has none
either (they compare equal; the E16 test's hotfix bundle shows it).

gates/6.md §5 and §10.3, gates/10.md W10-3 (still built, awaiting the
owner), staging-production-policy.md §3, drift-detection.md §1 (the E18
paragraph moved out of the table it had split), failure-and-recovery.md,
ledger.md, audit.md.

Red against the source before (the new tests on a49022e):
    TypeError: sourceFindingList is not a function   (5 failed, source-findings.test.ts)
    AssertionError: expected { …(2) } to match object { kind: 'compared', …(3) }   (hotfix-and-source.int.test.ts, 5 failed)
    TypeError: store.transaction is not a function   (4 failed, diagnostics.int.test.ts)
    AssertionError: expected { state: 'open', …(2) } to match object { state: 'open', …(1) }   (hotfix-watch.int.test.ts)
    AssertionError: expected undefined to match object { actor: { kind: 'service' }, …(2) }   (http-migrations.int.test.ts "E18: a plan of the whole local source …")
    AssertionError: expected [ { …(14) } ] to deeply equal []   (http-migrations.int.test.ts "E18: an invalid whole source …")

Developed by @davdxpx
…erved-target (W10-4)

A migration.apply plan for an observed target (ADR-0039) is built for real
and stored denied by the new rule migration.observed-target (deny, no
break-glass override, no parameter a setting could change). Accept is
PLAN_DENIED; no operation and no approval can exist for it. Every other
plan kind on an observed target stays refused with TARGET_OBSERVED_ONLY.

- target.ts: readObservedState reads as the observer without marker or
  exponetdb schema: empty ledger with the ls1 hash of no rows, fingerprint,
  extensions, sizes, inRecovery; system identifier and database oid
  checked as the connector does.
- planner.ts: the observed branch for migration.apply only, state
  registered with a registration snapshot; no exponetdb reads and no
  migrator-role finding; pending is anchored on the evidence target's
  baseline (migrations.ledger_state); additive target.mode,
  expectedState.anchor, expectedState.legacyLedger, facts.targetMode and
  analysis.observed.
- legacy-ledger.ts: the names-only digest of
  supabase_migrations.schema_migrations (version and name, never
  statements; unreadable or absent, never an empty list). Its own module,
  with the savepoint guard moved out of legacy.ts, so the planner does not
  import the legacy import (dependency-cruiser no-circular).
- kind.ts: checkBindings and execute refuse an observed target with
  TARGET_OBSERVED_ONLY (second guard).
- policy: the optional targetMode fact and the rule; the policy version of
  every migration.apply plan changes once (active plans go stale at the
  deploy).
- contracts: the additive optional fields; generated artifacts unchanged
  (the plan content is not in OpenAPI), no new error code, no Control
  Store bundle, frozen vectors unchanged.
- application: no E18 source recording for an observed target.
- docs: ADR-0039 §3 amendment (2026-11-04), staging-production-policy.md
  §2.1, policy-engine.md, gates/10.md (criterion 3 and W10-4: built on
  local containers; the real-target run waits for the owner's GO).
- tests: the "writes nothing" catalog footprint moved to
  packages/diagnostics/test/footprint.ts and shared; migrations-engine
  tests may use the diagnostics package (registration snapshots).

Red before the change:
- packages/policy test/migration-rules.test.ts: 3 failed | 20 passed (23)
  ("prod: expected 'allow' to be 'deny'")
- packages/migrations-engine test/observed.int.test.ts: 8 failed |
  1 passed (9) (the plan refused with TARGET_OBSERVED_ONLY at planning)
- apps/server http-migrations.int.test.ts "observed target over REST":
  expected [409, undefined] to equal [201, 'deny'] (TARGET_OBSERVED_ONLY)
- apps/server mcp-plans.int.test.ts "observed production": Refused:
  TARGET_OBSERVED_ONLY instead of a denied plan
…ule reads the target mode, ledger digest by column

Security review of #65 (no Critical or High):

- M1: MigrationApplyKind.checkBindings reports the changed binding
  `target: observed` instead of throwing TARGET_OBSERVED_ONLY. An
  acceptance now invalidates the plan and audits plan.invalidated; a
  queued operation of such a plan fails at the worker's start (PLAN_STALE)
  instead of staying queued and being claimed again. execute still refuses
  with TARGET_OBSERVED_ONLY.
- M2: migration.observed-target also fails when content.target.mode is
  observed, so a plan path that forgets facts.targetMode stays denied.
  Managed plans are unchanged (no new field, same plan hashes).
- L1: the legacy ledger digest binds `unreadable` only for a read the
  target refused (a TargetError readsAsUnreadable accepts); any other error
  fails the plan. The guard takes the predicate; the legacy import keeps
  its own.
- L2: the names query orders by the ledger's version column
  (`ORDER BY m.version`), not by the text alias; the comment says so. The
  digests of the existing tests do not change (Supabase versions are
  fixed-width text); a numeric version column is now ordered numerically.
- Docs: ADR-0039 §3 amendment, staging-production-policy.md §2.1,
  policy-engine.md, gates/10.md.

Red before the fix:
- packages/policy test/migration-rules.test.ts: 1 failed | 23 passed (24)
  (M2: expected 'allow' to be 'deny')
- packages/migrations-engine test/legacy-ledger.test.ts: 1 failed |
  1 passed (2) (L1: promise resolved "unreadable" instead of rejecting)
- packages/migrations-engine test/observed.int.test.ts: 3 failed |
  7 passed (10) (M1 accept: TARGET_OBSERVED_ONLY thrown instead of
  PLAN_STALE; M1 worker: MigrationError thrown out of the driver, the
  operation left queued; L2: digest of the text order)
@davdxpx
davdxpx merged commit 3dc33f9 into main Nov 4, 2026
15 of 18 checks passed
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.

1 participant