Skip to content

fix(bootstrap): preserve explicit source precedence - #89

Closed
seonghobae wants to merge 25 commits into
mainfrom
fix/bootstrap-explicit-dsn-precedence
Closed

seonghobae wants to merge 25 commits into
mainfrom
fix/bootstrap-explicit-dsn-precedence

Conversation

@seonghobae

@seonghobae seonghobae commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

RCA

Bootstrap source selection originally used boolean truthiness, conflating omission (None) with explicit false-valued input and allowing ambiguous database/decryption authority. The branch now separates source absence, source type, and source value.

  • resolve_dsn() consults PG_LLM_BATCH_DSN only when the explicit argument is omitted. An explicit Postgres DSN must be an exact string; non-string, empty, or whitespace-only explicit values fail with bounded ConfigError before environment fallback or libpq. Omitted input also rejects empty/whitespace-only environment DSNs. Valid nonblank DSNs retain byte identity.
  • resolve_secret_key() consults PG_LLM_BATCH_SECRET_KEY only when the explicit argument is omitted. An explicit Fernet bootstrap key must be an exact string; non-string values fail before environment fallback/store construction, while the valid explicit empty string remains empty and cannot silently inherit ambient decryption authority.
  • Existing omitted-argument fallback, missing-required-DSN failure, missing optional-key behavior, SecretStore semantics, schema, provider, HTTP, model, workflow, and release contracts remain unchanged.

Test-first evidence

Earlier RED→GREEN cycles established empty/whitespace precedence and ambient blank-DSN rejection. The latest type-authority cycle is independently reviewable:

  1. RED c140ee069eb498a0b98902a8956e046b7eb35039 added tests/test_bootstrap_type_boundary.py. CI 31354062621 failed seven intended cases: booleans/floats/bytes/containers either crossed the boundary or produced unrelated Python errors instead of bounded bootstrap validation.
  2. Production GREEN 6319d21648bd9176909b026ca17e69624cd4fbc9 rejects non-string explicit DSN/Fernet values before fallback; CI 31354421145, Security Scan 31354421128, and SAST Semgrep 31354421133 succeeded.
  3. Documentation RED 8b283e294f503bed38395ba4b9e60497a0ed41de required non-string, explicit Postgres DSN, explicit Fernet, and before environment fallback in doctoring/CHANGELOG. CI 31354545493 failed only that new documentation contract.
  4. Doctoring/CHANGELOG were reconciled, and a pre-existing documentation phrase contract (bootstrap secret-key precedence) caught and prevented semantic drift in the changelog. Current head 2df9aaf27e47bf54743d22ce610f6b8188429049 preserves both contracts.

Predecessor RED and GREEN results are development provenance only.

Current exact state

  • Head: 2df9aaf27e47bf54743d22ce610f6b8188429049.
  • Independently resolved protected main tip: bf2cc2e140dc3ff4a56c3203f80f41bb9fed5d10.
  • GitHub reports Draft and mergeable.
  • CI 31354988532: completed / success.
  • Security Scan 31354988512: completed / success.
  • SAST Semgrep 31354988530: completed / success.
  • Formal reviews and unresolved inline threads must be freshly refetched before promotion/merge; predecessor review evidence does not transfer.

These PR-triggered workflows still precede protected-main exact-source governance PR #88, so successful branch runs remain staged integration evidence until that prerequisite integrates and the final source is revalidated under the protected exact-source contract.

Merge boundary

Keep Draft until #88 reaches protected main; then reconcile only when integration correctness requires it and reacquire every applicable exact-source CI, security, dependency, packaging, provenance, semantic-review, and branch-policy gate. Do not churn a clean source head solely to retrigger an unavailable external reviewer.

Merge only with zero valid unresolved findings, live repository policy/protection satisfied, every required exact-current-head gate terminal-success, current semantic review where required, and qualifying independent non-author formal APPROVED review where required. The protected code-owner gate is separately disabled/on hold for the current solo-maintainer state and must not be inferred as universally mandatory. Failed RED, predecessor-head, stale-base, generated-merge-only, queued, pending, cancelled, skipped-required, absent, neutral-required, rate-limited, status-only, author-only, infrastructure-only, or synthetic-only evidence is not final acceptance.

@coderabbitai

coderabbitai Bot commented Aug 9, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a9a04996-a610-4844-a911-2587c4aff78e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@seonghobae seonghobae changed the title fix(bootstrap): reject explicit empty DSN fallback fix(bootstrap): preserve explicit source precedence Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

Review exact current source head 277cad148bdc00e7478c99c26741d8edef0f03d5 against protected main bf2cc2e140dc3ff4a56c3203f80f41bb9fed5d10. Focus on explicit-vs-omitted bootstrap source precedence for the required PostgreSQL DSN and optional Fernet key, failure before credential/database I/O, ambient-authority isolation, compatibility of non-empty explicit/environment fallback behavior, regression coverage, and the doctoring/rollback contract. Do not reuse predecessor-head, generated-merge-only, queued, pending, skipped, absent, rate-limited, or author-only evidence. This is review-only; keep the PR Draft until its declared #88 integration boundary is satisfied.

@coderabbitai

coderabbitai Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '=== checked-out and requested commits ==='
git rev-parse HEAD
git cat-file -t 277cad148bdc00e7478c99c26741d8edef0f03d5
git cat-file -t bf2cc2e140dc3ff4a56c3203f80f41bb9fed5d10
git merge-base --is-ancestor bf2cc2e140dc3ff4a56c3203f80f41bb9fed5d10 277cad148bdc00e7478c99c26741d8edef0f03d5 && echo 'base is ancestor of head'

echo '=== exact source diff summary ==='
git diff --stat bf2cc2e140dc3ff4a56c3203f80f41bb9fed5d10 277cad148bdc00e7478c99c26741d8edef0f03d5
git diff --name-status bf2cc2e140dc3ff4a56c3203f80f41bb9fed5d10 277cad148bdc00e7478c99c26741d8edef0f03d5

echo '=== resolver definitions and focused call sites ==='
rg -n -C 5 --glob '*.py' '^\s*def resolve_(dsn|secret_key)\s*\(|\bresolve_(dsn|secret_key)\s*\(' .

echo '=== relevant Python outlines ==='
fd -e py . | xargs -r ast-grep outline --items all --type function --match 'resolve_dsn|resolve_secret_key|SecretStore' --view expanded

echo '=== precedence and regression-test references ==='
rg -n -C 4 --glob '*.py' 'explicit_empty|resolve_dsn|resolve_secret_key|PG_LLM_BATCH_DSN|PG_LLM_BATCH_SECRET_KEY|SecretStore' .

echo '=== relevant documentation ==='
rg -n -C 4 -i 'explicit.*empty|empty.*explicit|source precedence|ambient|Fernet|decryption.authority|rollback|PG_LLM_BATCH_(DSN|SECRET_KEY)' \
  README.md CHANGELOG.md docs 2>/dev/null || true

echo '=== GitHub PR state and exact-head checks ==='
gh pr view 89 --repo ContextualWisdomLab/pg-llm-batch \
  --json number,isDraft,headRefOid,baseRefOid,mergeable,reviewDecision,reviews,statusCheckRollup \
  --jq '{number,isDraft,headRefOid,baseRefOid,mergeable,reviewDecision,reviews:[.reviews[]|{author:.author.login,state}],checks:[.statusCheckRollup[]|{name:.name,status:.status,conclusion:.conclusion,workflowName:.workflowName,headSha:.headSha}]}'

echo '=== PR `#88` state ==='
gh pr view 88 --repo ContextualWisdomLab/pg-llm-batch \
  --json number,state,isDraft,mergedAt,headRefOid,baseRefOid,mergeable \
  --jq '{number,state,isDraft,mergedAt,headRefOid,baseRefOid,mergeable}'

Length of output: 50656


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '=== exact patch ==='
git diff --find-renames --find-copies --unified=80 \
  bf2cc2e140dc3ff4a56c3203f80f41bb9fed5d10 \
  277cad148bdc00e7478c99c26741d8edef0f03d5 \
  -- pg_llm_batch/bootstrap.py tests/test_bootstrap_cli.py \
     tests/test_bootstrap_explicit_dsn_precedence.py \
     docs/doctoring/bootstrap-dsn-precedence.md CHANGELOG.md

echo '=== bootstrap implementation ==='
sed -n '1,110p' pg_llm_batch/bootstrap.py

echo '=== CLI parse, dispatch, and error boundary ==='
sed -n '35,180p' pg_llm_batch/cli.py

echo '=== bootstrap regression tests ==='
sed -n '1,125p' tests/test_bootstrap_cli.py
sed -n '1,180p' tests/test_bootstrap_explicit_dsn_precedence.py

echo '=== SecretStore key initialization and encrypted-read behavior ==='
sed -n '264,390p' pg_llm_batch/config.py

echo '=== environment-variable reads outside bootstrap ==='
rg -n --glob '*.py' -P '\b(?:os\.(?:environ|getenv)|environ\[)' pg_llm_batch tests || true

echo '=== doctoring document ==='
sed -n '1,140p' docs/doctoring/bootstrap-dsn-precedence.md

Length of output: 45539


@seonghobae Source review found no findings in the requested scope.

resolve_dsn("") raises before environment lookup. cli._dispatch() calls resolve_dsn() before database, credential, or client operations.

resolve_secret_key("") preserves the empty string. SecretStore treats that value as no Fernet key. Encrypted records still fail closed during decryption.

The regression coverage verifies explicit-empty behavior, existing non-empty precedence, environment fallback, missing required DSN failure, and missing optional-key behavior. The doctoring and changelog state the precedence, decryption-authority, verification, and rollback contracts.

PR #89 remains Draft. PR #88 is open and unmerged. The current check rollup still contains queued coverage-source-tree and in-progress strix checks. I did not treat those checks as acceptance evidence.

⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

Please review exact current head d0c784239e948b94d405b5cb0be3615fe2456d76 while this dependency-gated PR remains Draft. Focus on explicit-vs-omitted bootstrap source precedence and the whitespace-only DSN fail-closed boundary; predecessor-head evidence is historical.

@coderabbitai

coderabbitai Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

repo="ContextualWisdomLab/pg-llm-batch"
head="d0c784239e948b94d405b5cb0be3615fe2456d76"
base="bf2cc2e140dc3ff4a56c3203f80f41bb9fed5d10"

echo "=== Source identity ==="
git rev-parse HEAD
git cat-file -t "$head"
git cat-file -t "$base"
git merge-base --is-ancestor "$base" "$head" && echo "protected base is an ancestor of requested head"
git diff --name-status "$base" "$head"
git diff --unified=60 "$base" "$head" -- \
  pg_llm_batch/bootstrap.py \
  tests/test_bootstrap_explicit_dsn_precedence.py \
  docs/doctoring/bootstrap-dsn-precedence.md \
  CHANGELOG.md

echo "=== Bootstrap resolver implementation ==="
ast-grep outline pg_llm_batch/bootstrap.py --items all --type function --match 'resolve_dsn|resolve_secret_key' --view expanded
sed -n '1,180p' pg_llm_batch/bootstrap.py

echo "=== Resolver callers and I/O ordering ==="
rg -n -C 5 --glob '*.py' \
  '^\s*def resolve_(dsn|secret_key)\s*\(|\bresolve_(dsn|secret_key)\s*\(|(?:connect|SecretStore|create_engine|psycopg)' \
  pg_llm_batch tests

echo "=== Regression coverage ==="
ast-grep outline tests/test_bootstrap_explicit_dsn_precedence.py --items all --type function --view expanded
sed -n '1,260p' tests/test_bootstrap_explicit_dsn_precedence.py

echo "=== Doctoring and release contract ==="
sed -n '1,240p' docs/doctoring/bootstrap-dsn-precedence.md
rg -n -C 3 'bootstrap|DSN|secret|whitespace|precedence' CHANGELOG.md

echo "=== Live pull request and dependency state ==="
gh pr view 89 --repo "$repo" \
  --json number,isDraft,headRefOid,baseRefOid,mergeable,reviewDecision,statusCheckRollup \
  --jq '{number,isDraft,headRefOid,baseRefOid,mergeable,reviewDecision,checks:[.statusCheckRollup[]|{name,status,conclusion,headSha,workflowName}]}'
gh pr view 88 --repo "$repo" \
  --json number,state,isDraft,mergedAt,headRefOid,baseRefOid,mergeable \
  --jq '{number,state,isDraft,mergedAt,headRefOid,baseRefOid,mergeable}'

Length of output: 137650


@seonghobae Source review found no findings in the requested scope.

The checked-out source is exactly d0c784239e948b94d405b5cb0be3615fe2456d76. Protected main commit bf2cc2e140dc3ff4a56c3203f80f41bb9fed5d10 is its ancestor.

resolve_dsn() reads PG_LLM_BATCH_DSN only when explicit is None. It rejects explicit and environment DSNs that are empty or whitespace-only before any libpq access. It returns valid DSNs unchanged.

resolve_secret_key() preserves an explicit empty key. It reads PG_LLM_BATCH_SECRET_KEY only when the argument is omitted.

cli._dispatch() resolves the DSN before command-specific database or credential-store operations. The regression tests cover explicit empty and whitespace-only DSNs, whitespace-only environment DSNs, non-empty precedence, environment fallback, missing DSN behavior, and explicit empty secret-key behavior. The doctoring and changelog describe the boundary and rollback effect.

PR #89 remains Draft at the reviewed head. PR #88 remains open and unmerged. Keep this PR Draft until that integration boundary is satisfied. The completed checks are not final merge acceptance until the protected-main exact-source process runs after that boundary.

⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown
Contributor Author

Superseded by protected-main replacement PR #139. The replacement was rebuilt from the then-current protected main, preserved the intended omission-vs-explicit authority boundary, strengthened the string check to exact str (type(value) is str), retained explicit empty Fernet-key semantics, added current-base regressions/doctoring, and passed the full exact-head repository and central required workflow set before squash merge at cd7f72414ea47ba3e4ebf7976dfe3c02680e4ffc. This stale branch is therefore closed without merging; its historical checks/reviews do not transfer.

@seonghobae seonghobae closed this Aug 12, 2026
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