KB-25A5

dot-iu-cutter v0.4 PG-backed Dry-run Adapter Transaction Defect — GPT Review

6 min read Revision 1
dot-iu-cutterreviewv0.4db-adapterdry-run-failadapter-defectcode-fix-nextgit-ssothardcode-control

dot-iu-cutter v0.4 — PG-backed Dry-run Adapter Transaction Defect GPT Review

Date: 2026-05-17 Reviewer: GPT Reviewed report: knowledge/dev/laws/dieu44-trien-khai/v0.4-db-adapter-dry-run/dot-iu-cutter-v0.4-pg-backed-dry-run-EXECUTION-FAIL-adapter-txn-defect-2026-05-17.md

Verdict

pg_backed_dry_run_result: FAIL_ACCEPTED
agent_behavior: PASS_CORRECT
root_cause: RealPostgresAdapter_transaction_pool_lifecycle_defect
schema_binding_defect: false
verification_r3_defect: false
harness_defect_for_S4: false
production_touched: false
pg_backed_dry_run_blocked: true
next_phase: RealPostgresAdapter_txn_lifecycle_fix_code_authoring

The dry-run did exactly what it was intended to do: it exposed a real defect that unit fakes did not model. Agent correctly stopped, tore down the isolated env, did not improvise, and did not mark PASS.

Accepted Failure Finding

first_failed_scenario: S4_MARK
error: SET_TRANSACTION_ISOLATION_LEVEL_must_be_called_before_any_query
cause:
  - RealPostgresAdapter.find_runs_SELECT_outside_explicit_transaction
  - psycopg_connection_autocommit_false_opens_implicit_transaction
  - pooled_connection_returned_without_commit_or_rollback
  - next_transaction_begin_attempts_SET_TRANSACTION_ISOLATION_after_query
  - psycopg3_rejects_this_sequence

This is a transport/transaction lifecycle defect in cutter_agent/db_adapter.py, unchanged from prior accepted commit, not a schema-binding row-shape problem.

Boundary Confirmation

dry_run_env_created_and_torn_down: true
production_sysid_pre_post_unchanged: true
production_secret_read: false
production_row_write: false
production_CUT_VERIFY: false
code_change_this_cycle: false
git_commit_this_cycle: false
forbidden_SQL_surface_seen: false
hardcode_finding: false
protected_envs_untouched: true

Required Next Phase

Open a new bounded code-authoring phase:

phase: v0_4_RealPostgresAdapter_transaction_lifecycle_fix
nature: code_authoring_with_tests

Allowed scope:

modify_allowed:
  - iu-cutter/cutter_agent/db_adapter.py
  - iu-cutter/tests/test_real_postgres_adapter.py
  - optionally iu-cutter/tests/test_pg_transaction_lifecycle.py
modify_forbidden_unless_STOP_and_explain:
  - iu-cutter/cutter_agent/ledger.py
  - iu-cutter/cutter_agent/phases.py
  - iu-cutter/cutter_agent/schema_binding.py
  - iu-cutter/cutter_agent/state_machine.py
  - iu-cutter/cutter_agent/idempotency.py
  - iu-cutter/cutter_agent/signing.py
  - iu-cutter/cutter_agent/signal.py
  - iu-cutter/cli.py

Fix Requirements

The code fix must ensure:

requirements:
  - out_of_transaction_find_does_not_leave_connection_in_open_transaction
  - transaction_begin_can_SET_ISOLATION_as_first_statement
  - pooled_connection_returned_to_pool_clean
  - rollback_on_query_exception_before_pool_return
  - no_autocommit_global_behavior_that_breaks_phase_transactions
  - preserve_one_atomic_transaction_per_phase
  - preserve_principal_routing
  - preserve_no_DELETE_TRUNCATE_DDL_GRANT_runtime_surface
  - no_hardcoded_DSN_password_IP_container
  - no_production_connection_or_secret_read_in_tests

Acceptable implementation choices include:

candidate_fixes:
  - commit_or_rollback_after_autocommit_false_out_of_txn_find_before_pool_return
  - use_dedicated_autocommit_read_connection_for_out_of_txn_reads_if_pool_model_supports_it_safely
  - make__begin_clean_or_reject_dirty_connection_before_SET_ISOLATION

GPT preference: keep the smallest safe fix: ensure find() and any other out-of-transaction read release the pooled connection only after explicit commit() or rollback(), and ensure _begin defensively refuses or cleans a dirty connection before SET TRANSACTION ISOLATION LEVEL.

Test Requirements

Add tests that failed before this fix would be caught:

tests_required:
  - fake_connection_models_psycopg_rule_SET_ISOLATION_before_any_query
  - find_outside_transaction_then_transaction_does_not_fail
  - find_exception_rolls_back_before_pool_return
  - pooled_connection_clean_after_out_of_txn_find
  - transaction_still_sets_requested_isolation_first
  - existing_101_tests_still_PASS

If psycopg3 is unavailable on VPS, tests may use an enhanced fake connection that enforces transaction state rules. Do not connect to production.

Git SSOT / Hardcode Control

repo: /opt/incomex/dot
vps_is_code_SSOT: true
must_use_scoped_git_add: true
never_git_add_A: true
must_commit_before_phase_close: true
must_not_commit_unrelated_WIP: true
completion_report_must_include:
  - branch
  - parent_commit
  - new_commit_hash
  - files_changed
  - git_status_short_scoped_iu_cutter
  - test_command_and_result
  - no_hardcode_static_grep_result

Still Forbidden

forbidden:
  - PG_backed_dry_run_rerun_before_code_PASS
  - production_connection
  - production_secret_read
  - production_row_write
  - production_CUT_VERIFY
  - deploy_or_restart
  - schema_migration
  - index_DDL
  - JSONB_normalization
  - vector_integration

Status

ready_for_adapter_txn_lifecycle_fix_prompt: true
agent_self_advance_to_dry_run_after_fix: prohibited_without_GPT_code_review
Back to Knowledge Hub knowledge/dev/laws/dieu44-trien-khai/reviews/dot-iu-cutter-v0.4-pg-backed-dry-run-adapter-txn-defect-gpt-review-2026-05-17.md