Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:2giosangmitom Sqmeow nvim Transactional Apply

From Leeroopedia
Knowledge Sources
Domains Editing, Cancellation
Last Updated 2026-10-16 14:00 GMT

Overview

A transactional application principle that executes approved DML statements atomically, with cancellation safety ensuring that cancelled writes report their actual outcome rather than an assumed rollback.

Description

Transactional Apply is the principle of running planned DML statements as a unit where the dialect supports transactions, and reporting the outcome honestly. Cancellation must not interrupt a commit: Cancelled means no changes were committed (for transactional dialects). Adapters without transactions report partial application as a driver error, so callers do not mistake partial writes for a complete rollback.

This principle addresses the challenge of safely applying edits with cancellation support: a user may cancel mid-apply, but a write already sent to the database may have committed. The adapter must report the actual outcome — a sent write's success is observed even after cancel. The await_sent helper ensures a sent non-transactional write keeps its success after cancel; cancellation stops the next write, not the observation of this one's outcome.

For non-transactional dialects (Redis, MongoDB, Scylla), cancelled_after(done, total) reports how many changes were applied before the rest were cancelled, so the user knows the partial state.

Usage

Use this principle when applying edits to a database: wrap in a transaction where supported, report actual outcomes on cancellation, and never assume rollback for non-transactional backends.

Theoretical Basis

The principle separates sent-write observation from cancellation:

  1. Transaction: Where the dialect supports transactions, statements run in a single transaction. Cancellation before commit means nothing was applied; cancellation during commit reports the actual outcome.
  2. Non-transactional: Each statement runs independently. A sent write's outcome is observed even after cancel. The helper cancelled_after(done, total) reports partial application.
  3. Deadline: A Deadline trips the cancel token after timeout_ms. If the deadline (not a user cancel) tripped, the error says "ran past the timeout."
# Abstract pattern (NOT real implementation):
async def apply(statements, cancel_token):
    if dialect_supports_transactions:
        return await transactional_execute(statements, cancel_token)
    else:
        done = 0
        for stmt in statements:
            if cancel_token.cancelled: return cancelled_after(done, len(statements))
            await execute(stmt)  # observe outcome even if cancelled during
            done += 1
        return all_results

# A sent write keeps its success after cancel:
async def await_sent(cancel, work):
    if cancel.is_cancelled: raise Cancelled  # before send
    return await work  # observe outcome even if cancelled during

Related Pages

Implemented By

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment