Repository navigation
fix(postgres): refuse a pull that cannot succeed instead of asking for a retry - #2622
Conversation
…r a retry - A PostgreSQL pull of a namespace that does not exist, a pull asking for detailed catalog detail, and a pull of a namespace holding a table a schema file cannot describe without skip_unrepresentable_tables are now refusals. Each answers 400 invalid_request with what to change, instead of a 500 that says to retry: the existing schemas, basic catalog detail, or each table and the flag that returns the rest. - The primary_key lint leaves a partitioned table's partition key columns alone, since PostgreSQL requires them in the key. - Document the three refusals and that structured columns are MySQL only.
There was a problem hiding this comment.
🟡 Changes recommended
Active issues misclassify renderer/parser failures as client errors with unauthored guidance and offer schema suggestions that cannot resolve requests under configured overrides.
2 open issues
What changed in this PR
This PR makes PostgreSQL pull refusals actionable in SchemaBot instead of recommending retries that cannot help, supporting UX-4’s requirement to name the next action.
Changes:
- Return
400 invalid_requestfor unsupported catalog detail, missing namespaces, and unrepresentable tables. - Exempt partition key columns from primary-key type linting while retaining checks on other columns.
- Add refusal coverage and clarify PostgreSQL limitations in the documentation.
For a pull containing the unlogged table public.audit_log:
Before: unrepresentable table -> 500 -> retry repeats the failure
After: unrepresentable table -> 400 -> names the table and skip flag
Before: pull response
{
"error": "pull schema failed for database \"shop\" in environment \"production\": SchemaBot hit an internal error while reading the live schema. Retry in a moment. If it keeps failing, a SchemaBot operator can find the cause in the server log."
}After: pull response
{
"error": "pull schema failed: 1 table cannot be described by a schema file, so the pull returns nothing rather than part of the database: public.audit_log (unlogged tables cannot be rendered as a desired schema). Pull again with skip_unrepresentable_tables to get every other table, with these listed in skipped_tables",
"error_code": "invalid_request"
}Upgrade notes: None.
| File | Description |
|---|---|
pkg/lint/postgres.go |
Exempts partition key columns from type warnings. |
pkg/lint/postgres_test.go |
Covers partitioned-table key linting. |
pkg/engine/postgres/pull.go |
Classifies pull refusals and adds corrective guidance. |
pkg/engine/postgres/pull_refusal_integration_test.go |
Covers unrepresentable tables and missing namespaces. |
pkg/engine/postgres/postgres_test.go |
Checks reserved-schema and catalog-detail refusal messages. |
docs/schema-intelligence.md |
Documents PostgreSQL pull refusals and catalog limits. |
docs/ai-agents.md |
Clarifies that structured catalog details are MySQL-only. |
Review effort: Balanced
- A pull is refused as an incomplete baseline only when every table it stops on owes that to its shape. A render that stops for another reason, such as a catalog it could not read, stays an internal failure, since skipping unrepresentable tables would not help and pulling again may. - A pull whose namespace maps through a schema override to a schema that does not exist on the target now says so, and says to create that schema or correct the override. The engine's own suggestions name physical schemas and a pull without a namespace, which this target cannot use.
|
🤖 I reviewed the full diff at Please handle unknown canonical namespaces on targets with schema overrides. In The new mapped-schema refusal also puts the physical schema name in the client-facing error. Keep the canonical namespace in that response and the physical name in the existing operator log. Check the same boundary for the unrepresentable-table refusal, which formats the namespace read by the engine. The diff preserves unexpected renderer errors as internal failures and keeps lint active for the remaining primary-key columns. The current head reports successful build, unit, and engine integration checks. This was a local static review; I could not retrieve a Builderbot result for this head. I did not run tests locally. |
- A PostgreSQL pull of a namespace the target's schema override does not map, such as a typo, is refused as a request to correct, naming the namespace the target serves, instead of failing as an internal error to retry. The same holds for an import namespace. - The refusal of a mapped schema that does not exist names the namespace the caller asked for and leaves the physical schema to the server log. - The unrepresentable-table refusal names each table in the namespace the caller asked for. The engine returns the tables as a typed error, so a client that maps namespaces renders them in its own names.
|
🤖 Thanks, all three points are fixed in ee8f9ac.
— Claude Code (Claude Opus 5.5) |

Why
Three PostgreSQL pulls can never succeed, yet each answers
500with "SchemaBot hit an internal error while reading the live schema. Retry in a moment". The real cause is only in the server log.namespacethat does not exist.catalog_detail: detailed, which PostgreSQL does not support.UNLOGGEDor inherited table, withoutskip_unrepresentable_tables.A script or agent that follows the docs retries these forever. The CLI shows the same 500 for the first two.
Separately,
pull --lintflags the partition key column in a partitioned table's primary key as the wrong key type, although PostgreSQL requires that column in the key.What
400invalid_requestwith what to change, as other pull refusals already do.detailedsays PostgreSQL pulls support onlybasic, the default.skip_unrepresentable_tablesflag that returns every other table.primary_keylint no longer judges a partitioned table's partition key columns. Its other key columns are still judged.docs/schema-intelligence.mdlists the three refusals in the pull's400section, anddocs/ai-agents.mdsays structured columns are MySQL only.Before and after
POST /api/pullfor namespacepublic, which holds theUNLOGGEDtableaudit_log, with noskip_unrepresentable_tables.Unrepresentable table: before
{ "error": "pull schema failed for database \"shop\" in environment \"production\": SchemaBot hit an internal error while reading the live schema. Retry in a moment. If it keeps failing, a SchemaBot operator can find the cause in the server log." }Unrepresentable table: after
{ "error": "pull schema failed: 1 table cannot be described by a schema file, so the pull returns nothing rather than part of the database: public.audit_log (unlogged tables cannot be rendered as a desired schema). Pull again with skip_unrepresentable_tables to get every other table, with these listed in skipped_tables", "error_code": "invalid_request" }Unknown namespace and detailed catalog: after
Before, both read as the 500 above.
How
The engine returns each one as a
PlanRefusedErrorcarrying a message SchemaBot wrote. The pull handler already answers that with400and the message alone, locally and from a remote data plane, which sends it asFailedPrecondition. The engine's own error, with any host detail, stays in the server log. An incomplete baseline is a refusal only when every left-out table is one a schema file cannot describe; any other error is still a500.Risk
Only these three PostgreSQL pull failures change, from
500to400. Pulls that succeed, MySQL and Vitess pulls, and every other error are unchanged.Upgrade notes
None.
🤖 Generated with Claude Code