Skip to content

feat(sql-server): run queries through tedious with per-call transaction guards - #11520

Closed
melodic-automation-lanes[bot] wants to merge 3 commits into
mainfrom
work-resolve-issue/issue-11327-41194402769-1
Closed

melodic-automation-lanes[bot] wants to merge 3 commits into
mainfrom
work-resolve-issue/issue-11327-41194402769-1

Conversation

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor

Closes #11327

Summary

Opened by the work-resolve-issue lane. The run's own summary:

Adds src/executor.mjs, the database executor behind the query, list_objects and describe_object tools, per ADR 0086 sections 1 and 4. It uses tedious directly with the plugin's own pool: at most two connections, one per allow-listed database, idle ones closed, and the application name 'sql-server-plugin (agent session)'. Each call runs one guard batch (IF TRANCOUNT > 0 ROLLBACK, IMPLICIT_TRANSACTIONS OFF, XACT_ABORT ON, READ COMMITTED, LOCK_TIMEOUT), then the statement in autocommit, then a TRANCOUNT check, and closes the connection when the count is above 0 or after a timeout, cancel, error or capped result. Design choices and their basis: (1) The guard runs through execSqlBatch, not execSql, because Microsoft's SET statements page says a SET made inside sp_executesql is restored when that batch returns. (2) The executor's own timer owns the request timeout (tedious requestTimeout 0) and calls connection.cancel(); the row cap cancels at the first row past rowCap. (3) Connections are opened per database instead of switching with USE, so no SQL is built from a database name. (4) tedious and azure/identity load lazily on the first call, so the unit tests and CI's uninstalled npm test never import them. main.mjs now defaults to this executor in place of the 'no executor' stub. Tests in test/executor.test.mjs drive it through a fake tedious module, with one case for each done-when item.

Not verified

  • The unit tests (npm test in plugins/sql-server, including the new test/executor.test.mjs) were not run: this lane has no node. Left to the PR's CI test-node lane. The review subagent's reading found no failing assertion.
  • No plugins/sql-server/package-lock.json and no Dependabot npm entry for it. docs/contracts/on-demand-dependencies/README.md Rule 1 requires both for a run-time dependency. This lane cannot run npm, and writing a lockfile by hand (tedious plus the azure/identity tree, with integrity hashes) is not r
  • Review finding not fixed: the executor keeps tedious's encrypt true with trustServerCertificate false. A local SQL Server container with a self-signed certificate will fail the TLS check, and config.v1 has no option to change that. That is a config-schema decision outside this issue.
  • Review finding not fixed: the schema sets no maximum for requestTimeoutMs or lockTimeoutMs. A value above 2147483647 makes the Node timer fire at once, or makes SET LOCK_TIMEOUT fail on the server. This needs a schema change.
  • Review finding not fixed: when an earlier result set of list_objects or describe_object hits the row cap, the later sets come back empty. The cancel discards the connection, so the call stops there, and the result is marked truncated: true.
  • Review finding not fixed: close() during a pending connect lets that one call finish before its connection is discarded. main() waits for in-flight calls before close, so it cannot hit this.
  • Done-when 'ci-status is green on the PR head' is a PR check, left to the PR's CI.
  • Tidy skipped: the change is over the tidy cutoffs (about 700 changed lines against a 300 limit, and two areas: plugins/sql-server with .changes/sql-server, plus docs/catalog.md).
  • Done-when git grep -l '"tedious"' -- 'plugins/sql-server/**/package.json' was not run: git grep is not an allowed command here. The working-tree plugins/sql-server/package.json contains "tedious": "20.3.8", which matches once committed.
  • The checkout has untracked files this run did not create: .bash_profile, .bashrc, .gitconfig, .idea, .mcp.json, .profile, .ripgreprc, .vscode, .zprofile, .zshrc. They look like sandbox mount stubs and are left untouched; they are not part of this change.

Fix

  • plugins/sql-server/src/executor.mjs: new. The tedious executor: pool, guard batch, autocommit statement, TRANCOUNT check, discard rule, client-side request timeout, streaming row cap with cancel, sql-login and entra-default auth, named-instance support, and the list_objects and describe_object cat
  • plugins/sql-server/test/executor.test.mjs: new. Unit tests against a fake tedious Connection and Request, one case for each done-when item, plus cases for a broken idle connection, a named instance and both metadata tools
  • plugins/sql-server/src/main.mjs: the default createExecutor is now createTediousExecutor; removed the pendingExecutor stub
  • plugins/sql-server/package.json: dependencies tedious 20.3.8 and azure/identity 4.14.1, exact pins
  • plugins/sql-server/README.md: the control table points at src/executor.mjs; new 'The executor' section on call order, the timeout and cap, the pool, the app name, auth and lazy dependency loading; intro and tests text updated
  • plugins/sql-server/.claude-plugin/plugin.json: the description says the executor ships
  • docs/catalog.md: regenerated catalog line for sql-server to match plugin.json (validate-plugins catalog drift check)
  • .changes/sql-server/feat-11327-sql-server-tedious-executor-3b9d0f52.md: new minor changelog fragment, written by hand because new-changelog-fragment refuses a detached HEAD

Verification

The runner ran each check from the base copy against 1b3a0e9:

  • scripts/check-changelog-fragments.sh --check: passed

The run reports:

  • /home/runner/work/claude-code-plugins/claude-code-plugins/.lane/checks/bin/check-changelog-fragments: all 12 fragments valid (run before and after the review fixes)
  • /home/runner/work/claude-code-plugins/claude-code-plugins/.lane/checks/bin/check-affected: first run failed validate-plugins on docs/catalog.md drift; after the catalog fix, 11 passed, 7 skipped, 0 failed (run again after the review fixes, same result)
  • fresh-context review subagent over the whole diff: by reading the code, it found no test that would fail. It reported 2 medium and 8 low findings. Fixed: an idle connection the server ended could be handed out; a timeout racing the row-cap cancel could turn a truncated result into an error; a failed
  • read https: //tediousjs.github.io/tedious/api-connection.html: authentication types default/ntlm/token-credential; options port (1433, exclusive with instanceName), appName (default Tedious), encrypt true, trustServerCertificate false, requestTimeout 15000 (0 = none), cancelTimeout 5000, enableImpli
  • read https: //tediousjs.github.io/tedious/api-request.html: new Request(sql, callback(err, rowCount, rows)); a cancelled request's callback gets a RequestError with code ECANCEL; columnMetadata comes before row events; each row column has value and metadata; addParameter(name, type, value), name wit
  • read https: //raw.githubusercontent.com/tediousjs/tedious/master/src/connection.ts: 'default' auth reads options.userName and options.password; token-credential checks options.credential; request timeout raises RequestError code ETIMEOUT after request.cancel(); cancel() returns false with no current
  • read https: //registry.npmjs.org/tedious/latest: version 20.3.8, engines node >=22, depends on azure/identity ^4.13.1 and azure/core-auth
  • read https: //registry.npmjs.org/azure/identity/latest: version 4.14.1, engines node >=22.0.0, an ESM import entry
  • read https: //learn.microsoft.com/en-us/javascript/api/azure/identity/defaultazurecredential: constructor overloads include DefaultAzureCredentialClientIdOptions; getToken(scopes, options)
  • read https: //learn.microsoft.com/en-us/javascript/api/azure/identity/defaultazurecredentialclientidoptions: managedIdentityClientId is an optional user-assigned client id for ManagedIdentityCredential
  • read https: //learn.microsoft.com/en-us/sql/t-sql/statements/set-lock-timeout-transact-sql: SET LOCK_TIMEOUT timeout_period in ms; -1 (the default) waits forever, 0 does not wait; the setting lasts for the rest of the connection
  • read https: //learn.microsoft.com/en-us/sql/t-sql/statements/set-statements-transact-sql: a SET inside dynamic SQL run with sp_executesql or EXECUTE is restored when control returns from that batch
  • The lane run: https://github.com/melodic-software/claude-code-plugins/actions/runs/41194402769

Left out: the items under Not verified.

Related

#11327

Lane-Activity: work-resolve-issue/resolve-issue

@github-actions github-actions Bot 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.

claude-security-review: 1 inline finding(s) on 1b3a0e90268c8bceafc12265900a82463c3dcbc2; the summary is in this lane's pull request comment.

claude-lane: claude-security-review

"test": "node --test"
},
"dependencies": {
"@azure/identity": "4.14.1",

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.

The direct pins are exact, but there is no package-lock.json or Dependabot npm entry for this plugin. The PR description says so and cites docs/contracts/on-demand-dependencies/README.md Rule 1. tedious 20.3.8 depends on @azure/identity ^4.13.1 and a wider tree, and each of those resolves to whatever is latest when the user installs. That code runs in the same process as the SQL login password (read from env) and Entra tokens. A compromised transitive release would therefore land with those credentials, and nothing in the lockfile or Dependabot flow would catch it. Add the lockfile and the Dependabot entry before the executor is relied on.

severity: SUGGESTION

claude-lane: claude-security-review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

pr-unblock / address-feedback: UNCERTAIN, left open

Evidence: plugins/sql-server/package.json:12, docs/contracts/on-demand-dependencies/README.md:29, docs/contracts/on-demand-dependencies/README.md:34

The finding holds as stated. plugins/sql-server/package.json pins @azure/identity 4.14.1 and tedious 20.3.8 exactly, but no plugins/sql-server/package-lock.json exists and .github/dependabot.yml has no npm entry for plugins/sql-server. That leaves the transitive tree unpinned and without integrity hashes. The on-demand-dependencies contract (Rule 1) requires both the committed lockfile and a Dependabot npm entry. This lane cannot make the fix. The review-thread tool refuses both plugins/sql-server/package-lock.json and .github/dependabot.yml as outside this thread's scope. Generating a correct lockfile also needs npm to resolve the dependency tree, and this unattended mode runs no commands. A person should run npm install --package-lock-only in plugins/sql-server, commit the resulting package-lock.json, and add a Dependabot npm entry for /plugins/sql-server to .github/dependabot.yml. Any installer should then use npm ci against that lockfile, per Rule 2.

@github-actions

github-actions Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

claude-security-review reviewed d7443e3954d6f4d9d29febe7ece709297027c89a: 0 finding(s), 0 as inline comments.

No security findings in the incremental change since 39f00e9.

The only changed file is plugins/sql-server/.claude-plugin/plugin.json. The change splits one line in two. The base line held the description string and the opening of "author": { together. The head puts "author": { on its own line. The description text is byte-for-byte the same, and version (0.2.0), author and every other field are unchanged. I judged this from the diff alone, not from the PR text.

  • manifest description: pass. It is in the repository's inert set, and its text did not change.
  • manifest author: pass. It is in the inert set, and this diff does not change its value.
  • No hooks, mcpServers, lspServers, monitors, dependencies or userConfig key was added, changed or removed. No code runs on update, and no guard default moved.

This is not a trusted-path file, a trust control, an instruction surface or a token-scope change. It is not a billing change either. No critical-security hold applies, and critical-findings: 0.

I did not re-review the other files in this PR, which were reviewed at 39f00e9.

@github-actions

github-actions Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

claude-review reviewed d7443e3954d6f4d9d29febe7ece709297027c89a: 0 finding(s), 0 as inline comments.

Incremental review of plugins/sql-server/.claude-plugin/plugin.json since 39f00e9. The change only moves "author" onto its own line. The description text is identical, and the file is well-formed JSON. The description still matches the docs/catalog.md line for sql-server, so the catalog drift check should pass. No findings. I did not re-review the other files, which are unchanged since the last review.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

pr-unblock / address-feedback finished round 1 of max 4 on 1b3a0e9.

@melodic-automation-lanes

melodic-automation-lanes Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor Author

The pr-unblock lane stopped address-feedback on this pull request: the pull request has an unresolved review thread the lane does not take (a reviewer it does not act on, a review of an older head, or a thread it already answered), so nothing will resolve it. The lane sets no label: the run ends in a failing pr-unblock/address-feedback status on the head the lane gated.

When a retry on this head can change the outcome, the lane runs one on its own, up to its per-head cap, and edits this comment if it stops again; a run that does not stop clears the status. When no retry can (a review thread the lane does not take or settle, or a failing check after the retries are spent), a person resolves the threads or gets the checks green, then dispatches the workflow below: that run finds the cause gone and clears the status. On a pull request the lanes App opened, the dispatchers start that run once per stop; on any other, a person does. A new commit to the branch starts clean.

To run it again on this head now, dispatch the pr-unblock workflow:

gh workflow run pr-unblock.yml -R melodic-software/claude-code-plugins -f pr-number=11520 -f activity=address-feedback

@melodic-automation-lanes

melodic-automation-lanes Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor Author

Unattended merge: native auto-merge leaves this pull request unarmed at head d7443e3954d6f4d9d29febe7ece709297027c89a. The lanes clear this reason on their own; the next scheduled run judges it again.

a pr-unblock lane stopped its head (pr-unblock/address-feedback is failure), which ci-status fails
  in the merge queue

Lane-Activity: pr-unblock/resolve-conflicts

@github-actions github-actions Bot 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.

claude-review: 1 inline finding(s) on 39f00e9e0dcb4eb8d19dd7b6637d0445c1a26567; the summary is in this lane's pull request comment.

claude-lane: claude-review

Lane-Activity: pr-unblock/address-feedback
Lane-Thread: PRRT_kwDOTCGFQM6yRJQT
@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

pr-unblock / address-feedback finished round 2 of max 4 on d7443e3.

@kyle-sexton

Copy link
Copy Markdown
Member
Hold: replaced by #11550. Releases when: #11550 is merged, then this PR closes.

@github-actions
github-actions Bot deleted the work-resolve-issue/issue-11327-41194402769-1 branch November 3, 2026 06:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge Hard merge gate: do not merge while applied.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: run sql-server queries through tedious with per-call transaction guards

1 participant