Skip to main content

Module transaction_sentinel

Module transaction_sentinel 

Source
Expand description

Transaction sentinel detection for the dispatch path.

Every state-changing CLI verb should consult active_transactions before executing. When the answer is non-empty, the verb is running against a repo with one or more open transactions; the verb should either (a) refuse to mutate (the conservative shipping shape), or (b) append itself to the sentinel’s buffered_ops and defer.

This module ships only the detection primitive — recording each verb into the sentinel’s buffered_ops list (and replaying them at commit) is the larger follow-on the local transaction service already flags with TODO(transaction-replay).

Sentinel files live at <heddle_dir>/state/transactions/<id>.toml (the same path the local TransactionService uses), so the detection here is consistent with the gRPC view.

Structs§

ActiveTransaction
One open transaction, hydrated from its on-disk sentinel. Field names match the writer in crates/daemon/src/grpc_local_impl/transaction.rs::TransactionSentinel — keep this struct in sync if the writer’s shape changes. The Serialize impl is used by append_op_to_active_for_thread to rewrite the sentinel after appending a buffered op.

Functions§

active_for_thread
Return the active transaction whose thread matches thread_name, if any. Used by state-changing verbs that target a specific thread: the verb should either route into that transaction’s buffer (full wiring is follow-on work) or refuse to proceed (today’s shape).
active_transactions
Walk the sentinel directory and return every transaction whose state is still "active". Returns an empty vec when the directory is missing (no transactions ever started in this repo).
append_op_to_active_for_thread
Append verb_name to the buffered_ops list of every active transaction whose thread matches thread_name. Returns the transaction ids that were updated. Errors are tracing-warned and swallowed — buffering is best-effort metadata; the verb still executes regardless.
buffered_for_thread
Convenience wrapper for the common “did this verb get buffered?” question. Calls append_op_to_active_for_thread and returns true when at least one open transaction on thread_name recorded the verb. Useful for the dispatch path: when buffering occurs, the surrounding verb can short-circuit the actual mutation (the strict “buffer-instead-of-execute” mode the transaction contract calls for).