Skip to content

refactor(storage): make raw query policy reviewable - #2198

Merged
Jurij89 merged 14 commits into
integration/2052-system-record-syncfrom
refactor/2192-reviewable-raw-query-policy
Aug 9, 2026
Merged

refactor(storage): make raw query policy reviewable#2198
Jurij89 merged 14 commits into
integration/2052-system-record-syncfrom
refactor/2192-reviewable-raw-query-policy

Conversation

@Jurij89

@Jurij89 Jurij89 commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Replace opaque package-level dynamic-query fingerprints with a sorted, multiline v2 inventory of 287 package/path/symbol records containing normalized source expressions and SHA-256 values, so review diffs expose exactly what is approved.
  • Compare inventory entries through one validated fixed-order semantic key, preserve duplicate occurrence handling, refuse inventory rewrites when the underlying scan has violations, and prove deterministic write/read/write output.
  • Move the optional MSSQL Request.query() exception out of production code and into an exact occurrence-counted architecture-gate record; untyped store aliases, updates, and unreviewed dynamic calls remain fail-closed.
  • Centralize SPARQL lexical ownership in Core: prefix names, variables, literals, comments, IRI references, standalone words, token iteration, operation admission, and Query traversal now share one lexical model.

Related

Diagrams

Dynamic raw-query review

Before:

sequenceDiagram
    participant Source as First-party source
    participant Gate as Architecture gate
    participant Baseline as Package fingerprint
    Source->>Gate: Dynamic TripleStore.query expression
    Gate->>Baseline: Compare opaque package hash
    Baseline-->>Gate: Match or package-wide mismatch
Loading

After:

sequenceDiagram
    participant Source as First-party source
    participant Gate as Architecture gate
    participant Baseline as Reviewed inventory
    Source->>Gate: Dynamic TripleStore.query expression
    Gate->>Gate: Reject raw updates and unreviewed exceptions
    Gate->>Baseline: Compare stable semantic record
    Baseline-->>Gate: Exact match or reviewable multiline diff
Loading

SPARQL admission and traversal

Before:

sequenceDiagram
    participant Caller
    participant Core
    participant Query
    Caller->>Core: SPARQL admission
    Core->>Core: Core-owned word boundary heuristics
    Caller->>Query: Structural traversal
    Query->>Query: Query-owned prefix and token grammar
Loading

After:

sequenceDiagram
    participant Caller
    participant Core
    participant Query
    Caller->>Core: SPARQL admission
    Core->>Core: Consume canonical Core lexer
    Caller->>Query: Structural traversal
    Query->>Core: Consume canonical Core lexer
Loading

Files changed

File What
scripts/check-managed-store-raw-channels.mjs Validate semantic inventory keys, own exact non-store exceptions, emit multiline records, refuse failed-scan writes, and self-test deterministic round trips.
scripts/managed-store-dynamic-query-inventory.json Store the sorted 287-call v2 baseline in a human-reviewable multiline format.
.github/workflows/system-record-managed-ownership.yml Trigger the architecture gate for inventory-only changes.
packages/core/src/sparql-lexer.ts Own the canonical lexical grammar, opaque-region handling, typed token reader, and cursor-owning iterator.
packages/core/src/sparql-operation.ts Derive operation and mutation recognition from the Core lexer.
packages/query/src/sparql-utils.ts Preserve Query's helper API as thin Core re-exports rather than a second lexical implementation.
packages/query/src/dkg-query-engine.ts Consume canonical tokens for dataset, graph, variable, nested-select, brace, VALUES, and dedup-safety scans.
packages/query/src/sparql-graph-scope.ts Consume canonical tokens for prefix and top-level graph-value scans.
packages/query/src/sparql-guard.ts Derive read-only query admission from Core's recognized-read policy and fail closed on ambiguous programs.
packages/agent/src/generic-sql-source.ts Remove the scanner-specific suppression marker from production code.

Test plan

  • Build Core and run packages/core/test/sparql-operation.test.ts (3/3), including dotted-prefix and triple-separator boundaries.
  • Run the complete Core baseline suite after lexer extraction (1,695/1,695).
  • Build Query and run focused lexer/admission suites (22/22).
  • Run the complete Query suite after Core lexer consolidation (343/343).
  • Build Storage and run the managed-mutation admission regression suite on the current head (13/13); the broader raw-channel suite passed earlier in this PR (79/79).
  • Run pnpm check:managed-store-raw-channels; all 287 records match, duplicate MSSQL exceptions are rejected, and failed scans cannot rewrite the baseline.
  • Regenerate the inventory and prove semantic equivalence plus byte-identical deterministic round-trip output.
  • Run git diff --check.

Comment thread scripts/check-managed-store-raw-channels.mjs
Comment thread scripts/check-managed-store-raw-channels.mjs
Comment thread packages/core/src/sparql-operation.ts Outdated
Comment thread packages/core/src/sparql-operation.ts Outdated
Comment thread packages/query/src/dkg-query-engine.ts Outdated
Comment thread scripts/check-managed-store-raw-channels.mjs Outdated
Comment thread packages/core/test/sparql-operation.test.ts
Comment thread scripts/managed-store-dynamic-query-inventory.json Outdated
Comment thread packages/query/src/dkg-query-engine.ts Outdated
Comment thread packages/query/src/sparql-utils.ts Outdated
@Jurij89
Jurij89 force-pushed the refactor/2192-reviewable-raw-query-policy branch from d178509 to e5a8502 Compare August 9, 2026 15:52
@Jurij89

Jurij89 commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

@otReviewAgent Please review current rebased head e5a8502 for convergence. It is based on converged #2187, fixes the prefixed-name default-graph guard bypass, and passes the complete Query suite (339/339).

Comment thread packages/query/src/sparql-utils.ts Outdated
@Jurij89

Jurij89 commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

Review Agent: please run a fresh merge-readiness review against current head 0c028738d8. The scanner-contract finding is addressed with explicit prefixed-name/variable tokens, structural char fallback, updated consumers, and a focused contract regression; the full Query suite passes 340/340.

@Jurij89

Jurij89 commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

@otReviewAgent Please review current head 0c028738d8 for convergence. The scanner-contract finding is addressed with explicit semantic token kinds, updated consumers, and the 340/340 Query suite.

@Jurij89

Jurij89 commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

@otReviewAgent Please review the current head after the empty retrigger commit; the scanner-contract remediation remains unchanged and prior threads are resolved.

@Jurij89

Jurij89 commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

Carry-forward from #2207 review before integration: consolidate validateReadOnlySparql() onto the same Core recognized-read admission helper used by leased-store enforcement, preserving current reason messages/tests. This is required before #2193 is closed.

@Jurij89
Jurij89 force-pushed the refactor/2192-reviewable-raw-query-policy branch from 6f059aa to 95f98de Compare August 9, 2026 18:26
@Jurij89
Jurij89 changed the base branch from fix/2162-close-leased-raw-mutations to integration/2052-system-record-sync August 9, 2026 18:27
Comment thread packages/query/src/sparql-utils.ts Outdated
Comment thread packages/query/src/dkg-query-engine.ts Outdated
@Jurij89

Jurij89 commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

@otReviewAgent Please review current integration-based head c4ef88f62 for convergence. The carried-forward policy finding is addressed: validateReadOnlySparql() now derives admission from Core recognizedReadOnlySparqlForm(), ambiguous read-plus-update programs fail closed, and the full Query suite passes 340/340. Storage raw-channel admission passes 79/79 after ordered dependency builds; the managed raw-channel inventory passes all 287 reviewed call sites.

@Jurij89

Jurij89 commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

@otReviewAgent Please review current head 4706b8be8 for convergence. The adjacent-comment blocker and unused import are addressed and their threads resolved. PN_LOCAL parsing now terminates on raw comment/structural boundaries while preserving legal escapes; scoped-query and scanner regressions pass. Full Query 342/342, Storage admission 79/79, raw-channel inventory 287/287.

Comment thread scripts/check-managed-store-raw-channels.mjs
@Jurij89

Jurij89 commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

@otReviewAgent Please review current head 4319713d4 for convergence. The duplicate non-store exception blocker is addressed with occurrence-counted identity shared by scanning and self-test; only the first explicit MSSQL call is reviewed and an identical second call becomes an untyped raw-channel violation. The thread is resolved and the architecture gate passes all 287 reviewed query sites.

Comment thread packages/core/src/sparql-operation.ts
Comment thread packages/core/src/sparql-lexer.ts
@Jurij89
Jurij89 merged commit c49cb31 into integration/2052-system-record-sync Aug 9, 2026
6 checks passed
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.

2 participants