Repository navigation
Docs: PostgreSQL open-transaction restore limit, NO_BACKSLASH_ESCAPES caveat - #8
Conversation
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
Reviewer's GuideDocumentationDocument the PostgreSQL open-transaction restore limitation and safe forms, alongside the MySQL
TestsAdd PostgreSQL integration coverage for restoration after callback-owned transactions end and for the documented case where a later rollback undoes restoration.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Linked issuesChecked at commit ccf5b73 #7 MySqlHint: document the `NO_BACKSLASH_ESCAPES` limitation · 1 of 1 met
|
There was a problem hiding this comment.
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
… forms in the skill
Fixes #7
Refs #6
#6 (PostgreSQL restore undone by a rollback) cannot be fixed inside
within(): PostgreSQL has no non-transactionalSET. Checked on a livepostgres:17: sessionSET,set_config(..., false)andRESETinside a transaction are all undone byROLLBACK, and in an aborted transaction the restore fails with25P02. ComparinginTransaction()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).llms.txtand 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.pgsqlleg of the ungateddatabase-integrationjob: 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.txtand the skill carry the caveat. Reproduced offline:WITH a AS (SELECT 'C:\' AS p, ') SELECT x' AS q) SELECT * FROM agets the hint inside the second literal.Release header:
## 0.1.1 — 2026-11-20(nosrc/change).Local:
composer buildgreen,composer rectorclean, integration suite green againstpostgres:17, mutation (--with-uncovered) MSI 4.32 pp overminMsi88.Summary by Sourcery
Document database-specific timeout and SQL-scanning limitations, and add PostgreSQL integration tests that pin the supported transaction patterns.
Enhancements:
NO_BACKSLASH_ESCAPEScaveat and recommend safer alternatives toapply().Documentation:
llms.txt, and the agent skill with PostgreSQL restore limitations and MySQL scanner caveats.Tests: