Skip to content

feat(mcp-server-supabase): record a sql_classifier_call fact for each classifier call - #585

Open
barryroodt wants to merge 2 commits into
feat/run-notebook-classify-stepfrom
feat/sql-classifier-call-fact
Open

barryroodt wants to merge 2 commits into
feat/run-notebook-classify-stepfrom
feat/sql-classifier-call-fact

Conversation

@barryroodt

@barryroodt barryroodt commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Final PR in the stack replacing #454. Based on #584.

Why this changes

If the SQL confirmation classifier times out, the host sees a generic tool_error. It can’t tell from that outcome whether classification failed or the database operation failed. This PR adds a sql_classifier_call observation so the host can see what the classifier reported and how long it took.

What the host sees

Each time a classifier call finishes, the server records the feature (destructive_sql or notebook), the result, and the duration in milliseconds. The result comes from a fixed list, so observations can distinguish a timeout from a crash without including SQL or error text.

For example, if execute_sql stops because the classifier timed out, the host still sees tool_error. It now also sees sql_classifier_call with result: timeout. Both come from the same classifier outcome.

  • Notebooks: Each cell the confirmation classifier checks produces one observation, up to 50 per notebook call. The separate check that chooses a cell’s run mode produces none.
  • Skipped or pending calls: Answering a matching prompt skips classification, so it produces no classifier observation. A call that never finishes also produces none.
  • Fallbacks: When the primary classifier is unavailable and the fallback answers, the observation records the fallback’s result. The host can’t detect the primary outage from that observation alone.

Rollout

This completes the stack for release. Hosts that handle every ObservationFact kind in an exhaustive switch must add a sql_classifier_call case when they upgrade.

Before Platform enables a custom classifier, it still needs to decide how to alert on failures and sample traces, how to count cancellations during classification, and when to time out a call that never finishes.

Refs AI-1338

…fact

Tests for one payload-free `sql_classifier_call` fact per classifier call,
in execute_sql, apply_migration and run_notebook. They fail on this commit
by design: nothing records the fact yet.

- A shared table maps each classifier outcome to the fact's `result`, and
  the SQL tools and run_notebook run it on each path that classifies,
  including the state-error path and the notebook's resend paths.
- A result that throws when read records `invalid`, bare and through
  withFallback.
- A result whose failure kind changes while it is read records one fact
  with a fixed `result`, and the fact and the client's error describe the
  same outcome.
- Requests cancelled while the classifier runs record `aborted`, run
  nothing and end as tool_error.
- `durationMs` is pinned with a controlled clock.
- Existing exact fact lists on paths that classify gain the new fact. Lists
  on paths that never ask the classifier are unchanged, so they still prove
  no fact is recorded there.
- The packed consumer fixture expects the fact on its destructive SQL call,
  and its type check holds a sample for each feature.
… classifier call

The classify step now records one payload-free fact when the classifier call
settles: what it decided, how long it took, or how it failed. Before this, a
call that failed in the classifier left no fact that said so.

execute_sql and apply_migration record it under destructive_sql, run_notebook
under notebook. An aborted request records aborted, whatever the classifier
resolved or threw. A result outside the contract records invalid, also when
reading it throws.

The step derives the outcome once, from one checked read of the result, and
maps both the fact and the reason or error from it, so the two always agree.
Its return value and thrown errors are unchanged.

The step's observation argument is required, so a new caller cannot leave the
fact out by accident.

This branch has not been deployed

No deployments
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