Skip to content

docs(wiki): rewrite protocol-parsing.md's SQL section against parse_sql as ADR-0008 leaves it - #282

Merged
amondnet merged 8 commits into
mainfrom
amondnet/issue-261-protocol-parsing-sql
Sep 19, 2026
Merged

amondnet merged 8 commits into
mainfrom
amondnet/issue-261-protocol-parsing-sql

Conversation

@amondnet

@amondnet amondnet commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

What

wiki/deep-dive/protocol-parsing.md's SQL section still described the leading-token heuristic that ADR-0008 replaced with sqlparser, and one claim was refuted by the test it cited: the page said DROP MATERIALIZED VIEW mv must yield mv, "proven by drop_if_exists_extracts_real_table", while that test asserts the table is empty because a view is not a table.

Changes

  • SQL section rewritten from the code, not from the old table with corrections applied. It states what parse_sql does: parse with sqlparser's PostgreSQL dialect (with ADR-0008's caveat that the dialect is not the server's grammar), classify by what the statement executes (EXPLAIN ANALYZE, data-modifying CTEs), report the most dangerous verb per VERB_PRECEDENCE, and fill sql.table with one relation or nothing. The empty-table cases are stated as the rule (sole_relation, more_dangerous): several targets, a cascade, any same-rank tie, a read over several relations. The two limits the precedence choice leaves are named rather than papered over: writes of different rank are not a tie, and an upsert reported as UPDATE passes a deny-INSERT/allow-UPDATE policy (postgres facts: carry every verb and relation a statement executes (sql.verbs / sql.tables) #104). Every row of the new table cites the test that proves it, with the statement that test asserts.
  • The clean_identifier sentence is unchanged, moved verbatim into the fallback paragraph it describes; the parsed path's relation_name gets its own sentence.
  • Test coverage table: the three rows the docs(wiki): protocol-parsing.md's SQL section predates sqlparser, and one claim is refuted by the test it cites #261 thread found a thousand lines stale are repointed, the schema-qualified parses_postgres_truncate_and_select row that thread asked for is added, and the "9 unit tests" count in the intro is dropped (the module holds 46 now).
  • Two other anchors on the page that name the same items are repointed so the page does not carry two different ranges for one thing: the At-a-glance parse_sql row (41-93, now inside parse_postgres_query, to 72-99) and the framing paragraph's rejects_malformed_query_frames (219-237 to 1061-1079, matching the coverage table). The page's remaining stale anchors are in the PostgreSQL framing and Kubernetes sections and are filed as docs(wiki): protocol-parsing.md's PostgreSQL framing and Kubernetes anchors predate the sqlparser growth of protocols.rs #284, not widened into this diff.
  • Anchor ledger: the #261 TRACKED entry in scripts/check-wiki-source-anchors.ts is removed, since the page no longer produces that finding, and the comment above the ledger says so.
  • wiki/llms-full.txt regenerated.

Verification

Both wiki checks go red on the old state and green with the fix:

  • check-wiki-source-anchors.ts with the old ledger entry against the fixed page: TRACKED names protocols.rs#L248-L254 (blank, #261) … which produces no such finding any more.
  • check-wiki-bundle-current.ts with the old bundle against the new page: its wiki/deep-dive/protocol-parsing.md section is not that page's current content.

At the final head: 1150 citations resolve, bundle byte-identical to 14 pages, bun run lint && bun run typecheck && bun test green (533 pass), grep -n '^#[0-9]' on the page prints nothing.

Not changed: anything under crates/. The code is right and the page was wrong.

Closes #261

…ql as ADR-0008 leaves it

The section still described the leading-token heuristic ADR-0008 replaced,
and its `DROP MATERIALIZED VIEW mv` claim cited a test that asserts the
opposite: `drop_if_exists_extracts_real_table` proves the table is empty,
because a view is not a table.

Write the section from the code instead: `parse_sql` classifies by what a
statement executes (`EXPLAIN ANALYZE`, data-modifying CTEs), reports the most
dangerous verb per `VERB_PRECEDENCE`, and fills `sql.table` with one relation
or nothing — a multi-target or cascading statement deliberately names none,
so only a table-blind rule can decide it. Every row of the new table cites
the test that proves it. The `clean_identifier` sentence is kept verbatim,
now placed in the fallback paragraph it describes.

Repoint the three Test coverage rows the #261 thread found a thousand lines
stale, add the schema-qualified row that thread asked for, and drop the
unit-test count the table's intro had stopped matching.

Drop the #261 entry from the anchor ledger, since the page no longer produces
that finding, and regenerate llms-full.txt.

Refs #261
…it names

protocols.rs:41-93 now opens inside parse_postgres_query; parse_sql is at
72-99, where the rewritten SQL section already cites it.

Refs #261

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request updates the documentation in wiki/deep-dive/protocol-parsing.md and wiki/llms-full.txt to describe the transition of parse_sql from a basic heuristic to using PostgreSQL's grammar via sqlparser's PostgreSqlDialect. It also updates the associated test coverage details and removes a tracked anchor in scripts/check-wiki-source-anchors.ts. The review feedback correctly identifies a documentation citation issue where the cited line range for parse_sql_heuristic does not start at its doc comment, which violates the repository's documentation conventions.

Comment thread wiki/deep-dive/protocol-parsing.md Outdated
@greptile-apps

greptile-apps Bot commented Sep 19, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

The documentation-only PR appears safe to merge, with no actionable discrepancies found in the revised SQL behavior or source anchors.

Summary

Rewrites the SQL protocol-parsing documentation to reflect the current sqlparser-based implementation and regenerates the bundled wiki.

Reviews (4) · Last reviewed commit: "docs(wiki): precedence names a deny targ..."

The comment above the ledger still listed #261 as a live reason for an
entry the array no longer holds.

Refs #261

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 16e294148b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread wiki/deep-dive/protocol-parsing.md Outdated
Comment thread wiki/deep-dive/protocol-parsing.md Outdated
greptile-apps[bot]
greptile-apps Bot previously approved these changes Sep 19, 2026
@greptile-apps
greptile-apps Bot dismissed their stale review September 19, 2026 02:27

Dismissed because a newer commit was pushed; Greptile will re-review the current head.

@codspeed

codspeed Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 18 untouched benchmarks


Comparing amondnet/issue-261-protocol-parsing-sql (47164d5) with main (0c350c2)

Open in CodSpeed

- state that the parser is sqlparser's PostgreSQL dialect, not the server's
  grammar, as ADR-0008's consequences already say
- narrow the sql.table rule: writes of different rank are not a tie, the
  higher-ranked verb keeps its table and the lower write is visible to no
  rule (#104)
- start the parse_sql_heuristic citation on its doc comment

Refs #261
greptile-apps[bot]
greptile-apps Bot previously approved these changes Sep 19, 2026
@greptile-apps
greptile-apps Bot dismissed their stale review September 19, 2026 02:28

Dismissed because a newer commit was pushed; Greptile will re-review the current head.

@amondnet

Copy link
Copy Markdown
Contributor Author

/gemini review

greptile-apps[bot]
greptile-apps Bot previously approved these changes Sep 19, 2026
…ames

more_dangerous blanks the table on every tied write without comparing
targets; the page had narrowed that to different relations.

Refs #261
@greptile-apps
greptile-apps Bot dismissed their stale review September 19, 2026 02:32

Dismissed because a newer commit was pushed; Greptile will re-review the current head.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 682c6f4f4a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread wiki/deep-dive/protocol-parsing.md Outdated

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request updates the documentation in wiki/deep-dive/protocol-parsing.md and wiki/llms-full.txt, along with the anchor-checking script in scripts/check-wiki-source-anchors.ts, to align with the new SQL parsing behavior introduced by ADR-0008. The documentation now details how parse_sql uses sqlparser's PostgreSQL dialect to classify statements based on execution rather than leading tokens, outlines verb precedence and table extraction rules, and updates the corresponding test coverage references. There are no review comments to evaluate, and I have no additional feedback to provide.

…with the first

The framing paragraph cited the test at 219-237 while the coverage table,
repointed in this PR, cites it at 1061-1079.

Refs #261
The first matching rule decides, allow included, so an upsert reported as
UPDATE passes a deny-INSERT/allow-UPDATE policy. State that limit (ADR-0008,
#104) instead of a deny-only safety claim.

Refs #261
@sonarqubecloud

Copy link
Copy Markdown

@amondnet
amondnet merged commit 57cc747 into main Sep 19, 2026
13 checks passed
@amondnet
amondnet deleted the amondnet/issue-261-protocol-parsing-sql branch September 19, 2026 02:38
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.

docs(wiki): protocol-parsing.md's SQL section predates sqlparser, and one claim is refuted by the test it cites

1 participant