Skip to content

Add SQL Server write-safety instructions for T-SQL 🤖🤖🤖 - #5447

Merged
aaronpowell merged 4 commits into
github:mainfrom
scottkcoffey-a11y:add-sql-server-write-safety-instructions
Oct 25, 2026
Merged

aaronpowell merged 4 commits into
github:mainfrom
scottkcoffey-a11y:add-sql-server-write-safety-instructions

Conversation

@scottkcoffey-a11y

Copy link
Copy Markdown

Standalone resubmission of #5310, revised per review.

  • No upstream or product links. The file stands on its own.
  • Dry run fails closed: anything other than an explicit 0, including NULL, is a dry run.
  • The procedure template archives in TOP (N) batches with one short transaction per batch, a fresh OUTPUT...INTO key set, and refuses to run inside a caller-owned transaction.
  • Removed the tooling, security, and review checklist sections that restated defaults. What remains is SQL Server-specific: XACT_ABORT with THROW, @@TRANCOUNT handling, statements that cannot run in a user transaction, batched archive-then-delete, and read-only DMV diagnostics.

The procedure template was executed on SQL Server 16.0.4305.5 Developer Edition (64-bit) against a 12,000-row test table: default dry run and @DryRun = NULL changed nothing, a caller transaction was refused, invalid parameters raised errors, a live run with @batchsize = 500 moved exactly the 4,000 qualifying rows, and a rerun moved 0.

Co-authored-by: scottkcoffey-a11y <scottkcoffey-a11y@users.noreply.github.com>
@scottkcoffey-a11y
scottkcoffey-a11y requested review from a team as code owners October 24, 2026 13:29
Copilot AI max review requested due to automatic review settings October 24, 2026 13:29
@github-actions github-actions Bot added instructions PR touches instructions new-submission PR adds at least one new contribution awaiting-automation merge-risk:medium labels Oct 24, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔒 PR Risk Scan Results

Scanned 1 changed file(s).

Severity Count
🔴 High 0
🟠 Medium 0
ℹ️ Info 0

✅ No matching risk patterns were detected in changed files.

This is an automated soft-gate report. Findings indicate review targets and do not block merge by themselves.

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

🚦 Submission status: 👀 Ready for review

Risk tier: merge-risk:medium — New or substantially changed resource without privileged execution
Required to merge: passing submission-gate checks plus 1 approval from reviewers with write access.

Why this tier
  • Adds 1 file(s), e.g. instructions/sql-server-safe-tsql.instructions.md
  • Changes 135 lines (low-risk limit is 40)

Automated checks

Check Status Details
Line endings ✅ Passed Passed · logs
Spelling ✅ Passed Passed · logs
Generated README consistency ✅ Passed Passed · logs
Risk scan ✅ Passed Passed · logs
Contributor reputation ✅ Passed Passed · logs
Duplicate resource scan ✅ Passed Passed · logs
PR quality signal ⏭️ Skipped Skipped by its workflow · logs

Review

  • Approvals: 0/1
  • Assigned reviewer: not assigned yet — comment /request-review to ask for one
  • Review target date: not set
  • Still needed: 1 more approval(s)
  • No staffed reviewer pool owns these files yet; any reviewer with write access counts as the domain reviewer.

Commands

Command Who What it does
/rerun-checks PR author, maintainers Re-runs failed or incomplete checks and re-evaluates this gate
/request-review PR author, maintainers Asks the review rotation to assign a reviewer (adds needs-reviewer)

Updated for 9c19d39 · gate run · This comment is maintained automatically — see submission gate docs.

@github-actions github-actions Bot added ready-for-review Submission passed intake validation and is ready for maintainer review and removed awaiting-automation labels Oct 24, 2026

Copilot AI 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.

🟡 Changes recommended

The archive template’s transaction and failure-reporting guarantees need correction before it is safe to reuse.

2 open issues
What changed in this PR

Adds SQL Server-specific safety instructions for T-SQL and PowerShell scripts, complementing the repository’s general SQL guidance.

Changes:

  • Defines fail-closed dry runs, transaction handling, and confirmation gates for destructive operations.
  • Provides a batched archive/delete template and read-only diagnostic guidance.
  • Adds the resource to the instructions catalog with installation links.
File Description
instructions/​sql-server-safe-tsql.instructions.md Adds SQL Server write-safety rules, a procedure template, and diagnostic guidance.
docs/​README.instructions.md Lists the new instructions and installation links.

Review effort: Max

Comment thread instructions/sql-server-safe-tsql.instructions.md Outdated
Comment thread instructions/sql-server-safe-tsql.instructions.md Outdated
…cted note

Co-authored-by: scottkcoffey-a11y <scottkcoffey-a11y@users.noreply.github.com>
Copilot AI max review requested due to automatic review settings October 25, 2026 15:08
@scottkcoffey-a11y

Copy link
Copy Markdown
Author

/request-review

@github-actions github-actions Bot added needs-reviewer and removed ready-for-review Submission passed intake validation and is ready for maintainer review labels Oct 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🙋 Added needs-reviewer. Reviewer routing is assigning a reviewer now.

@github-actions github-actions Bot added ready-for-review Submission passed intake validation and is ready for maintainer review and removed awaiting-automation labels Oct 25, 2026

Copilot AI 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.

🟡 Changes recommended

The single-transaction guidance can leave writes uncommitted and locks held when implicit transactions are enabled.

1 open issue
1 previously missed issue

In code that hasn't changed since last review

Medium severity Remove HOLDLOCK unless preventing new qualifying rows is required

instructions/​sql-server-safe-tsql.instructions.md:92

HOLDLOCK gives this scan serializable semantics, so it can retain range locks beyond the copied rows and block inserts, including when the final batch is empty. UPDLOCK already protects copied rows until the key-based delete commits; remove HOLDLOCK unless preventing new qualifying rows is an explicit requirement.

2 resolved since last review

Review effort: Max

Comment thread instructions/sql-server-safe-tsql.instructions.md Outdated
…le, drop HOLDLOCK

Co-authored-by: scottkcoffey-a11y <scottkcoffey-a11y@users.noreply.github.com>
Copilot AI max review requested due to automatic review settings October 25, 2026 16:32
@github-actions github-actions Bot added awaiting-automation and removed ready-for-review Submission passed intake validation and is ready for maintainer review labels Oct 25, 2026
@github-actions github-actions Bot added ready-for-review Submission passed intake validation and is ready for maintainer review and removed awaiting-automation labels Oct 25, 2026

Copilot AI 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.

🔵 Needs a closer look

The template’s default batch size can reach SQL Server’s lock-escalation threshold and cause table-wide blocking.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Reduce default batch size to limit lock escalation

instructions/​sql-server-safe-tsql.instructions.md:40

Under row/key locking, a full 5,000-row batch can reach SQL Server's lock-escalation threshold, causing table-wide blocking until the batch commits. Use a smaller default such as 1,000 to reduce this risk; larger overrides should be tuned for the workload.

1 resolved since last review

Review effort: Max

…tion

Co-authored-by: scottkcoffey-a11y <scottkcoffey-a11y@users.noreply.github.com>
Copilot AI max review requested due to automatic review settings October 25, 2026 17:24

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@github-actions github-actions Bot added awaiting-automation ready-for-review Submission passed intake validation and is ready for maintainer review and removed ready-for-review Submission passed intake validation and is ready for maintainer review awaiting-automation labels Oct 25, 2026

@aaronpowell aaronpowell 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.

Thanks @scottkcoffey-a11y — this addresses everything from #5310: no upstream link, @DryRun IS NULL OR @DryRun <> 0 fails closed, real TOP (@BatchSize) batches, and the generic sections are gone. The IMPLICIT_TRANSACTIONS check and the @RowsAffected-after-rethrow note are exactly the SQL Server traps this file should carry. Optional nit: a narrower .ps1 glob would help. Approving.

@aaronpowell
aaronpowell merged commit 12b6b64 into github:main Oct 25, 2026
25 of 27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

instructions PR touches instructions merge-risk:medium needs-reviewer new-submission PR adds at least one new contribution ready-for-review Submission passed intake validation and is ready for maintainer review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants