Skip to content

Fix strict-result defects and harden CLI output and the CLI broker - #144

Merged
ivanvyd merged 5 commits into
mainfrom
fix/review-batch-20261128
Nov 28, 2026
Merged

ivanvyd merged 5 commits into
mainfrom
fix/review-batch-20261128

Conversation

@ivanvyd

@ivanvyd ivanvyd commented Nov 28, 2026 •

Copy link
Copy Markdown
Owner

What this changes

Strict results (GenieClientOptions.StrictResults, added in 0.5.0)

  • Only the identity fields strict mode validates (space_id, conversation_id, message_id, id, attachment_id, statement_id) must be non-empty strings. Other *_id fields, such as Genie's numeric user_id, are accepted. Duplicate property names are still rejected everywhere.
  • HTTP failures are classified by status code without reading the error body.
  • Chunk indices must be consecutive. An advertised trailing chunk is fetched even when the row budget is exactly used. Explicit zero-row results without data_array are accepted. A query attachment without an id is reported as incomplete, as ADR 0010 already said.
  • Both chunk walkers share one next-chunk link resolver. Legacy results now also refuse links that carry user info, and detect repeats on the resolved URL.
  • New public GenieErrorCodes constants for STRICT_RESULT_LIMIT and STRICT_RESULT_INCOMPLETE.

Hardening

  • The Databricks CLI broker looks up databricks in absolute PATH directories only, and skips matches without an execute bit on Unix.
  • Raw stdout (CSV, agents list -f csv, export last) has control characters replaced when stdout is a terminal. Redirected output is unchanged.
  • Markdown escapes &, < and | in table cells and the Agent line. Generated SQL is fenced with a backtick run longer than any it contains.

Docs and supply chain

  • RELEASING.md, SECURITY.md and the release.yml comment no longer claim that a signed tag makes a stolen maintainer account insufficient.
  • SECURITY.md says presigned URLs are never fetched, which matches the code.
  • The Dockerfile comment says which restore is locked.
  • The scheduled-report example pins LakeSpeak.Cli 0.5.0.

Structure (second commit, no behaviour change)

  • GenieClient chooses a LegacyGenieTransport or StrictGenieTransport in its constructor. It no longer checks strict mode in about 17 places across send, read, failure mapping, normalization and results.
  • GenieTransport owns the shared HTTP send and failure mapping, the next-chunk resolver and the re-execute polling loop. Each result operation gets its own fetch delegate, so the strict budget is never nullable.
  • GenieResponse.WithQueryAttachments derives Query, Result and the metadata attachment id from the first query attachment. Before, three places kept those copies in step by hand.
  • GenieClient.cs drops from 811 to 448 lines. There is no public API change, and log event ids and messages are unchanged.

Dependencies: this PR includes the Dependabot updates from #141 (dependency-review-action 5.0.1) and #142 (test-only coverlet.collector 10.1.1, WireMock.Net 2.32.0). Both PRs close when this merges.

Why

The problems came from a review of the 0.5.0 changes: maintainability, correctness, deslop and a source-level security audit.

  • Numeric user_id. Strict mode threw MalformedResponse on any numeric *_id. The Databricks SDK types GenieConversation.user_id as an integer, so a strict Ask could submit and bill a question and then fail to return its conversation id.
  • Misclassified HTTP errors. In strict mode, a 401, 403, 404 or 429 with a body larger than MaxBytes, or a body that could not be read, came back as STRICT_RESULT_LIMIT or Network.
  • Planted CLI. .NET's Unix Process.Start looks in the current directory before PATH. See ResolvePath in Process.Unix.cs on release/8.0 and release/10.0. Running a pack from an untrusted checkout could therefore start a databricks file planted in it, and that process would receive the user's OAuth session. On Windows a local probe did not reproduce this: the real CLI ran.
  • Terminal escapes. CSV written to a terminal passed ESC and C1 sequences through, which contradicts SECURITY.md.
  • Markdown injection. A SQL line containing a backtick fence closed the code block and the <details> wrapper.
  • Signed-tag claim. GitHub runs the release workflow and its verifier from the tagged commit, and the same account approves the nuget environment. The signed tag guards against mistakes and lesser access, not against a compromised owner account.

Evidence

  • dotnet build LakeSpeak.slnx -c Release: 0 warnings, 0 errors.
  • dotnet format LakeSpeak.slnx --verify-no-changes: exit 0.
  • dotnet test -c Release --filter-not-trait 'Category=Live': 1186 total, 1184 passed, 0 failed, 2 skipped. The skipped case is the Unix-only execute-bit test on net8 and net10; Linux CI runs it.
  • The baseline before this change was 1118 of 1118, with the Dependabot updates merged.
  • Revert check: I put back the old *_id rule and removed the absolute-path check in the resolver. Three new tests failed: Strict_ask_accepts_numeric_non_identity_ids, Strict_followup_accepts_numeric_non_identity_ids and Relative_and_empty_path_entries_are_never_searched. After restoring both fixes, all 77 targeted tests passed, with 1 skipped as Unix-only.
  • bash .github/scripts/test-release-workflow-policy.sh: passed.
  • Not tested live. No live Genie run used strict mode; the user_id type comes from the Databricks SDK, not from a live response.

Checklist

  • dotnet build -c Release is clean — warnings are errors
  • dotnet format --verify-no-changes is clean
  • dotnet test -c Release --filter "Category!=Live" passes
  • Lock files regenerated with dotnet restore --force-evaluate if dependencies changed (only Dependabot's test-group lock updates; locked restore passes)
  • Tests use Arrange / Act / Assert with explicit section markers
  • An ADR is included if this changes architecture or the public API of LakeSpeak.Genie (ADR 0010 updated for GenieErrorCodes and the strict rules)
  • No comment asserts a guarantee the code does not actually provide

What a reviewer should be sceptical of

  • Legacy chunk walking is a little stricter. It now rejects user-info links and dedupes on the resolved URI, so a walk can stop earlier, flagged as truncated.
  • Windows PATH lookup. It appends .exe only, as CreateProcess did, and no longer searches System32 or the Windows directory. A databricks.cmd shim must be named explicitly.
  • Markdown escaping. Links and images in cells still render. Genie's prose answers are written as returned, apart from control characters.
  • The transport refactor. Its evidence is that the same 1186 tests (1184 passed, 2 skipped) pass with no assertion changed. Two tests only changed where they reference a moved internal constant or method. Metadata and the legacy first-result list are now new objects with equal values.

dependabot Bot and others added 5 commits November 21, 2026 08:03
Bumps the minor-and-patch group with 1 update: [actions/dependency-review-action](https://github.com/actions/dependency-review-action).


Updates `actions/dependency-review-action` from 5.0.0 to 5.0.1
- [Release notes](https://github.com/actions/dependency-review-action/releases)
- [Commits](actions/dependency-review-action@a1d282b...bbc44d1)

---
updated-dependencies:
- dependency-name: actions/dependency-review-action
  dependency-version: 5.0.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: minor-and-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps coverlet.collector from 10.1.0 to 10.1.1
Bumps WireMock.Net from 2.31.0 to 2.32.0

---
updated-dependencies:
- dependency-name: coverlet.collector
  dependency-version: 10.1.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: test
- dependency-name: WireMock.Net
  dependency-version: 2.32.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: test
...

Signed-off-by: dependabot[bot] <support@github.com>
Strict results:
- Validate only the identity fields strict mode checks; numeric user_id
  and other non-identity *_id fields no longer fail real responses.
- Classify strict HTTP failures by status without reading the body.
- Require consecutive chunk indices, fetch an advertised trailing chunk
  when the row budget is exactly used, accept explicit zero-row results,
  and report a query attachment without an id as incomplete.
- Share one next-chunk link resolver between the legacy and strict
  walkers; legacy now also refuses user-info links and dedupes on the
  resolved URL.
- Publish GenieErrorCodes for the strict error codes.

Hardening:
- Resolve the databricks executable from absolute PATH entries only; on
  Linux and macOS .NET otherwise checks the current directory first.
- Sanitize raw stdout (CSV and similar) when it is a terminal.
- Escape &, < and | in Markdown cells and fence SQL past its backticks.

Docs: correct the signed-tag claim, SECURITY.md wording, the Dockerfile
restore comment, and pin the CLI in the scheduled-report example.

Includes the Dependabot updates from #141 and #142.
GenieClient checked whether strict results were enabled in about 17
places, including the shared HTTP send, body reading, failure mapping
and normalization. It now picks a LegacyGenieTransport or a
StrictGenieTransport in its constructor and only orchestrates.

- GenieTransport owns the shared send, the status-to-failure mapping,
  the workspace-bound next-chunk resolver with a typed refusal, and the
  re-execute polling loop. Each result operation gets a fetch delegate,
  so the strict aggregate budget is never nullable.
- Each transport owns its body reading, identity checks, reported
  message error and chunk walker; log event ids are unchanged.
- GenieResponse.WithQueryAttachments derives Query, Result and the
  metadata attachment id from the first query attachment, replacing
  three hand-synced copies.
- Strict body reads take a byte cap; only aggregate result reads draw
  down the shared budget.

GenieClient.cs drops from 811 to 448 lines. No public API change.
@ivanvyd
ivanvyd enabled auto-merge (squash) November 28, 2026 06:16
@ivanvyd
ivanvyd merged commit abc19ab into main Nov 28, 2026
16 checks passed
@ivanvyd
ivanvyd deleted the fix/review-batch-20261128 branch November 28, 2026 06:16
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