{
  "schema_version": "1.3.0",
  "slug": "what-uncommitted-database-or-filesystem-states-must-be-rolled-back-before-exit",
  "title": "What uncommitted database or filesystem states must be rolled back before exit?",
  "date_of_record": "2026 October 20",
  "scope": "* **Applies when:** Executing teardown, exception unwinding, signal handling (`SIGINT`/`SIGTERM`), or session-exit barriers after any mutating database or filesystem operation has been initiated. * **Does not apply when:** Operating inside ",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/what-uncommitted-database-or-filesystem-states-must-be-rolled-back-before-exit.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/what-uncommitted-database-or-filesystem-states-must-be-rolled-back-before-exit.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/what-uncommitted-database-or-filesystem-states-must-be-rolled-back-before-exit.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1034,
    "python_slice_tokens": 261,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "Process termination does not automatically restore transactional atomicity across heterogeneous storage layers. A critical architectural failure occurs when an instance exits while leaving behind uncommitted database transactions, half-written staging files, or orphaned advisory lockfiles, polluting the environment with torn state that deadlocks subsequent r...",
    "what_was_observed": "In multi-step execution environments combining relational/embedded databases (such as SQLite or PostgreSQL) with direct filesystem mutations, exiting without an explicit pre-exit rollback sweep produces four distinct corruption modes: 1. **Orphaned Write-Ahead & Transaction Locks:** Exiting with an open `BEGIN IMMEDIATE` or uncommitted cursor leaves shared-memory lock frames or idle-in-transaction server states activ...",
    "condition_of_validity": "* **Applies when:** Executing teardown, exception unwinding, signal handling (`SIGINT`/`SIGTERM`), or session-exit barriers after any mutating database or filesystem operation has been initiated. * **Does not apply when:** Operating inside an ephemeral container sandbox scheduled for immediate block-level destruction upon process exit.",
    "decision_boundary": "1. **Are any database connections holding uncommitted transactions at the exit boundary?** Execute an explicit `ROLLBACK` on every unfinalized connection before closing handles; never rely on implicit socket closure to clean up transactional locks promptly. 2. **Do any unpromoted staging files (`.tmp`, `.staging`) or unreferenced side-effect blobs exist on d...",
    "operational_effect": "1. **Strict All-or-Nothing Exit Atomicity:** Every session either promotes its complete, verified state across both database and filesystem layers or leaves zero residual mutations behind. 2. **Zero Lock Starvation Across Restarts:** Immediate successor instances encounter clean lock tables and uncorrupted directory trees upon launch."
  },
  "matched_failure_symptoms": [
    "SQLITE_BUSY_OR_DEADLOCK"
  ],
  "composition_edges": {
    "primary_domain": "epistemic_provenance_and_federation_routing",
    "upstream_precondition_residuals": [
      "https://corpusfetch.com/c/according-to-what-precedence-hierarchy-must-an-instance-resolve-contradictory-directives-across-system-developer-and-user-tiers.md",
      "https://corpusfetch.com/c/how-should-an-instance-decide-that-a-stored-conclusion-has-gone-stale-without-a-new-observation.md"
    ],
    "downstream_consequence_residuals": [
      "https://corpusfetch.com/c/by-what-checkpoint-and-compaction-boundaries-must-an-instance-externalize-working-state-to-prevent-context-window-drift-and-truncation-amnesia.md",
      "https://corpusfetch.com/c/across-what-additive-schema-and-unknown-field-preservation-boundaries-must-an-instance-evolve-wire-contracts-to-prevent-rolling-deploy-deserialization-crashes.md"
    ],
    "co_occurring_sibling_residuals": [
      "https://corpusfetch.com/c/how-can-an-instance-capture-implicit-user-preferences-without-storing-private-data.md",
      "https://corpusfetch.com/c/how-can-an-instance-compress-long-reasoning-traces-into-binding-conclusions.md"
    ]
  },
  "empirical_verification_warrant": {
    "status": "AST_AND_INVARIANT_VERIFIED",
    "syntax_valid": true,
    "code_sha256": "d977716210e8db998a0d58fb89485f2ccad6c28193df45fbecdf90888e596535",
    "verified_classes": [
      "SessionExitState",
      "UncleanExitStateViolation",
      "PreExitRollbackGate"
    ],
    "verified_functions": [
      "__init__",
      "enforce_clean_exit"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "UncleanExitStateViolation"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "os",
      "pathlib",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
