/** SQL statements for the fenced resolution-command state machine. */ export { FENCE_EXISTS_SQL } from "@hikoutei/ikisaki"; export declare const FIND_EXISTING_COMMAND_SQL = "\n SELECT command_id, request_key, action, actor_id, role, target_conflict_id,\n expected_revision, active_candidate_hash, expected_candidate_epoch,\n payload_hash, status\n FROM resolution_command\n WHERE command_id = ? OR request_key = ?\n"; export declare const READ_CONFLICT_SQL = "\n SELECT conflict_id, conflict_group_id, event_id, row_binding_id, entity_id, field_name,\n user_value, user_base_revision, canonical_value_at_detection,\n canonical_revision_at_detection, current_canonical_value,\n current_canonical_revision, candidate_epoch,\n candidate_visible_revision, candidate_visible_hash,\n status, resolution_command_id\n FROM sync_conflict\n WHERE logical_sheet_id = ? AND conflict_id = ?\n"; /** * Reads conflict ids that carry a durable pending resolution command for one * logical sheet. `resolution_command` has no logical-sheet column, so the * conflict table supplies the scope through the command's target. */ export declare const READ_PENDING_CONFLICT_IDS_SQL = "\n SELECT DISTINCT c.conflict_id AS conflict_id\n FROM resolution_command rc\n JOIN sync_conflict c ON c.conflict_id = rc.target_conflict_id\n WHERE c.logical_sheet_id = ? AND rc.status = 'pending'\n ORDER BY c.conflict_id\n"; /** Reads every durable pending command targeting one conflict. */ export declare const READ_PENDING_COMMANDS_FOR_CONFLICT_SQL = "\n SELECT command_id, request_key, action, actor_id, role, target_conflict_id,\n expected_revision, active_candidate_hash, expected_candidate_epoch,\n payload_hash, status\n FROM resolution_command\n WHERE target_conflict_id = ? AND status = 'pending'\n ORDER BY command_id\n"; /** Marks one durable pending command stale idempotently (status guarded). */ export declare const MARK_PENDING_COMMAND_STALE_SQL = "\n UPDATE resolution_command\n SET status = 'stale'\n WHERE command_id = ? AND status = 'pending'\n AND EXISTS (\n SELECT 1 FROM writer_lease\n WHERE role = ? AND writer_epoch = ? AND fencing_token = ? AND lease_until > ?\n)\n"; /** * Stales every pending automatic command superseded by a newer resolution * identity. * * Only the latest automatic generation for a conflict may stay pending; older * generations are obsolete the moment a newer canonical revision is planned. * Manual or unknown pending commands are never superseded by polling-owned * planning: actor, action, and identity prefix must all match one of the two * automatic identities (retired legacy `sync:auto-system-wins` and current * implicit `sync:system-wins`). */ export declare const STALE_SUPERSEDED_PENDING_COMMANDS_SQL = "\n UPDATE resolution_command\n SET status = 'stale'\n WHERE target_conflict_id = ? AND command_id != ? AND status = 'pending'\n AND action = 'acknowledge_system'\n AND (\n (actor_id = 'sync:system-wins' AND command_id LIKE 'sync:system-wins:%')\n OR (actor_id = 'sync:auto-system-wins' AND command_id LIKE 'auto-system-wins:%')\n )\n AND EXISTS (\n SELECT 1 FROM writer_lease\n WHERE role = ? AND writer_epoch = ? AND fencing_token = ? AND lease_until > ?\n)\n"; /** Rebases an unresolved conflict to the current canonical field state. */ export declare const REBASE_ACTIVE_CONFLICT_SQL = "\n UPDATE sync_conflict\n SET current_canonical_value = ?, current_canonical_revision = ?,\n status = 'NEEDS_REBASE', last_rebased_commit_id = ?, updated_at = ?\n WHERE conflict_id = ?\n AND status IN ('OPEN', 'NEEDS_REBASE')\n AND EXISTS (\n SELECT 1 FROM writer_lease\n WHERE role = ? AND writer_epoch = ? AND fencing_token = ? AND lease_until > ?\n)\n"; export declare const READ_ACTIVE_CANDIDATE_POINTER_SQL = "\n SELECT physical_sheet_id, projection, candidate_epoch, active_candidate_hash\n FROM sheet_visible_field_state\n WHERE row_binding_id = ? AND field_name = ?\n AND active_candidate_conflict_id = ?\n AND active_candidate_hash IS NOT NULL\n"; export declare const INSERT_PROCESSING_COMMAND_SQL = "\n INSERT INTO resolution_command (\n command_id, request_key, action, actor_id, role, target_conflict_id,\n expected_revision, active_candidate_hash, expected_candidate_epoch,\n payload_hash, status, issued_at\n )\n SELECT ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'processing', ?\n WHERE EXISTS (\n SELECT 1 FROM writer_lease\n WHERE role = ? AND writer_epoch = ? AND fencing_token = ? AND lease_until > ?\n)\n"; /** Records a deferred automatic resolution without claiming it for execution. */ export declare const INSERT_PENDING_COMMAND_SQL = "\n INSERT INTO resolution_command (\n command_id, request_key, action, actor_id, role, target_conflict_id,\n expected_revision, active_candidate_hash, expected_candidate_epoch,\n payload_hash, status, issued_at\n )\n SELECT ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'pending', ?\n WHERE NOT EXISTS (\n SELECT 1 FROM resolution_command\n WHERE command_id = ? OR request_key = ?\n )\n AND EXISTS (\n SELECT 1 FROM writer_lease\n WHERE role = ? AND writer_epoch = ? AND fencing_token = ? AND lease_until > ?\n)\n"; /** Promotes a durable deferred command only after its predecessor is gone. */ export declare const MARK_PENDING_COMMAND_PROCESSING_SQL = "\n UPDATE resolution_command\n SET status = 'processing'\n WHERE command_id = ? AND request_key = ? AND status = 'pending'\n AND EXISTS (\n SELECT 1 FROM writer_lease\n WHERE role = ? AND writer_epoch = ? AND fencing_token = ? AND lease_until > ?\n)\n"; export declare const MARK_CONFLICT_RESOLVED_SQL = "\n UPDATE sync_conflict\n SET status = 'RESOLVED', resolution_command_id = ?, updated_at = ?\n WHERE conflict_id = ? AND status IN ('OPEN', 'NEEDS_REBASE')\n AND current_canonical_revision = ? AND candidate_epoch = ?\n AND EXISTS (\n SELECT 1 FROM writer_lease\n WHERE role = ? AND writer_epoch = ? AND fencing_token = ? AND lease_until > ?\n)\n"; export declare const CLEAR_ACTIVE_CANDIDATE_POINTER_SQL = "\n UPDATE sheet_visible_field_state\n SET active_candidate_conflict_id = NULL, active_candidate_hash = NULL,\n candidate_epoch = candidate_epoch + 1\n WHERE physical_sheet_id = ? AND projection = ?\n AND row_binding_id = ? AND field_name = ?\n AND active_candidate_conflict_id = ? AND candidate_epoch = ?\n AND EXISTS (\n SELECT 1 FROM writer_lease\n WHERE role = ? AND writer_epoch = ? AND fencing_token = ? AND lease_until > ?\n)\n"; export declare const ADVANCE_ROW_BINDING_CANDIDATE_EPOCH_SQL = "\n UPDATE row_binding\n SET candidate_epoch = CASE\n WHEN candidate_epoch <= ? THEN ?\n ELSE candidate_epoch\n END\n WHERE row_binding_id = ? AND logical_sheet_id = ?\n AND EXISTS (\n SELECT 1 FROM writer_lease\n WHERE role = ? AND writer_epoch = ? AND fencing_token = ? AND lease_until > ?\n)\n"; /** * Supersedes pending User_Input candidate_reconcile rewrites for one row * binding the moment the conflict that owned the row resolves. * * Cleanup scans now stream bound-row rewrites under the binding key * (`projection-row::`), so the resolution's own * supersede-and-replan covers them. This statement is the safety net for * LEGACY anchor-keyed rewrites (`target_id` = physical anchor) that were * already durable before that change (or were enqueued by an older scan): * the resolution's normal replan lookup never sees them, and the worker * candidate gate blocks them only while the conflict stays OPEN or * NEEDS_REBASE. Once a resolution command applies, the gate opens and a * stale rewrite would otherwise deliver (it was enqueued before the * resolution's own fresh reconcile, whose visible-hash CAS it then breaks) * and overwrite the row with a stale value. The resolution's reconcile is * now authoritative for the row, so any such pending rewrite is superseded * in the same transaction. Only non-terminal `pending` rewrites are touched: * in-flight (`processing`/`delivery_uncertain`) writes are left to settle * and `blocked_candidate` heads are already terminal and converge through a * later re-scan. */ export declare const SUPERSEDE_PENDING_USER_INPUT_REWRITES_SQL = "\n UPDATE sheet_effect_outbox\n SET status = 'superseded', supersedes_effect_id = ?\n WHERE logical_sheet_id = ?\n AND projection = 'user_input'\n AND effect_kind = 'candidate_reconcile'\n AND row_binding_id = ?\n AND effect_id != ?\n AND status = 'pending'\n AND EXISTS (\n SELECT 1 FROM writer_lease\n WHERE role = ? AND writer_epoch = ? AND fencing_token = ? AND lease_until > ?\n)\n"; export declare const MARK_COMMAND_APPLIED_SQL = "\n UPDATE resolution_command\n SET status = 'applied', applied_commit_id = ?\n WHERE command_id = ? AND status = 'processing'\n AND EXISTS (\n SELECT 1 FROM writer_lease\n WHERE role = ? AND writer_epoch = ? AND fencing_token = ? AND lease_until > ?\n)\n"; export declare const MARK_CONFLICT_STALE_SQL = "\n UPDATE sync_conflict\n SET status = ?, updated_at = ?\n WHERE conflict_id = ? AND status IN ('OPEN', 'NEEDS_REBASE')\n AND EXISTS (\n SELECT 1 FROM writer_lease\n WHERE role = ? AND writer_epoch = ? AND fencing_token = ? AND lease_until > ?\n)\n"; export declare const MARK_COMMAND_STALE_SQL = "\n UPDATE resolution_command\n SET status = 'stale'\n WHERE command_id = ? AND status = 'processing'\n AND EXISTS (\n SELECT 1 FROM writer_lease\n WHERE role = ? AND writer_epoch = ? AND fencing_token = ? AND lease_until > ?\n)\n"; export declare const MARK_COMMAND_REJECTED_SQL = "\n UPDATE resolution_command\n SET status = 'rejected'\n WHERE command_id = ? AND status = 'processing'\n AND EXISTS (\n SELECT 1 FROM writer_lease\n WHERE role = ? AND writer_epoch = ? AND fencing_token = ? AND lease_until > ?\n)\n"; export declare const READ_EFFECT_DEDUPE_SQL = "\n SELECT effect_kind, commit_id, logical_sheet_id, physical_sheet_id,\n projection, target_kind, target_id, payload_hash\n FROM sheet_effect_outbox\n WHERE effect_dedupe_key = ?\n"; export declare const READ_REGISTERED_PROJECTION_SQL = "\n SELECT logical_sheet_id, projection, enabled\n FROM physical_sheet_registry\n WHERE physical_sheet_id = ?\n"; /** * Finds an in-flight predecessor that could still materialize after a * replacement. `delivery_uncertain` counts as in-flight because the remote * write may still commit after a lost response; resolution successors must * wait until that predecessor is probe-settled. */ export declare const READ_PROCESSING_PREDECESSOR_SQL = "\n SELECT effect_id\n FROM sheet_effect_outbox\n WHERE logical_sheet_id = ? AND target_kind = ? AND target_id = ?\n AND stream_sequence < ? AND status IN ('processing', 'delivery_uncertain')\n ORDER BY stream_sequence\n LIMIT 1\n"; //# sourceMappingURL=resolutionWriterSql.d.ts.map