Skip to content

Docs: PostgreSQL open-transaction restore limit, NO_BACKSLASH_ESCAPES caveat - #8

Merged
rasuvaeff merged 2 commits into
masterfrom
fix/review-2026-11-20
Nov 20, 2026
Merged

rasuvaeff merged 2 commits into
masterfrom
fix/review-2026-11-20

Conversation

@rasuvaeff

@rasuvaeff rasuvaeff commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

Fixes #7
Refs #6

#6 (PostgreSQL restore undone by a rollback) cannot be fixed inside within(): PostgreSQL has no non-transactional SET. Checked on a live postgres:17: session SET, set_config(..., false) and RESET inside a transaction are all undone by ROLLBACK, and in an aborted transaction the restore fails with 25P02. Comparing inTransaction() on exit would detect the case but has nothing that survives the caller's rollback, so no code change ships here (a regression test cannot fail without a fix that changes nothing).

  • README Limitations (EN + RU), llms.txt and the agent skill name the leaking pattern (entered outside a transaction, callback exits with its own transaction still open, rolled back later) and the two safe forms.
  • Integration tests in the pgsql leg of the ungated database-integration job: the callback commits / rolls back its own transaction → the previous limit is restored; a transaction left open and rolled back → the session keeps the budget (pins the documented limit).

#7 (MySqlHint under NO_BACKSLASH_ESCAPES): README Security (EN + RU), llms.txt and the skill carry the caveat. Reproduced offline: WITH a AS (SELECT 'C:\' AS p, ') SELECT x' AS q) SELECT * FROM a gets the hint inside the second literal.

Release header: ## 0.1.1 — 2026-11-20 (no src/ change).

Local: composer build green, composer rector clean, integration suite green against postgres:17, mutation (--with-uncovered) MSI 4.32 pp over minMsi 88.

Summary by Sourcery

Document database-specific timeout and SQL-scanning limitations, and add PostgreSQL integration tests that pin the supported transaction patterns.

Enhancements:

  • Document PostgreSQL transaction-lifecycle limitations and safe usage patterns for restoring statement timeouts.
  • Document the MySQL NO_BACKSLASH_ESCAPES caveat and recommend safer alternatives to apply().

Documentation:

  • Update English and Russian README files, llms.txt, and the agent skill with PostgreSQL restore limitations and MySQL scanner caveats.
  • Publish the 0.1.1 release notes.

Tests:

  • Add PostgreSQL integration coverage for transaction-safe restoration and the documented rollback limitation.

@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: cdbf3108-d964-4ff3-9ce8-7c387821a96c
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@sourcery-ai

sourcery-ai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Documentation

Document the PostgreSQL open-transaction restore limitation and safe forms, alongside the MySQL NO_BACKSLASH_ESCAPES caveat, across the release notes and user-facing guidance.

  • CHANGELOG.md L8-18
  • README.md L55-63, L161-169
  • README.ru.md L58-66, L166-175
  • llms.txt L26-34
  • resources/skills/rasuvaeff-context-db/SKILL.md L34-40

Tests

Add PostgreSQL integration coverage for restoration after callback-owned transactions end and for the documented case where a later rollback undoes restoration.

  • tests/Integration/ServerTimeoutIntegrationTest.php L12, L110-172

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai

sourcery-ai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Linked issues

Checked at commit ccf5b73

#7 MySqlHint: document the `NO_BACKSLASH_ESCAPES` limitation · 1 of 1 met

# Requirement Status Notes
1 Add the NO_BACKSLASH_ESCAPES caveat to README Security in both languages. ✅ Met The English and Russian Security sections explain the scanner limitation and recommend using within() or binding values as parameters.

@sourcery-ai sourcery-ai 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.

Hey - I've found 4 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="README.md" line_range="167" />
<code_context>
+backslash (`'C:\'`) is read as unterminated, and the hint can land inside a
+later string literal — changing that literal's value. Do not use `apply()` on
+MySQL connections in that mode (use `within()`), or keep backslashes out of
+literals by binding such values as parameters. A budget that
 came from another process must already be capped (see
 `rasuvaeff/context`'s `WireCodec`).
</code_context>
<issue_to_address>
**Concurrent scopes use wrong timeout**

When two callbacks on the same PDO overlap, such as when one yields while its `within()` scope is active, the first `within()` call sets a session budget and pauses in its callback; a second call on the same PDO saves that temporary value and restores it, then the first call restores an older value out of order. Subsequent queries receive the wrong limit, and the session can be left with a leaked timeout.

Document that `within()` calls must be serialized per PDO, or guard overlapping scopes and use isolated connections.
</issue_to_address>

### Comment 2
<location path="README.md" line_range="58-59" />
<code_context>
+- **On PostgreSQL, do not leave a transaction open across `within()`.**
+  PostgreSQL has no non-transactional `SET`: when `within()` is entered
+  outside a transaction and the callback opens one and returns (or throws)
+  with it still open, the restore runs inside that transaction, and a later
+  rollback undoes it — the session keeps the budget as its statement timeout.
+  Either open and close the transaction inside the callback, or call
+  `within()` inside the transaction, so it uses `SET LOCAL`.
</code_context>
<issue_to_address>
**Aborted restore described as successful**

When the callback throws after a PostgreSQL statement error has left its transaction aborted, a database error can leave the callback’s transaction aborted, so `scoped()`’s restore attempt fails with `25P02` and is swallowed; the later rollback does not undo a successful restore. The docs attribute the lingering budget to rollback undoing the restore, which misstates what happens on this common error path.

Clarify that the restore is only attempted in the aborted transaction and can fail with `25P02`; the caller’s rollback then leaves the session budget in place.

Also at `README.ru.md:61-62`.
</issue_to_address>

### Comment 3
<location path="README.md" line_range="59" />
<code_context>
+  PostgreSQL has no non-transactional `SET`: when `within()` is entered
+  outside a transaction and the callback opens one and returns (or throws)
+  with it still open, the restore runs inside that transaction, and a later
+  rollback undoes it — the session keeps the budget as its statement timeout.
+  Either open and close the transaction inside the callback, or call
+  `within()` inside the transaction, so it uses `SET LOCAL`.
</code_context>
<issue_to_address>
**Rollback leaves prior timeout active**

When the prior PostgreSQL statement timeout is stricter than the context budget, `scoped()` preserves that stricter timeout instead of installing the context budget, so a later rollback leaves the prior timeout active rather than the budget claimed by the README.

Clarify that rollback leaves the preserved prior timeout active when it is stricter than the context budget.

Also at `README.ru.md:62`, `resources/skills/rasuvaeff-context-db/SKILL.md:35`, `CHANGELOG.md:12`.
</issue_to_address>

### Comment 4
<location path="resources/skills/rasuvaeff-context-db/SKILL.md" line_range="35" />
<code_context>
    transaction-pooling pgbouncer call `within()` inside a transaction so it
-   uses `SET LOCAL`.
+   uses `SET LOCAL`. Never leave a transaction open across `within()`: a
+   rollback after it undoes the restore and the session keeps the budget.
+
+   MySQL under `sql_mode=NO_BACKSLASH_ESCAPES`: do not use `apply()` — its
</code_context>
<issue_to_address>
**Skill omits a safe form**

When an agent relies on the skill for PostgreSQL transaction-lifecycle guidance, the skill warns against leaving a transaction open across `within()` and mentions `SET LOCAL`, but never tells the agent that opening and closing its own transaction inside the callback is also safe; agents relying on the skill miss one of the two claimed patterns.

Add the callback-owned transaction form to the skill's PostgreSQL guidance.
</issue_to_address>

Sourcery assessment

Approval pending. 1 finding to address first.

Blocking findings: README.md:167


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread README.md Resolved
Comment thread README.md Resolved
Comment thread README.md Resolved
@rasuvaeff
rasuvaeff merged commit aa2399a into master Nov 20, 2026
15 checks passed
@rasuvaeff
rasuvaeff deleted the fix/review-2026-11-20 branch November 20, 2026 20:40
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.

MySqlHint: document the NO_BACKSLASH_ESCAPES limitation

1 participant