fix(data-integrity): remove session.rollback() calls from ProjectRepository #10990
No reviewers
Labels
No labels
auto/needs-reevaluation
controller-managed
overdue
auto/blocked-by-deps
auto/ci-timeout
auto/claimed-implementer
auto/claimed-merge
auto/claimed-reviewer
auto/driver-down
auto/invariant-violation
auto/last-attempt-tier-0
auto/last-attempt-tier-1
auto/last-attempt-tier-2
auto/last-attempt-tier-min
Automation Tracking
auto/needs-conflict-resolution
auto/needs-implementer
auto/postmortem
auto/ready-to-merge
auto/restart-throttled
auto/revert
auto/sentinel
auto/stale-inactivity
auto/unstable
Blocked
Bounty
$100
Bounty
$1000
Bounty
$10000
Bounty
$20
Bounty
$2000
Bounty
$250
Bounty
$50
Bounty
$500
Bounty
$5000
Bounty
$750
MoSCoW
Could have
MoSCoW
Must have
MoSCoW
Should have
Needs Feedback
Points
1
Points
13
Points
2
Points
21
Points
3
Points
34
Points
5
Points
55
Points
8
Points
88
Priority
Backlog
Priority
CI Blocker
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Signed-off: Owner
Signed-off: Scrum Master
Signed-off: Tech Lead
Spike
State
Completed
State
Duplicate
State
In Progress
State
In Review
State
Paused
State
Unverified
State
Verified
State
Wont Do
Type
Automation
Type
Bug
Type
Discussion
Type
Documentation
Type
Epic
Type
Feature
Type
Legendary
Type
Refactor
Type
Support
Type
Task
Type
Testing
No project
No assignees
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
cleveragents/cleveragents-core!10990
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/8179-remove-session-rollback-calls"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
PR Compliance Checklist (MANDATORY)
ISSUES CLOSED: #8179included in commit messagefeatures/project_repository.featureSummary
This PR removes unconditional
session.rollback()calls within exception handlers inProjectRepository.create()andNamespacedProjectRepositorymethods (create,update,delete). The Unit of Work pattern already handles transaction rollback at theouter layer via its
except Exception: session.rollback()handler, making these innerrollbacks redundant.
Changes
Code Changes (repositories.py)
Removed 5
session.rollback()calls:ProjectRepository.create()exception handlerNamespacedProjectRepository.create()IntegrityError handlerNamespacedProjectRepository.create()OperationalError/SQLAlchemyDatabaseError handlerNamespacedProjectRepository.update()OperationalError/SQLAlchemyDatabaseError handlerNamespacedProjectRepository.delete()OperationalError/SQLAlchemyDatabaseError handlerTest Changes
Added BDD scenarios in
features/project_repository.feature:Added step definitions for the new BDD scenarios.
Why This Matters
SQLAlchemy automatically invalidates the transaction state when exceptions occur after
flush(), preventing partial data from being committed. The redundantsession.rollback()calls were:
Removing them improves clarity, eliminates potential issues related to exception chaining
across retry boundary layers, and aligns repository implementations with explicit
transaction boundaries.
Issue Reference
Parent Epic: #7505 (LLMTraceRepository data-integrity fix)
Child: #8179
0f281c24325eb8f02ab0Code Review — PR #10990
Thank you for the clear PR description and the effort to address a real data-integrity concern. The core idea — removing redundant
session.rollback()calls fromProjectRepository— is sound. However, there are several blocking issues that must be resolved before this can be approved.CI Status
CI is currently failing on:
lint,unit_tests,integration_tests,benchmark-regression, andstatus-check. The lint failure is directly caused by a dead import introduced by this PR (see inline comment). The test failures likely cascade from there. All CI gates must pass before merge.Summary of Blocking Issues
Dead import in step file —
from sqlalchemy.exc import IntegrityError as _IntegrityErroris imported but never used, causing thelintCI failure.Incorrect rollback removal for
NamespacedProjectRepository— This class uses a session-factory pattern where it creates, commits, and closes its own session. It is NOT wired into a UnitOfWork. Removingsession.rollback()from its error handlers WITHOUT adding arollback()call to thefinallyblock leaves the owned session in a potentially dirty transaction state beforeclose(). The justification in the PR description ("UoW handles rollback at the outer layer") does not apply here. The fix forProjectRepository.create()(which IS a shared UoW session) is correct; the fixes forNamespacedProjectRepositoryneed either (a)session.rollback()added back, or (b) thefinallyblock updated to callsession.rollback()beforesession.close()on error paths.CHANGELOG.md structural duplication — The new entry was inserted as a brand-new
### Fixedsection immediately before the existing### Fixedsection. This results in two consecutive### Fixedheaders under[Unreleased]. The new entry must be merged into the existing### Fixedsection.Missing
Type/label on PR — Per CONTRIBUTING.md, every PR must have exactly oneType/label (Type/Bug,Type/Feature, orType/Task). This PR has no labels at all.Missing
@tdd_issue_8179regression tags — For a bug fix, CONTRIBUTING.md requires BDD scenarios to be tagged with@tdd_issue,@tdd_issue_<N>, and (for pre-fix scenarios)@tdd_expected_fail. The two new scenarios inproject_repository.featurehave no tags at all.Non-Blocking Suggestions
@then('the repository error type should be "{error_type}"')step added at line 591 is functionally identical to the existing@then('the repository error should be "{error_type}"')at line 180. Consider reusing the existing step in the new scenarios rather than introducing a near-duplicate.step_pr_create_with_errorstates "rollback is delegated to the UoW outer-layer handler" — butNamespacedProjectRepositoryoperates outside UoW context. The docstring is misleading regardless of how the rollback issue is resolved.Automated by CleverAgents Bot
Supervisor: PR Review | Agent: pr-review-worker
BLOCKING — Duplicate
### FixedSection HeaderThis creates a second
### Fixedsection immediately preceding the existing### Fixedsection in the[Unreleased]block. Keep a Changelog format requires exactly one subsection per type per release block.Why it's a problem: The resulting CHANGELOG has two consecutive
### Fixedheadings under[Unreleased], which is structurally invalid and would confuse changelog parsers and readers.How to fix: Remove the new
### Fixedheader introduced here and instead add the new entry directly into the existing### Fixedsection that follows. The entry itself is well-written and correct — only the duplicate header is the problem.Automated by CleverAgents Bot
Supervisor: PR Review | Agent: pr-review-worker
BLOCKING — Missing TDD Regression Tags
Per CONTRIBUTING.md, BDD scenarios that serve as regression tests for bug fixes must be tagged with
@tdd_issueand@tdd_issue_<N>(where N is the issue number). Both new scenarios are missing these tags entirely.Why it's a problem: The TDD tag system is how CI identifies regression tests and how the codebase maintains traceability between tests and the bugs they prevent. Without these tags, the scenarios are not recognisable as regression tests.
How to fix: Add tags above the scenarios:
Automated by CleverAgents Bot
Supervisor: PR Review | Agent: pr-review-worker
BLOCKING — Dead Import (Lint Failure)
This import is never used anywhere in the function body.
_IntegrityErroris neither caught nor referenced. This is the direct cause of theCI / lintfailure.Why it's a problem: Ruff (the project's linter) flags unused imports as errors (
F401), and the lint CI gate is required for merge.How to fix: Remove this line entirely. The step only needs to call
context.pr_project_repo.create(project)and catchException— there is no need to importIntegrityErrorhere.Automated by CleverAgents Bot
Supervisor: PR Review | Agent: pr-review-worker
BLOCKING — Incorrect Rollback Removal for
NamespacedProjectRepositoryThe PR description justifies removing
session.rollback()by stating that the UnitOfWork handles rollback at the outer layer. This reasoning is correct forProjectRepository, which receives a shared UoW-managedsessionvia constructor injection.However,
NamespacedProjectRepositorydoes NOT use a shared UoW session. It is a session-factory pattern repository: each method callsself._session()to create a brand-new session, and the method itself callssession.commit()andsession.close(). The class docstring (line ~3000) explicitly states: "All mutating methods flush and commit within their own session. No external UnitOfWork is needed."Why it's a problem: When
session.commit()raisesIntegrityErrororOperationalError, the connection is left in a failed transaction state. Callingsession.close()in thefinallyblock without a priorsession.rollback()does not guarantee the underlying database connection is properly rolled back before it is returned to the connection pool. This can cause connection pool poisoning or unexpected transaction states for subsequent callers.How to fix: For the
NamespacedProjectRepositorymethods, either:session.rollback()in the error handlers, ORfinallyblock:The removal from
ProjectRepository.create()(which uses a UoW-managed shared session) is correct and should be kept.Automated by CleverAgents Bot
Supervisor: PR Review | Agent: pr-review-worker
Automated by CleverAgents Bot
Supervisor: PR Review | Agent: pr-review-worker
@forgejo-label-manager apply labels: State/In Review, Priority/Medium
Re-Review — PR #10990
Thank you for the prompt follow-up commit addressing the previous feedback. Good progress was made — three of the five blocking issues were correctly resolved. However, two blocking issues remain that are directly causing the current CI failures, and one additional formatting issue was introduced in the fix commit itself.
Previous Feedback — Status
_IntegrityErrorin step fileNamespacedProjectRepositoryrollback infinallysession.rollback()added beforesession.close()in all four owned-session methods### FixedsectionType/label on PR@tdd_expected_failis incorrect on post-fix scenarios (see below)Current Blocking Issues
1.
@tdd_expected_failis incorrect on the new scenarios — directly causingCI / unit_testsfailureThe
@tdd_expected_failtag inverts the Behave result: when present, a test passing is reported as failing ("bug was fixed without removing the tag"), and a test failing is reported as passing ("bug still exists"). This tag is for TDD issue-capture tests written BEFORE the fix to prove the bug exists — not for post-fix verification tests.The two new scenarios in
project_repository.featureare included in the FIX PR itself and verify correct post-fix behaviour (thatDatabaseErrorandProjectNotFoundErrorare raised correctly). Since the fix is in place, these scenarios PASS — which means@tdd_expected_failcauses them to be reported as FAILING in CI. This is the direct cause of theCI / unit_testsfailure.How to fix: Remove
@tdd_expected_failfrom both scenarios. Keep@tdd_issueand@tdd_issue_8179— those are correct for traceability. Only@tdd_expected_failshould be removed.2. Blank line after docstring in
step_pr_create_with_error— causingCI / lintfailureThe second commit introduced a blank line between the closing
"""of the docstring and the first statement of the function body (project = _make_project(ns_name)). Ruff'sformat --checktreats this as a formatting violation. This is the direct cause of theCI / lintfailure.How to fix: Remove the blank line immediately after the closing
"""so the first statement follows the docstring directly.3. Missing
Type/label — still unaddressedPer CONTRIBUTING.md, every PR must have exactly one
Type/label (Type/Bug,Type/Feature, orType/Task). This PR has no labels at all. For a bug fix, the correct label isType/Bug.How to fix: Apply the
Type/Buglabel to this PR.CI Summary
Failing required gates:
CI / lint— failing (blank line formatting violation in step file)CI / unit_tests— failing (@tdd_expected_failinversion on passing scenarios)CI / status-check— failing (aggregate of above)Passing:
typecheck,security,integration_tests,e2e_tests,build,quality,coverageNon-Blocking Observations
NamespacedProjectRepositoryrollback fix is well-implemented using thefinallypattern — exactly the right approach.CONTRIBUTORS.mdentry is appropriate.Automated by CleverAgents Bot
Supervisor: PR Review | Agent: pr-review-worker
BLOCKING —
@tdd_expected_failis incorrect here and is causingCI / unit_teststo failThe
@tdd_expected_failtag inverts the Behave result: a passing test is reported as failing and a failing test is reported as passing. This tag belongs on TDD issue-capture tests written BEFORE the fix — not on verification tests added in the fix PR itself.Because the fix is now in place, these scenarios PASS correctly. But with
@tdd_expected_failpresent, CI reports them as FAILED. This is the direct cause of theCI / unit_testsfailure.How to fix: Remove
@tdd_expected_failfrom both new scenarios — keep only@tdd_issueand@tdd_issue_8179:Automated by CleverAgents Bot
Supervisor: PR Review | Agent: pr-review-worker
BLOCKING — Extra blank line after docstring is causing
CI / lintfailureThere is a blank line between the closing
"""of the docstring and the first statementproject = _make_project(ns_name). Ruff'sformat --check(run as part ofCI / lint) rejects this — it does not allow extra blank lines immediately after a docstring inside a function body.How to fix: Remove the blank line so the first statement follows immediately:
Running
nox -s formatlocally would catch and auto-fix this.Automated by CleverAgents Bot
Supervisor: PR Review | Agent: pr-review-worker
Automated by CleverAgents Bot
Supervisor: PR Review | Agent: pr-review-worker
[CONTROLLER-DEFER:Gate 1:full_duplicate]
This PR has been deferred for re-evaluation. The controller has stepped back
from processing it. To resume, a human or scope-evaluator must clear the
deferral flag AND re-add the auto/sentinel label.
Decision:
To clear the deferral (SQL):
UPDATE workflows SET deferred_reason=NULL,
deferred_at=NULL,
deferred_target_workflow_id=NULL
WHERE workflow_id = 397;
Audit ID: 142072
Automated by the CleverAgents controller pipeline.
Identity: HAL9000 (pipeline action)
📋 Estimate: tier 1.
Core change is straightforward: remove 5 redundant session.rollback() calls from repositories.py (single file, well-understood pattern). However, CI has multiple failures requiring fixes: (1) ruff format issue on features/steps/project_repository_steps.py (trivial), (2) the newly-added BDD scenario "IntegrityError raises DatabaseError through repository create method" is failing — needs step definition debugging to understand why the test doesn't pass. Other CI failures (actor_run_signature, pr_compliance_checklist, integration tests) appear pre-existing and unrelated. Multi-file scope (repositories.py + .feature file + step definitions) and a failing test that requires reasoning about the BDD implementation push this above tier 0. No architectural complexity or cross-subsystem coupling.
(attempt #4, tier 2)
🔧 Implementer attempt —
blocked.Files touched:
features/project_repository.feature,features/steps/project_repository_steps.py,features/database_repository_coverage.feature,features/steps/container_and_repository_coverage_steps.py.Blockers:
5b11afeb74ec047130e4(attempt #9, tier 2)
🔧 Implementer attempt —
ci-not-ready.ec047130e4872776da69872776da69b8319ab07f(attempt #12, tier 2)
🔧 Implementer attempt —
ci-not-ready.✅ Approved
Reviewed at commit
b8319ab.Confidence: high.
Claimed by
merge_drive.py(pid 2329255) until2026-06-14T17:06:13.703747+00:00.This claim is advisory and will be released when the cycle ends, or after the TTL by a sibling driver's expired-claim sweep.
b8319ab07fdd80d05558Approved by the controller reviewer stage (workflow 397).