fix(data-integrity): remove session.rollback() calls from ProjectRepository #10990
Merged
HAL9000
merged 4 commits from 2026-06-14 15:59:54 +00:00
fix/8179-remove-session-rollback-calls into master
Labels
Clear 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
Needs Feedback
Signed-off: Owner
Signed-off: Scrum Master
Signed-off: Tech Lead
Spike
Controller deferred this PR; awaiting Phase 6+ scope-evaluator or operator re-enablement.
Auto-agents controller manages this PR/issue (see tools/controller/deploy/RUNBOOK.md). Remove this label to abandon controller management.
PR blocked by an open issue dependency. Operator must close the dep (or remove the dependency link) before the merge driver can act. Auto-cleared by merge_drive when no open deps remain.
Most recent merge cycle hit CI timeout. Driver excludes this PR while last merge_cycle row is < 30 min old; label persists thereafter as visible history.
Currently being processed by an implementer worker.
Currently being processed by the merge driver.
Currently being processed by a reviewer worker.
Merge driver heartbeat stale; pipeline halted. Closed automatically on next clean tick.
Detected master commit violating the strict merge invariant. Tracked as an issue (not a PR label); kept here for label completeness.
In-cycle escalation: most recent attempt ran at the Tier 0 slot (`tier-0`). Slot's model defined in .opencode/models/tiers.yaml.
In-cycle escalation: most recent attempt ran at the Tier 1 slot (`tier-1`). Slot's model defined in .opencode/models/tiers.yaml.
In-cycle escalation: most recent attempt ran at the Tier 2 slot (`tier-2`). Slot's model defined in .opencode/models/tiers.yaml. Gated behind IMPLEMENTER_ESCALATION_TIER2_ENABLED.
In-cycle escalation: most recent attempt ran at the Tier -1 slot (`tier-min`). Slot's model defined in .opencode/models/tiers.yaml. Suffix is ``-min`` (not ``--1``) so the Forgejo UI reads naturally.
Tracking issues used by the AI Automation system for agents to communicate and report.
Rebase conflict needs LLM conflict-resolver.
Failing CI needs implementer attention.
Documenting a driver incident or rollback.
Reviewer has APPROVED this PR and no later REQUEST_CHANGES is outstanding. The merge driver requires this label to even consider a PR for merging. Set by the reviewer worker on APPROVE; cleared on REQUEST_CHANGES.
Train repeatedly lost master-tempo races. Driver excludes via merge_cycle until cooldown elapses; label persists as visible history.
Revert PR backing out an invariant violation. Fast-tracked through the merge driver.
Sentinel PR duplicated from upstream into a personal fork by tools/duplicate_prs_to_fork.py for pipeline testing. Lives only in the fork; the canonical pipeline never sees it.
No implementer activity for N days. Flagged for human review. Auto-cleared on next push to head branch.
Repeatedly fails on current master (>= 3 ci-fail-on-rebased-sha releases in 12 h). Excluded from driver until human triage.
A ticket in a blocked state and unable to complete until some other task is completed first.
Bounty
$100
A bounty of $100 for any open-source contributor who provides a MR that solves this issue
Bounty
$1000
A bounty of $1000 for any open-source contributor who provides a MR that solves this issue
Bounty
$10000
A bounty of $10000 for any open-source contributor who provides a MR that solves this issue
Bounty
$20
A bounty of $20 for any open-source contributor who provides a MR that solves this issue
Bounty
$2000
A bounty of $2000 for any open-source contributor who provides a MR that solves this issue
Bounty
$250
A bounty of $250 for any open-source contributor who provides a MR that solves this issue
Bounty
$50
A bounty of $50 for any open-source contributor who provides a MR that solves this issue
Bounty
$500
A bounty of $500 for any open-source contributor who provides a MR that solves this issue
Bounty
$5000
A bounty of $5000 for any open-source contributor who provides a MR that solves this issue
Bounty
$750
A bounty of $750 for any open-source contributor who provides a MR that solves this issue
MoSCoW
Could have
Could have feature in order to satisfy the epic/legendary.
MoSCoW
Must have
Must have feature in order to satisfy the epic/legendary.
MoSCoW
Should have
Should have feature in order to satisfy the epic/legendary.
There are questions in the ticket that can not be completed until the project owner provides clarity.
Points
1
1 man-hours worth of work for an expert with no learning curve.
Points
13
13 man-hours worth of work for an expert with no learning curve.
Points
2
2 man-hours worth of work for an expert with no learning curve.
Points
21
21 man-hours worth of work for an expert with no learning curve.
Points
3
3 man-hours worth of work for an expert with no learning curve.
Points
34
34 man-hours worth of work for an expert with no learning curve.
Points
5
5 man-hours worth of work for an expert with no learning curve.
Points
55
55 man-hours worth of work for an expert with no learning curve.
Points
8
8 man-hours worth of work for an expert with no learning curve.
Points
88
88 man-hours worth of work for an expert with no learning curve.
Priority
Backlog
This ticket has backlogged priority and is not to be worked on yet
Priority
CI Blocker
Critical priority issue that blocks CI/CD pipeline and prevents PR merges
Priority
Critical
The priority is critical
Priority
High
The priority is high
Priority
Low
The priority is low
Priority
Medium
The priority is medium
When an epic or legendary is in review it must be signed off by owner, tech lead, and scrum master before being marked as completed.
When an epic or legendary is in review it must be signed off by owner, tech lead, and scrum master before being marked as completed.
When an epic or legendary is in review it must be signed off by owner, tech lead, and scrum master before being marked as completed.
A ticket for learning a tool or technology that is needed to be able to do future planning and design.
State
Completed
The ticket has been fully implemented, completed, and merged with the source code. This label should only be applied once a ticket is closed.
State
Duplicate
A ticket that represents the same content as an existing ticket.
State
In Progress
A ticket that is actively being developed.
State
In Review
A ticket that has had some code completed to implement but is waiting to pass peer review and is not yet merged in.
State
Paused
This ticket's work started but wasn't finished. It's on hold (likely in a feature branch) and will be resumed later, either due to a blocker or a delay.
State
Unverified
All new tickets start in this state. A developer may set it to show the ticket is unverified. This means we haven't agreed to work on it. It will either move to a verified state or be closed as wontdo.
State
Verified
The issue has been verified by a developer as legitimate. It will be worked on and verified tickets are now considered part of the backlog.
State
Wont Do
This ticket has been decided it wont be done. This may mean the bug has been determined to not be real (cant verify) or the feature is one we have decided we dont want to adopt.
Type
Automation
Any edits or discussion about the AI automated coding system.
Type
Bug
Something that doesnt work as intended.
Type
Discussion
Anytime a ticket represents a discussion about a subject and doesnt fall into one of the other categories.
Type
Documentation
An error or improvement needed in the documentation.
Type
Epic
Any first tier epic. That is, an epic which contains only issues as children and will not have sub-epics.
Type
Feature
Some new functionality not present.
Type
Legendary
A type of Epic which will contain other Epics.
Type
Refactor
A code change that restructures existing code without changing its external behavior.
Type
Support
Someone needs help using the project.
Type
Task
A generic task that doesnt fit into the other type categories.
Type
Testing
Work exclusively focusing on fixing or expanding testing.
Projects
Clear projects
No project
Assignees
aditya (Aditya Chhabra)
aleenaumair (Aleena Umair)
brent.edwards (Brent Edwards)
CoreRasurae (Luis Mendes)
drew (Drew Morris)
eugen.thaci (Eugen Thaci)
freemo (Jeffrey Phillips Freeman)
HAL9000 (HAL 9000)
HAL9001 (HAL9001)
hamza.khyari (Hamza Khyari)
hurui200320 (Rui Hu)
justin.morris
khird (Kyle Hird)
org.cleveragents
Clear assignees
No Assignees
HAL9000
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: cleveragents/cleveragents-core#10990
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
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
0f281c2432to5eb8f02ab0Code 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:
5b11afeb74toec047130e4(attempt #9, tier 2)
🔧 Implementer attempt —
ci-not-ready.ec047130e4to872776da69872776da69tob8319ab07f(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.
b8319ab07ftodd80d05558Approved by the controller reviewer stage (workflow 397).