Skip to content

fix(postgres): refuse a pull that cannot succeed instead of asking for a retry - #2622

Merged
aparajon merged 3 commits into
mainfrom
armand/pull-refusals-are-not-retries
Dec 4, 2026
Merged

aparajon merged 3 commits into
mainfrom
armand/pull-refusals-are-not-retries

Conversation

@aparajon

@aparajon aparajon commented Dec 4, 2026 •

Copy link
Copy Markdown
Collaborator

Why

Three PostgreSQL pulls can never succeed, yet each answers 500 with "SchemaBot hit an internal error while reading the live schema. Retry in a moment". The real cause is only in the server log.

  • A namespace that does not exist.
  • catalog_detail: detailed, which PostgreSQL does not support.
  • A namespace holding a table schema files cannot describe, such as an UNLOGGED or inherited table, without skip_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 --lint flags 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

  • Each of the three pulls answers 400 invalid_request with what to change, as other pull refusals already do.
    • An unknown namespace names the schemas the pull can read. On a target with a schema override, it names the namespace the override maps instead, and a mapped schema that does not exist says to create it or correct the override.
    • On such a target, every refusal names namespaces as the caller knows them. The physical schema stays in the server log.
    • detailed says PostgreSQL pulls support only basic, the default.
    • The unrepresentable-table refusal names each table with its reason (up to 10) and the skip_unrepresentable_tables flag that returns every other table.
  • The primary_key lint no longer judges a partitioned table's partition key columns. Its other key columns are still judged.
  • docs/schema-intelligence.md lists the three refusals in the pull's 400 section, and docs/ai-agents.md says structured columns are MySQL only.

Before and after

POST /api/pull for namespace public, which holds the UNLOGGED table audit_log, with no skip_unrepresentable_tables.

Before                                    After

┌─────────────────────────────────┐       ┌─────────────────────────────────┐
│ engine: audit_log is unlogged   │       │ engine: audit_log is unlogged   │
└────────────────┬────────────────┘       └────────────────┬────────────────┘
                 │ plain error                             │ refusal
                 ▼                                         ▼
┌─────────────────────────────────┐       ┌─────────────────────────────────┐
│ 500 "Retry in a moment"         │ ✗     │ 400 invalid_request: names      │
│ every retry gets the same 500   │       │ audit_log and the skip flag     │
└─────────────────────────────────┘       └─────────────────────────────────┘
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
pull schema failed: schema "nosuch" does not exist. Pull one of app, billing, public, or pull without a namespace to get every schema
pull schema failed: PostgreSQL pulls support only basic catalog detail. Pull again with basic catalog detail, which is the default

Before, both read as the 500 above.

How

The engine returns each one as a PlanRefusedError carrying a message SchemaBot wrote. The pull handler already answers that with 400 and the message alone, locally and from a remote data plane, which sends it as FailedPrecondition. 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 a 500.

Risk

Only these three PostgreSQL pull failures change, from 500 to 400. Pulls that succeed, MySQL and Vitess pulls, and every other error are unchanged.

  • UX-4: upholds. Each refusal names the next step, where it was a dead-end retry.

Upgrade notes

None.

🤖 Generated with Claude Code

…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.
Copilot AI balanced review requested due to automatic review settings December 4, 2026 21:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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_request for 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

Comment thread pkg/engine/postgres/pull.go Resolved
Comment thread pkg/engine/postgres/pull.go Resolved
- 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.
@aparajon
aparajon marked this pull request as ready for review December 4, 2026 21:38
@JashLal

JashLal commented Dec 4, 2026

Copy link
Copy Markdown
Collaborator

🤖 I reviewed the full diff at 9bcb8ebc9.

Please handle unknown canonical namespaces on targets with schema overrides. In pullSchemaFromEngine, an explicit namespace that is absent from SchemaOverrides exits at physicalNamespace(canonical), before the MissingNamespaceError branch. On a target mapping only app, requesting appp still reaches the caller as a generic error with retry guidance. The new override test exercises app mapped to a missing physical schema, so it misses the typo case. Return a typed refusal at the override lookup with the allowed canonical namespace and test the resulting 400 invalid_request through the pull handler.

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.
@aparajon

aparajon commented Dec 4, 2026

Copy link
Copy Markdown
Collaborator Author

🤖 Thanks, all three points are fixed in ee8f9ac.

  • Unknown canonical namespace: pullSchemaFromEngine now returns a typed refusal when the override lookup fails, for the namespace and for each import namespace. On a target mapping only app, a pull of appp answers 400 invalid_request with pull schema failed: namespace "appp" is not one this target serves. Pull "app" instead. TestPullSchemaHandlerRefusesANamespaceTheSchemaOverridesDoNotMap drives this through the pull handler with a real LocalClient, and TestPostgresPullRefusesANamespaceTheOverrideDoesNotMap checks that nothing is read from the target.
  • Physical name in the mapped-schema refusal: the answer now names only the canonical namespace and says the server log names the schema. The physical name stays in the existing operator log.
  • Unrepresentable-table refusal: the engine returns the refused tables as a typed engine.UnrepresentableTablesError, and the client renders them through the override's canonical name, so svc.audit_log is named rather than the physical schema. TestPostgresPullNamesUnrepresentableTablesInTheCanonicalNamespace covers it. Without overrides, the engine's message is unchanged.

— Claude Code (Claude Opus 5.5)

@aparajon
aparajon added this pull request to the merge queue Dec 4, 2026
Merged via the queue into main with commit 4d40dd6 Dec 4, 2026
49 checks passed
@aparajon
aparajon deleted the armand/pull-refusals-are-not-retries branch December 4, 2026 22:58
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.

3 participants