Skip to content

fix(bootstrap): cover v0.34.1 oauth_clients.{source_id, federated_read} columns#1017

Closed
ChenyqThu wants to merge 1 commit into
garrytan:masterfrom
ChenyqThu:upstream-fix/bootstrap-oauth-clients-cols
Closed

fix(bootstrap): cover v0.34.1 oauth_clients.{source_id, federated_read} columns#1017
ChenyqThu wants to merge 1 commit into
garrytan:masterfrom
ChenyqThu:upstream-fix/bootstrap-oauth-clients-cols

Conversation

@ChenyqThu
Copy link
Copy Markdown

Why

applyForwardReferenceBootstrap in both PostgresEngine and PGLiteEngine covers 9 forward-reference targets that schema-embedded.ts makes (pages.source_id, pages.deleted_at, links., content_chunks., mcp_request_log.*, subagent_messages.provider_id, ingest_log.source_id, …) — but missed v0.34.1's oauth_clients.{source_id, federated_read} additions.

Result: brains upgrading from a pre-v0.34 schema (which has oauth_clients but neither column) crash at schema-embedded.ts during SCHEMA_SQL replay with:

column "source_id" does not exist

…on the partial-index CREATE INDEX idx_oauth_clients_source_id ON oauth_clients(source_id) WHERE source_id IS NOT NULL and on the parallel idx_oauth_clients_federated_read GIN-index DDL. Migrations v60-v65 backfill both columns + RLS policies later, but they can't run until SCHEMA_SQL replay succeeds, so the bootstrap must add enough state up front.

Patch shape

Same pattern as #627 (superseded by upstream fixwave #682+#741 for mcp_request_log v0.26.3 columns):

  1. Probe rows in the existing information_schema EXISTS round-trip — oauth_clients_exists, oauth_source_id_exists, oauth_federated_read_exists.
  2. needsOauthClientsBootstrap when the table exists but either column is missing.
  3. Early-return guard extended so fresh installs and modern brains still no-op.
  4. ALTER TABLE block at the end of the function alongside the other missing-column bootstraps. source_id picks up its FK to sources(id) and federated_read its NOT NULL DEFAULT '{}'.

Mirrored across src/core/postgres-engine.ts and src/core/pglite-engine.ts. Doc comments at the top of each function updated to list the new coverage.

Test follow-through

test/schema-bootstrap-coverage.test.ts gains two entries in REQUIRED_BOOTSTRAP_COVERAGE (oauth_clients.source_id, oauth_clients.federated_read). The existing contract test strips both columns, runs the bootstrap, then asserts they exist after SCHEMA_SQL replay — same loop as every other v33+ column the test already covers.

E2E test (test/e2e/postgres-bootstrap.test.ts) was not extended in this PR — its single "pre-v0.18" mutation scenario is structurally identical for any forward-reference target, and the contract test already validates the per-column bootstrap. Happy to add an oauth-specific E2E case if maintainers prefer.

Validation

  • bun run typecheck clean
  • bun test test/schema-bootstrap-coverage.test.ts test/bootstrap.test.ts:
    • 11 pass / 0 fail (was 11 pass with 48 expect() calls; now 50 — the +2 new probes)

Field repro

Hit during the Jarvis KOS v2 fork's v0.31.2 → v0.34.4 sync (commit 1b6acd77):

  • bun install postinstall ran gbrain apply-migrations (requires schema_version ≥ 51 for the v0.32.2 facts orchestrator).
  • Schema was at v45. Running gbrain init --migrate-only to bump v45 → v66 failed at the idx_oauth_clients_source_id DDL.
  • Worked around with one manual ALTER TABLE oauth_clients ADD COLUMN IF NOT EXISTS source_id … / federated_read …; migrations v60-v65 then ran clean in under a minute.
  • Same shape as the mcp_request_log trap that produced fix(bootstrap): cover v0.26.3 mcp_request_log columns #627 in our v0.26.7 sync.

🤖 Generated with Claude Code

…d} columns

Extends applyForwardReferenceBootstrap in both PostgresEngine and
PGLiteEngine to probe oauth_clients.{source_id, federated_read} and
ALTER TABLE ADD COLUMN IF NOT EXISTS them when the table exists but
the columns don't.

Without this, brains upgrading from a pre-v0.34 schema (which has
oauth_clients but no source_id / federated_read columns) crash at
schema-embedded.ts during SCHEMA_SQL replay with:

  column "source_id" does not exist

…on the CREATE INDEX idx_oauth_clients_source_id partial-index and the
parallel idx_oauth_clients_federated_read GIN-index statements. The
migration chain (v60-v65) backfills both columns + RLS policies later,
but it can't run until SCHEMA_SQL replay succeeds, so the bootstrap
must add enough state up front.

Pattern lift from garrytan#627 (superseded by upstream fix wave garrytan#682+garrytan#741,
which extended the same mechanism to mcp_request_log.{agent_name,
params, error_message} in v0.26.3). Same shape:

  1. Probe rows in the existing information_schema EXISTS round-trip
     for the table + each column.
  2. needsOauthClientsBootstrap when the table exists but either column
     is missing.
  3. Extra clause in the early-return guard so fresh installs and
     modern brains still no-op.
  4. ALTER TABLE block at the end of the function alongside the other
     missing-column bootstraps. source_id picks up its FK to sources(id)
     and federated_read its NOT NULL DEFAULT '{}'.

Coverage:

- test/schema-bootstrap-coverage.test.ts — REQUIRED_BOOTSTRAP_COVERAGE
  gains two entries (oauth_clients.source_id, oauth_clients.federated_read).
  Contract test strips both columns, runs the bootstrap, then asserts
  they exist after SCHEMA_SQL replay — same as every other v33+ column
  the test already covers.

Validation:

- bun run typecheck clean
- bun test test/schema-bootstrap-coverage.test.ts test/bootstrap.test.ts:
  11 pass / 0 fail (was 11 pass with 48 expect() calls; now 50 — the +2
  new probes).

Field repro (Jarvis KOS v2 fork, 2026-05-09 v0.31.2 → v0.34.4 sync):
schema v45 → v66 bumped via gbrain init --migrate-only, which forced
the SCHEMA_SQL replay path and tripped the idx_oauth_clients_source_id
DDL. Manually ALTER-ed the two columns; migrations then ran v60-v65
clean. Same pattern as the mcp_request_log trap in v0.26.7 sync.
ChenyqThu pushed a commit to ChenyqThu/jarvis-knowledge-os-v2 that referenced this pull request May 15, 2026
JARVIS-ARCHITECTURE.md §6.25 records the 2026-05-15 follow-up session:
diagnostic correction (the historical 117k stderr "fire" that wasn't),
two upstream PRs filed (garrytan#1016 google max_batch_tokens, garrytan#1017
oauth_clients forward-bootstrap), CJK keyword-only eval verdict,
overlap-matrix verdict, M2-B + M2-C verdicts, mechanical cleanup
(48 sync_failures ack'd, bun-test hang root-caused), and the new
[facts:absorb] sub-process DB-connection latent bug. 8 TODO items
closed, 1 new entry filed.

CLAUDE.md "Chinese-first knowledge base" rule tightened per the
CJK-eval verdict: the strict invariant is *compound CJK (4+ Han chars
without whitespace) requires vector*; English and 2-3 char standalone
CJK match fine on keyword. Operational guidance unchanged — the modal
operator query on this brain is a compound CJK phrase that depends on
vector being live.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@ChenyqThu
Copy link
Copy Markdown
Author

Superseded by upstream v0.35.5.0 (4446e9f9, PR #1111).

The v0.35.5.0 fix(bootstrap): extend probes for files/oauth_clients/sources.archived* + add MIGRATIONS introspection guard commit is a strict superset of this PR:

Same pattern as #627 (closed when v0.31.1.1 fixwave superseded with broader v0.20 + v39-v41 column coverage).

Production impact for jarvis-knowledge-os-v2 fork: already manually ALTER-ed on the prod DB during v0.34.4 sync (per docs/JARVIS-ARCHITECTURE.md §6.24); v0.35.6.0 sync landed today (2026-05-17) and bun install postinstall confirmed All migrations up to date with no manual intervention needed.

@ChenyqThu ChenyqThu closed this May 17, 2026
ChenyqThu pushed a commit to ChenyqThu/jarvis-knowledge-os-v2 that referenced this pull request May 17, 2026
…08 commits, v0.34.4 → v0.35.6.0)

Auto-merge: 95% clean. WAL fork patch + pglite 0.4.4 override + google.ts
max_batch_tokens patch all survived. Real conflicts: 2 (.gitignore +
CLAUDE.md), both mechanical (fork-only block reorder).

Key value:
- v0.35.5.0 bootstrap fixwave (4446e9f) SUPERSEDES fork PR garrytan#1017
  (oauth_clients.source_id + federated_read). Upstream adds 7 probes
  + files.* + sources.archived.* + DDL connection threading +
  MIGRATIONS introspection guard — strict superset of our PR.
- v0.35.4.0 entity bare-name resolver 58x perf benefits enrich-sweep.
- v0.35.5.0 walker pruneDir speeds up sync (descent-time exclusion).
- v0.35.6.0 search floor-ratio gate improves retrieval quality.
- v0.35.5.1 supervisor clean-exit classification reduces launchd noise.

Validation: bun typecheck clean, bun test test/ai/+bootstrap 221/221
pass, bun run build emits 0.35.6.0 binary. Production: bun install
postinstall silent-applied migrations (schema_version still 66,
3138 pages preserved, brain_score 80/100 unchanged, RLS 41/41).
5 launchd services bootout/bootstrap clean; kos-compat-api PID 9074
serving /status with 3138 pages locally + via kos.chenge.ink.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
ChenyqThu pushed a commit to ChenyqThu/jarvis-knowledge-os-v2 that referenced this pull request May 17, 2026
§6.26 in JARVIS-ARCHITECTURE.md: 9-version upstream sync (108 commits,
v0.34.4 → v0.35.6.0), only 2 real conflicts, PR garrytan#1017 superseded by
v0.35.5.0 garrytan#1111 bootstrap fixwave, brain_score 80/100 unchanged,
3138 pages preserved, ~1h end-to-end vs 3-3.5h plan estimate.

TODO.md: header bumped to post-v0.35.6.0 state, PR-2 entry marked CLOSED
2026-05-17 with supersede link.

README.md: upstream_compat bumped >= 0.35.6.0.

CONSOLIDATION-PLAN.md: Last reviewed bumped to 2026-05-17.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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