Commit 17113b1dfb9 for woocommerce

commit 17113b1dfb92066b0c1e77af2899e6dec5abc349
Author: Barry Hughes <3594411+barryhughes@users.noreply.github.com>
Date:   Wed Nov 25 10:55:31 2026 -0700

    Subscriptions engine: append-only contract history (#71419)

    * Add the contract history table and HistoryEntry entity to the subscriptions engine

    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

    * Add contract history storage to the subscriptions engine repository

    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

    * Add the contract history facade methods and view to the subscriptions engine

    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

    * Add a changelog entry and README notes for subscriptions engine contract history

    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

    * Tidy subscriptions engine contract history after review

    Fence a locked history insert with fence_child_write() like the other child
    writes, drop the unused HistoryEntry::get_creation_key() and the locked-only
    message variant of the target-not-found error, and encode the payload once,
    in the repository with wp_json_encode(), as plans and snapshots do.

    Cover the insert failure branches (with and without a lock or a creation key,
    and a lock lost meanwhile), the creation-key fallback read, the owner slug
    check on add_history_entry(), and a read of another extension's history.

    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

    * Return a history entry with the payload as stored

    The entry returned by add_history_entry() is hydrated from the encoded JSON, so a nested object in the payload comes back as an array, the same as a later read.

    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

    ---------

    Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

diff --git a/packages/php/woocommerce-subscriptions-engine/README.md b/packages/php/woocommerce-subscriptions-engine/README.md
index 1c1b4529fda..b214a57c6cc 100644
--- a/packages/php/woocommerce-subscriptions-engine/README.md
+++ b/packages/php/woocommerce-subscriptions-engine/README.md
@@ -6,6 +6,7 @@ The engine records subscription facts (plans, contracts, billing cycles) and off

 - **Due dispatch:** an extension registers a contract due handler with its slug, and the engine calls it when one of its contracts reaches its next due moment, passing the dispatcher's contract lock. What happens then (renew, skip, clear the due moment) is the extension's decision.
 - **Ownership:** every plan and contract records its owning extension (`extension_slug`). Reads work across extensions. Every write names the expected owner, the row's owning extension (also when acting for that extension, for example a listener writing with the owner's lock passes the contract's `extension_slug`), and never touches a row of another extension: such a row reads as missing to the write. This guards against writing another extension's row by mistake; it is not authorization. `Plans::update()`, `Contracts::update()`, `add_cycle()` and `transition_cycle()` take `extension_slug` in their arguments; `Contracts::lock()` and the contract and plan meta writes take it as their second parameter, for example `Contracts::lock( $contract_id, $extension_slug, $operation )` and `Plans::add_meta( $plan_id, $extension_slug, $key, $value )`.
-- **Contract lock:** one lock per contract on the facade. `Contracts::lock( $contract_id, $extension_slug, $operation )` takes it for an operation (null when another operation holds it or no contract of that extension has the id) and `Contracts::create()` creates every contract locked from birth (null when its optional creation key is taken); every write takes the lock as its last parameter. Every write runs under a lock: the caller's, or, for an update or meta write made without one, an internal lock the engine takes for that call. Every contract write is owner-scoped where its lock is taken, and no write path skips the lock. Cycle writes require the caller's lock. A write is refused with `ContractLockedException` while another operation holds the lock, and with `InvalidArgumentException` when it names an owner other than its lock's.
+- **Contract lock:** one lock per contract on the facade. `Contracts::lock( $contract_id, $extension_slug, $operation )` takes it for an operation (null when another operation holds it or no contract of that extension has the id) and `Contracts::create()` creates every contract locked from birth (null when its optional creation key is taken); every write takes the lock as its last parameter. Every write runs under a lock: the caller's, or, for an update or meta write made without one, an internal lock the engine takes for that call. Every contract write is owner-scoped where its lock is taken. Cycle writes require the caller's lock. A write is refused with `ContractLockedException` while another operation holds the lock, and with `InvalidArgumentException` when it names an owner other than its lock's. One exception: a history entry added without a lock is a plain owner-scoped insert that no held lock refuses (see below).
+- **Contract history:** `Contracts::add_history_entry( $contract_id, $args, $lock )` records an entry the owning extension writes on its own command: a `type` slug it chooses, an optional cycle of the contract, an opaque JSON `payload` and an optional `creation_key` that makes the add idempotent per contract (null when taken). `Contracts::get_history( $contract_id, $args )` reads entries newest first. The engine writes no entries itself and gives types and payloads no meaning. With the caller's lock the write is fenced by it; without one it is never blocked by a lock another operation holds.
 - **Cycle tools:** cycle appends are append-if-absent on the chain's positions, and status transitions are compare-and-set.
 - **Payments broker:** `Api\Payments` lets an extension ask the order's gateway to take a scheduled payment off-session (`Payments::process_scheduled_payment( $order )`). Gateways opt in by adding the `subscriptions_engine` feature to their `$supports` and charging the order on `woocommerce_subscriptions_engine_scheduled_payment_{gateway_id}( $order )`, reporting the outcome through the order status. What a gateway can do beyond that (renewal payments, payment method changes, ...) it declares with the existing WooCommerce gateway features; extensions check the ones an operation needs with `Payments::gateway_supports( $gateway_id, $features )`, and the engine does not interpret them.
diff --git a/packages/php/woocommerce-subscriptions-engine/changelog/add-subscriptions-engine-contract-history b/packages/php/woocommerce-subscriptions-engine/changelog/add-subscriptions-engine-contract-history
new file mode 100644
index 00000000000..6b4f93faf40
--- /dev/null
+++ b/packages/php/woocommerce-subscriptions-engine/changelog/add-subscriptions-engine-contract-history
@@ -0,0 +1,3 @@
+Significance: patch
+Type: dev
+Comment: Add contract history storage and facade methods to the unreleased subscriptions engine; no changelog entry needed.
diff --git a/packages/php/woocommerce-subscriptions-engine/src/Api/Contracts.php b/packages/php/woocommerce-subscriptions-engine/src/Api/Contracts.php
index 4b7da8b1e73..f9deca903c7 100644
--- a/packages/php/woocommerce-subscriptions-engine/src/Api/Contracts.php
+++ b/packages/php/woocommerce-subscriptions-engine/src/Api/Contracts.php
@@ -12,9 +12,10 @@
  *
  * One lock per contract ({@see self::lock()}): every write runs under a lock, the caller's or,
  * for an update or meta write made without one, an internal one the engine takes for that call.
- * Every contract write is owner-scoped where its lock is taken, and no write path skips the lock.
- * Cycle writes require the caller's lock. A write is refused with {@see ContractLockedException}
- * while another operation holds the lock.
+ * Every contract write is owner-scoped where its lock is taken. Cycle writes require the caller's
+ * lock. A write is refused with {@see ContractLockedException} while another operation holds the
+ * lock. One exception: a history entry ({@see self::add_history_entry()}) is fenced by the caller's
+ * lock when one is passed, and is otherwise a plain owner-scoped insert that no held lock refuses.
  *
  * @package Automattic\WooCommerce\SubscriptionsEngine\Api
  */
@@ -26,8 +27,10 @@ namespace Automattic\WooCommerce\SubscriptionsEngine\Api;
 use InvalidArgumentException;
 use Automattic\WooCommerce\SubscriptionsEngine\Api\View\ContractView;
 use Automattic\WooCommerce\SubscriptionsEngine\Api\View\CycleView;
+use Automattic\WooCommerce\SubscriptionsEngine\Api\View\HistoryEntryView;
 use Automattic\WooCommerce\SubscriptionsEngine\Core\Entity\Contract;
 use Automattic\WooCommerce\SubscriptionsEngine\Core\Entity\Cycle;
+use Automattic\WooCommerce\SubscriptionsEngine\Core\Entity\HistoryEntry;
 use Automattic\WooCommerce\SubscriptionsEngine\Core\Support\ArgumentValidator;
 use Automattic\WooCommerce\SubscriptionsEngine\Core\Support\InvalidInputException;
 use Automattic\WooCommerce\SubscriptionsEngine\Core\Support\ValidationErrorCode;
@@ -135,6 +138,30 @@ final class Contracts {
 		'reason'         => true,
 	);

+	/**
+	 * Keys accepted by {@see self::add_history_entry()}, as a key map: the `extension_slug` that
+	 * scopes the write (not an entry field) and the entry fields.
+	 *
+	 * @var array<string, true>
+	 */
+	private const HISTORY_ENTRY_KEYS = array(
+		'extension_slug' => true,
+		'type'           => true,
+		'cycle_id'       => true,
+		'payload'        => true,
+		'creation_key'   => true,
+	);
+
+	/**
+	 * Keys accepted by {@see self::get_history()}, as a key map.
+	 *
+	 * @var array<string, true>
+	 */
+	private const HISTORY_READ_KEYS = array(
+		'limit'  => true,
+		'offset' => true,
+	);
+
 	/**
 	 * Keys accepted by {@see self::list_for_customer()}, as a key map.
 	 *
@@ -729,7 +756,90 @@ final class Contracts {
 			throw ValidationException::from_core( $e ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- from_core() escapes the message.
 		}

-		return self::cycle_views( ( new ContractRepository() )->find_cycle_history( $contract_id, Cycle::KIND_BILLING, $limit, $offset ) );
+		return self::cycle_views( ( new ContractRepository() )->find_cycles( $contract_id, Cycle::KIND_BILLING, $limit, $offset ) );
+	}
+	// phpcs:enable Squiz.Commenting.FunctionCommentThrowTag.WrongNumber
+
+	// phpcs:disable Squiz.Commenting.FunctionCommentThrowTag.WrongNumber -- @throws also lists exceptions raised by the methods called.
+	/**
+	 * Add an entry to a contract's history: a record the owning extension writes on its own command.
+	 * The engine writes no entries itself and gives types and payloads no meaning; the history table
+	 * is its generic per-contract record store, history being its first use. With `$lock` the write is
+	 * fenced by it; without one it is a plain owner-scoped insert that no held lock refuses. A taken
+	 * `creation_key` is a lost race and returns null. Unknown keys get `_doing_it_wrong()`.
+	 *
+	 * @param int                  $contract_id Contract id.
+	 * @param array<string, mixed> $args        `extension_slug` (required, the expected owner), `type`
+	 *                                          (required, 1-64 of `[a-z0-9_-]`), `cycle_id` (a cycle of
+	 *                                          this contract), `payload` (array, stored as JSON) and
+	 *                                          `creation_key` (1-100 characters, trimmed, unique per contract).
+	 * @param ContractLock|null    $lock        The caller's lock on this contract, or null for an unlocked insert.
+	 * @return HistoryEntryView|null The new entry; null when the creation key is taken.
+	 * @throws ValidationException      If a required key is missing or a value is invalid, every error reported.
+	 * @throws InvalidArgumentException If no contract of that extension has the id, the cycle is not one of
+	 *                                  this contract's, or the lock is for another contract or extension.
+	 * @throws ContractLockedException  If `$lock` was passed and has been lost.
+	 * @throws \RuntimeException        If the write fails.
+	 */
+	public static function add_history_entry( int $contract_id, array $args, ?ContractLock $lock = null ): ?HistoryEntryView {
+		$filtered_args = ArgumentFilter::filter_known_keys( __METHOD__, $args, self::HISTORY_ENTRY_KEYS );
+
+		$validator      = new ArgumentValidator();
+		$extension_slug = (string) $validator->get_extension_slug( 'extension_slug', $filtered_args['extension_slug'] ?? null );
+		$entry_args     = array(
+			'contract_id'  => $contract_id,
+			'type'         => $validator->get_slug( 'type', $filtered_args['type'] ?? null ),
+			'cycle_id'     => $validator->get_nullable_id( 'cycle_id', $filtered_args['cycle_id'] ?? null ),
+			'payload'      => $validator->get_nullable_array( 'payload', $filtered_args['payload'] ?? null ),
+			'creation_key' => $validator->get_nullable_string( 'creation_key', $filtered_args['creation_key'] ?? null ),
+		);
+		try {
+			$validator->throw_errors();
+			$entry = HistoryEntry::create( $entry_args );
+		} catch ( InvalidInputException $e ) {
+			throw ValidationException::from_core( $e ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- from_core() escapes the message.
+		}
+
+		$stored = ( new ContractRepository() )->add_history_entry( $entry, $extension_slug, $lock );
+		if ( null === $stored ) {
+			return null;
+		}
+
+		return HistoryEntryView::from_entry( $stored );
+	}
+	// phpcs:enable Squiz.Commenting.FunctionCommentThrowTag.WrongNumber
+
+	// phpcs:disable Squiz.Commenting.FunctionCommentThrowTag.WrongNumber -- @throws also lists exceptions raised by the methods called.
+	/**
+	 * A window of a contract's history, newest first. Reads work across extensions. Unknown keys
+	 * get `_doing_it_wrong()`.
+	 *
+	 * @param int                  $contract_id Contract id.
+	 * @param array<string, mixed> $args        `limit` (default 20) and `offset` (default 0), non-negative.
+	 * @return array<int, HistoryEntryView> Entries newest first; empty for an unknown contract.
+	 * @throws ValidationException If `limit` or `offset` is invalid, both reported.
+	 * @throws \RuntimeException   If the read fails.
+	 */
+	public static function get_history( int $contract_id, array $args = array() ): array {
+		$filtered_args = ArgumentFilter::filter_known_keys( __METHOD__, $args, self::HISTORY_READ_KEYS );
+
+		$validator = new ArgumentValidator();
+		$limit     = (int) $validator->get_non_negative_int( 'limit', $filtered_args['limit'] ?? 20 );
+		$offset    = (int) $validator->get_non_negative_int( 'offset', $filtered_args['offset'] ?? 0 );
+		try {
+			$validator->throw_errors();
+		} catch ( InvalidInputException $e ) {
+			throw ValidationException::from_core( $e ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- from_core() escapes the message.
+		}
+
+		$entries = ( new ContractRepository() )->find_history( $contract_id, $limit, $offset );
+
+		return array_map(
+			static function ( HistoryEntry $entry ): HistoryEntryView {
+				return HistoryEntryView::from_entry( $entry );
+			},
+			$entries
+		);
 	}
 	// phpcs:enable Squiz.Commenting.FunctionCommentThrowTag.WrongNumber

diff --git a/packages/php/woocommerce-subscriptions-engine/src/Api/View/HistoryEntryView.php b/packages/php/woocommerce-subscriptions-engine/src/Api/View/HistoryEntryView.php
new file mode 100644
index 00000000000..6fade3b139e
--- /dev/null
+++ b/packages/php/woocommerce-subscriptions-engine/src/Api/View/HistoryEntryView.php
@@ -0,0 +1,134 @@
+<?php
+/**
+ * HistoryEntryView - a read-only view of a contract history entry at the `Api\` boundary.
+ *
+ * Consumers read history entries through this view instead of the Core entity. Getters may be
+ * added, never removed.
+ *
+ * @package Automattic\WooCommerce\SubscriptionsEngine\Api\View
+ */
+
+declare( strict_types=1 );
+
+namespace Automattic\WooCommerce\SubscriptionsEngine\Api\View;
+
+use Automattic\WooCommerce\SubscriptionsEngine\Core\Entity\HistoryEntry;
+
+defined( 'ABSPATH' ) || exit;
+
+/**
+ * Immutable history entry view.
+ */
+final class HistoryEntryView {
+
+	/**
+	 * Entry id.
+	 *
+	 * @var int
+	 */
+	private $id;
+
+	/**
+	 * Contract id.
+	 *
+	 * @var int
+	 */
+	private $contract_id;
+
+	/**
+	 * Cycle id, or null.
+	 *
+	 * @var int|null
+	 */
+	private $cycle_id;
+
+	/**
+	 * The extension's type slug.
+	 *
+	 * @var string
+	 */
+	private $type;
+
+	/**
+	 * The extension's payload, or null.
+	 *
+	 * @var array<int|string, mixed>|null
+	 */
+	private $payload;
+
+	/**
+	 * When the engine stored the entry (GMT `Y-m-d H:i:s`).
+	 *
+	 * @var string
+	 */
+	private $date_created_gmt;
+
+	/**
+	 * Use {@see self::from_entry()}.
+	 */
+	private function __construct() {
+	}
+
+	/**
+	 * Build a view of a stored entry.
+	 *
+	 * @internal Built by the engine `Api\` facades only.
+	 *
+	 * @param HistoryEntry $entry Stored entry.
+	 */
+	public static function from_entry( HistoryEntry $entry ): self {
+		$view                   = new self();
+		$view->id               = (int) $entry->get_id();
+		$view->contract_id      = $entry->get_contract_id();
+		$view->cycle_id         = $entry->get_cycle_id();
+		$view->type             = $entry->get_type();
+		$view->payload          = $entry->get_payload();
+		$view->date_created_gmt = (string) $entry->get_date_created_gmt();
+
+		return $view;
+	}
+
+	/**
+	 * Entry id.
+	 */
+	public function get_id(): int {
+		return $this->id;
+	}
+
+	/**
+	 * Contract id.
+	 */
+	public function get_contract_id(): int {
+		return $this->contract_id;
+	}
+
+	/**
+	 * Cycle id, or null.
+	 */
+	public function get_cycle_id(): ?int {
+		return $this->cycle_id;
+	}
+
+	/**
+	 * The extension's type slug.
+	 */
+	public function get_type(): string {
+		return $this->type;
+	}
+
+	/**
+	 * The extension's payload, decoded, or null.
+	 *
+	 * @return array<int|string, mixed>|null
+	 */
+	public function get_payload(): ?array {
+		return $this->payload;
+	}
+
+	/**
+	 * When the engine stored the entry (GMT `Y-m-d H:i:s`).
+	 */
+	public function get_date_created_gmt(): string {
+		return $this->date_created_gmt;
+	}
+}
diff --git a/packages/php/woocommerce-subscriptions-engine/src/Core/Entity/Contract.php b/packages/php/woocommerce-subscriptions-engine/src/Core/Entity/Contract.php
index e8b0975ba2c..8767a8c9c2a 100644
--- a/packages/php/woocommerce-subscriptions-engine/src/Core/Entity/Contract.php
+++ b/packages/php/woocommerce-subscriptions-engine/src/Core/Entity/Contract.php
@@ -879,16 +879,10 @@ final class Contract {
 	 * @param mixed $creation_key Creation key to check.
 	 */
 	private static function get_creation_key_error( $creation_key ): ?InvalidInputException {
-		if ( null === $creation_key ) {
-			return null;
-		}
-
-		if ( ! is_string( $creation_key ) ) {
-			return new InvalidInputException( ValidationErrorCode::INVALID_TYPE, 'creation_key', 'Contract: creation_key must be a string.', array( 'type' => 'string' ) );
-		}
-
-		if ( '' === $creation_key || mb_strlen( $creation_key ) > 100 ) {
-			return new InvalidInputException( ValidationErrorCode::INVALID_VALUE, 'creation_key', 'Contract: creation_key must be 1-100 characters.' );
+		try {
+			ArgumentValidator::validate_creation_key( $creation_key );
+		} catch ( InvalidInputException $e ) {
+			return $e;
 		}

 		return null;
diff --git a/packages/php/woocommerce-subscriptions-engine/src/Core/Entity/HistoryEntry.php b/packages/php/woocommerce-subscriptions-engine/src/Core/Entity/HistoryEntry.php
new file mode 100644
index 00000000000..97944c2d110
--- /dev/null
+++ b/packages/php/woocommerce-subscriptions-engine/src/Core/Entity/HistoryEntry.php
@@ -0,0 +1,252 @@
+<?php
+/**
+ * HistoryEntry - one record in a contract's history, written on the owning extension's command.
+ *
+ * The engine gives an entry no meaning: `type` is a slug the extension chooses and `payload` is
+ * the extension's opaque data, stored as JSON. `cycle_id` optionally names a cycle of the same
+ * contract, and `creation_key` optionally makes the add idempotent per contract. Entries are
+ * immutable: there are no setters, and a stored entry is built with {@see self::from_storage()}.
+ *
+ * @package Automattic\WooCommerce\SubscriptionsEngine\Core\Entity
+ */
+
+declare( strict_types=1 );
+
+namespace Automattic\WooCommerce\SubscriptionsEngine\Core\Entity;
+
+use Automattic\WooCommerce\SubscriptionsEngine\Core\Support\ArgumentValidator;
+use Automattic\WooCommerce\SubscriptionsEngine\Core\Support\Coercion;
+use Automattic\WooCommerce\SubscriptionsEngine\Core\Support\InvalidInputException;
+use Automattic\WooCommerce\SubscriptionsEngine\Core\Support\ValidationErrorCode;
+
+defined( 'ABSPATH' ) || exit;
+
+/**
+ * History entry entity.
+ *
+ * Construct via {@see self::create()} for a new (unsaved) entry or
+ * {@see self::from_storage()} when hydrating a stored row.
+ */
+final class HistoryEntry {
+
+	/**
+	 * Entry id, or null before it is persisted.
+	 *
+	 * @var int|null
+	 */
+	private $id;
+
+	/**
+	 * Contract id.
+	 *
+	 * @var int
+	 */
+	private $contract_id;
+
+	/**
+	 * Cycle id (a cycle of the same contract), or null.
+	 *
+	 * @var int|null
+	 */
+	private $cycle_id;
+
+	/**
+	 * Extension-chosen type slug.
+	 *
+	 * @var string
+	 */
+	private $type;
+
+	/**
+	 * Idempotency key, unique per contract, or null.
+	 *
+	 * @var string|null
+	 */
+	private $creation_key;
+
+	/**
+	 * The extension's opaque payload, or null.
+	 *
+	 * @var array<int|string, mixed>|null
+	 */
+	private $payload;
+
+	/**
+	 * When the engine stored the entry (GMT `Y-m-d H:i:s`), or null before it is persisted.
+	 *
+	 * @var string|null
+	 */
+	private $date_created_gmt;
+
+	/**
+	 * Use {@see self::create()} or {@see self::from_storage()}. Coerces each attribute to its
+	 * property type; unknown keys are ignored, missing keys take the default.
+	 *
+	 * @param array<string, mixed> $data Raw attributes keyed by property name.
+	 */
+	private function __construct( array $data ) {
+		$this->id               = Coercion::coerce_nullable_int( $data['id'] ?? null );
+		$this->contract_id      = Coercion::coerce_int( $data['contract_id'] ?? null );
+		$this->cycle_id         = Coercion::coerce_nullable_int( $data['cycle_id'] ?? null );
+		$this->type             = Coercion::coerce_string( $data['type'] ?? null );
+		$this->creation_key     = Coercion::coerce_nullable_string( $data['creation_key'] ?? null );
+		$this->payload          = is_array( $data['payload'] ?? null ) ? $data['payload'] : null;
+		$this->date_created_gmt = Coercion::coerce_nullable_string( $data['date_created_gmt'] ?? null );
+	}
+
+	/**
+	 * Build a new, unsaved entry. `type` is required (1-64 of `[a-z0-9_-]`); `payload` must be
+	 * JSON-encodable; `creation_key` is 1-100 characters, trimmed. Every invalid attribute is
+	 * reported in one exception.
+	 *
+	 * @param array<string, mixed> $args `contract_id`, `cycle_id`, `type`, `payload`, `creation_key`.
+	 * @throws InvalidInputException If the entry attributes are not valid.
+	 */
+	public static function create( array $args ): self {
+		// A new entry is always unsaved; the engine sets the id and the creation time on insert.
+		unset( $args['id'], $args['date_created_gmt'] );
+
+		// The key column ignores trailing spaces when comparing, so they never tell keys apart.
+		if ( isset( $args['creation_key'] ) && is_string( $args['creation_key'] ) ) {
+			$args['creation_key'] = trim( $args['creation_key'] );
+		}
+
+		$errors = array_filter(
+			array(
+				self::get_type_error( $args['type'] ?? null ),
+				self::get_creation_key_error( $args['creation_key'] ?? null ),
+				self::get_payload_error( $args['payload'] ?? null ),
+			)
+		);
+		if ( array() !== $errors ) {
+			throw InvalidInputException::from_errors( array_values( $errors ) );
+		}
+
+		return new self( $args );
+	}
+
+	/**
+	 * Hydrate from a stored row, decoding the JSON payload. Stored values are not validated.
+	 *
+	 * @param array<string, mixed> $row History row.
+	 */
+	public static function from_storage( array $row ): self {
+		$payload = $row['payload'] ?? null;
+		if ( is_string( $payload ) ) {
+			$row['payload'] = json_decode( $payload, true );
+		}
+
+		return new self( $row );
+	}
+
+	/**
+	 * Entry id, or null before save.
+	 */
+	public function get_id(): ?int {
+		return $this->id;
+	}
+
+	/**
+	 * Contract id.
+	 */
+	public function get_contract_id(): int {
+		return $this->contract_id;
+	}
+
+	/**
+	 * Cycle id, or null.
+	 */
+	public function get_cycle_id(): ?int {
+		return $this->cycle_id;
+	}
+
+	/**
+	 * Type slug.
+	 */
+	public function get_type(): string {
+		return $this->type;
+	}
+
+	/**
+	 * Payload, or null.
+	 *
+	 * @return array<int|string, mixed>|null
+	 */
+	public function get_payload(): ?array {
+		return $this->payload;
+	}
+
+	/**
+	 * When the engine stored the entry (GMT `Y-m-d H:i:s`), or null before save.
+	 */
+	public function get_date_created_gmt(): ?string {
+		return $this->date_created_gmt;
+	}
+
+	/**
+	 * The stored columns. The payload stays an array: the repository encodes it as JSON.
+	 *
+	 * @return array{id: int|null, contract_id: int, cycle_id: int|null, type: string, creation_key: string|null, payload: array<int|string, mixed>|null, date_created_gmt: string|null}
+	 */
+	public function to_storage(): array {
+		return array(
+			'id'               => $this->id,
+			'contract_id'      => $this->contract_id,
+			'cycle_id'         => $this->cycle_id,
+			'type'             => $this->type,
+			'creation_key'     => $this->creation_key,
+			'payload'          => $this->payload,
+			'date_created_gmt' => $this->date_created_gmt,
+		);
+	}
+
+	/**
+	 * The error for a type that is not a slug of 1-64 of `[a-z0-9_-]`, or null.
+	 *
+	 * @param mixed $type Type to check.
+	 */
+	private static function get_type_error( $type ): ?InvalidInputException {
+		try {
+			ArgumentValidator::validate_slug( 'type', $type );
+		} catch ( InvalidInputException $e ) {
+			return $e;
+		}
+
+		return null;
+	}
+
+	/**
+	 * The error for a creation key that is not null or a string of 1-100 characters, or null.
+	 *
+	 * @param mixed $creation_key Creation key to check.
+	 */
+	private static function get_creation_key_error( $creation_key ): ?InvalidInputException {
+		try {
+			ArgumentValidator::validate_creation_key( $creation_key );
+		} catch ( InvalidInputException $e ) {
+			return $e;
+		}
+
+		return null;
+	}
+
+	/**
+	 * The error for a payload that is not null or a JSON-encodable array, or null.
+	 *
+	 * @param mixed $payload Payload to check.
+	 */
+	private static function get_payload_error( $payload ): ?InvalidInputException {
+		if ( null === $payload ) {
+			return null;
+		}
+		if ( ! is_array( $payload ) ) {
+			return new InvalidInputException( ValidationErrorCode::INVALID_TYPE, 'payload', 'HistoryEntry: payload must be null or an array.', array( 'type' => 'object' ) );
+		}
+		// Core is WordPress-free, so PHP's encoder checks it, not wp_json_encode().
+		if ( false === json_encode( $payload ) ) { // phpcs:ignore WordPress.WP.AlternativeFunctions.json_encode_json_encode
+			return new InvalidInputException( ValidationErrorCode::INVALID_VALUE, 'payload', 'HistoryEntry: payload cannot be encoded as JSON.' );
+		}
+
+		return null;
+	}
+}
diff --git a/packages/php/woocommerce-subscriptions-engine/src/Core/Support/ArgumentValidator.php b/packages/php/woocommerce-subscriptions-engine/src/Core/Support/ArgumentValidator.php
index 17d7d1f5fd7..8e3539ce650 100644
--- a/packages/php/woocommerce-subscriptions-engine/src/Core/Support/ArgumentValidator.php
+++ b/packages/php/woocommerce-subscriptions-engine/src/Core/Support/ArgumentValidator.php
@@ -31,8 +31,8 @@ final class ArgumentValidator {

 	/**
 	 * Format of an engine slug, in JSON-schema syntax: 1-64 lowercase letters, digits, hyphens or
-	 * underscores. Extension slugs (the owner), schedule sources and lock operation labels share it;
-	 * 64 is the width of their columns.
+	 * underscores. Extension slugs (the owner), schedule sources, lock operation labels and history
+	 * entry types share it; 64 is the width of their columns.
 	 */
 	public const SLUG_PATTERN = '^[a-z0-9_-]{1,64}$';

@@ -124,6 +124,21 @@ final class ArgumentValidator {
 		}
 	}

+	/**
+	 * Collecting {@see self::validate_slug()}: the slug, or null when refused.
+	 *
+	 * @param string $key   Field name.
+	 * @param mixed  $value Caller value.
+	 */
+	public function get_slug( string $key, $value ): ?string {
+		try {
+			return self::validate_slug( $key, $value );
+		} catch ( InvalidInputException $e ) {
+			$this->add( $e );
+			return null;
+		}
+	}
+
 	/**
 	 * Collecting {@see self::validate_nullable_string()}: the value, or null when refused.
 	 *
@@ -351,6 +366,18 @@ final class ArgumentValidator {
 	 * @throws InvalidInputException If the value is missing, empty, not a string or not a valid slug.
 	 */
 	public static function validate_extension_slug( string $key, $value ): string {
+		return self::validate_slug( $key, $value );
+	}
+
+	/**
+	 * Validate and return a slug: a non-empty string matching {@see self::SLUG_PATTERN}, not
+	 * trimmed or case folded.
+	 *
+	 * @param string $key   Field name.
+	 * @param mixed  $value Caller value.
+	 * @throws InvalidInputException If the value is missing, empty, not a string or not a valid slug.
+	 */
+	public static function validate_slug( string $key, $value ): string {
 		$slug = self::validate_non_empty_string( $key, $value );
 		if ( ! self::is_slug( $slug ) ) {
 			throw self::get_invalid_input( ValidationErrorCode::INVALID_PATTERN, $key, 'must be 1-64 lowercase letters, digits, hyphens or underscores', array( 'pattern' => self::SLUG_PATTERN ) );
@@ -359,6 +386,27 @@ final class ArgumentValidator {
 		return $slug;
 	}

+	/**
+	 * Validate and return a creation key, or null: a string of 1-100 characters. The caller trims
+	 * it first, because the binary key columns ignore trailing spaces when comparing.
+	 *
+	 * @param mixed $value Caller value.
+	 * @throws InvalidInputException If the value is not null or a string of 1-100 characters.
+	 */
+	public static function validate_creation_key( $value ): ?string {
+		if ( null === $value ) {
+			return null;
+		}
+		if ( ! is_string( $value ) ) {
+			throw self::get_invalid_input( ValidationErrorCode::INVALID_TYPE, 'creation_key', 'must be a string', array( 'type' => 'string' ) );
+		}
+		if ( '' === $value || mb_strlen( $value ) > 100 ) {
+			throw self::get_invalid_input( ValidationErrorCode::INVALID_VALUE, 'creation_key', 'must be 1-100 characters' );
+		}
+
+		return $value;
+	}
+
 	/**
 	 * Whether a string matches {@see self::SLUG_PATTERN}.
 	 *
diff --git a/packages/php/woocommerce-subscriptions-engine/src/Integration/Storage/ContractRepository.php b/packages/php/woocommerce-subscriptions-engine/src/Integration/Storage/ContractRepository.php
index be5f4c18248..f5164040350 100644
--- a/packages/php/woocommerce-subscriptions-engine/src/Integration/Storage/ContractRepository.php
+++ b/packages/php/woocommerce-subscriptions-engine/src/Integration/Storage/ContractRepository.php
@@ -6,15 +6,17 @@
  * The contract is the live source of truth. A chain is NOT a stored entity: it is
  * the pair `(contract_id, kind)`, with its head and counters derived from the cycle
  * rows. The entity never carries a cycle graph in memory, so cycles are reached
- * through purpose-built reads ({@see self::find_cycle_history()}, etc.), appended one at a
+ * through purpose-built reads ({@see self::find_cycles()}, etc.), appended one at a
  * time ({@see self::append_cycle()}) and changed only through compare-and-set writes
  * ({@see self::transition_cycle()}). Cycle snapshot ids are stored as given and their
  * value objects attached on read. Meta is read and written only through the meta methods.
  *
  * Every update, meta write, cycle write and child write runs under the per-contract lock
  * ({@see ContractLock}): the caller's, or an internal one taken for an update or meta write made
- * without one; each child-table write fences its lock itself. The exception is {@see self::delete()},
- * the discard of a contract its creator still holds locked. No transactions, no object cache.
+ * without one; each child-table write fences its lock itself. Two exceptions: {@see self::delete()},
+ * the discard of a contract its creator still holds locked, and a history entry added without a
+ * lock ({@see self::add_history_entry()}), a single owner-scoped insert no held lock refuses. No
+ * transactions, no object cache.
  *
  * @package Automattic\WooCommerce\SubscriptionsEngine\Integration\Storage
  */
@@ -31,6 +33,7 @@ use Automattic\WooCommerce\SubscriptionsEngine\Core\Entity\Contract;
 use Automattic\WooCommerce\SubscriptionsEngine\Core\Entity\ContractStatus;
 use Automattic\WooCommerce\SubscriptionsEngine\Core\Entity\Cycle;
 use Automattic\WooCommerce\SubscriptionsEngine\Core\Entity\CycleStatus;
+use Automattic\WooCommerce\SubscriptionsEngine\Core\Entity\HistoryEntry;
 use Automattic\WooCommerce\SubscriptionsEngine\Core\Support\ArgumentValidator;
 use Automattic\WooCommerce\SubscriptionsEngine\Core\Support\Coercion;
 use Automattic\WooCommerce\SubscriptionsEngine\Core\Support\InvalidInputException;
@@ -978,7 +981,7 @@ final class ContractRepository {

 	// phpcs:disable Squiz.Commenting.FunctionCommentThrowTag.WrongNumber -- @throws also lists exceptions raised by the methods called.
 	/**
-	 * Fence a child-table write (cycles, meta, items, addresses) made with `$lock`; within 60 s
+	 * Fence a child-table write (cycles, meta, items, addresses, history) made with `$lock`; within 60 s
 	 * of the lock's last database stamp it costs no query. Past that, the lock is extended once when
 	 * the local estimate gives 120 s or less left; otherwise it is re-verified on the database clock
 	 * and trusted for up to 60 s more, extended once with 60 s or less left, and refused once the
@@ -1351,7 +1354,7 @@ final class ContractRepository {
 	}

 	/**
-	 * Delete a contract and its child, cycle and snapshot rows. Takes no lock: it is the
+	 * Delete a contract and its child, cycle, snapshot and history rows. Takes no lock: it is the
 	 * engine-internal discard of a contract its creator still holds locked.
 	 *
 	 * @param int $id Contract id.
@@ -1366,6 +1369,7 @@ final class ContractRepository {
 			SchemaInstaller::TABLE_CONTRACT_ITEMS,
 			SchemaInstaller::TABLE_CONTRACT_ADDRESSES,
 			SchemaInstaller::TABLE_CONTRACT_META,
+			SchemaInstaller::TABLE_CONTRACT_HISTORY,
 		) as $child ) {
 			// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching
 			$wpdb->delete( SchemaInstaller::get_table_name( $child ), array( 'contract_id' => $id ) );
@@ -1955,8 +1959,7 @@ final class ContractRepository {
 	}

 	/**
-	 * A window of a chain's cycle history, newest first - the paginated read for
-	 * history screens.
+	 * A window of a chain's cycles, newest first - the paginated cycle read.
 	 *
 	 * @param int    $contract_id Contract id.
 	 * @param string $kind        Chain kind. Defaults to billing.
@@ -1965,7 +1968,7 @@ final class ContractRepository {
 	 * @return array<int, Cycle> Cycles newest first.
 	 * @throws \RuntimeException If the read fails: a failed read must not look like an empty chain.
 	 */
-	public function find_cycle_history( int $contract_id, string $kind = Cycle::KIND_BILLING, int $limit = 20, int $offset = 0 ): array {
+	public function find_cycles( int $contract_id, string $kind = Cycle::KIND_BILLING, int $limit = 20, int $offset = 0 ): array {
 		global $wpdb;

 		$table = SchemaInstaller::get_table_name( SchemaInstaller::TABLE_CYCLES );
@@ -1986,6 +1989,169 @@ final class ContractRepository {
 		return $cycles;
 	}

+	// phpcs:disable Squiz.Commenting.FunctionCommentThrowTag.WrongNumber -- @throws also lists exceptions raised by the methods called.
+	/**
+	 * Add a history entry to a contract of `$extension_slug` in one `INSERT ... SELECT`. With `$lock`
+	 * the insert is fenced by it; without one it is scoped by the owner and takes no lock, so no held
+	 * lock refuses it (an append-only insert has nothing to read-modify-write). A cycle must be one of
+	 * the contract's, checked in the same statement. A taken `creation_key` returns null.
+	 *
+	 * @param HistoryEntry      $entry          The new entry.
+	 * @param string            $extension_slug The expected owning extension.
+	 * @param ContractLock|null $lock           The caller's lock on this contract, or null.
+	 * @return HistoryEntry|null The stored entry with its id and creation time; null when the key is taken.
+	 * @throws \InvalidArgumentException If no contract of that extension has the id, the cycle is not one
+	 *                                   of its cycles, or the lock is for another contract or extension.
+	 * @throws ContractLockedException If `$lock` was lost.
+	 * @throws \RuntimeException If the insert fails.
+	 */
+	public function add_history_entry( HistoryEntry $entry, string $extension_slug, ?ContractLock $lock = null ): ?HistoryEntry {
+		global $wpdb;
+
+		$contract_id = $entry->get_contract_id();
+		$cycle_id    = $entry->get_cycle_id();
+		if ( null !== $lock ) {
+			self::assert_lock_owner( $lock, $extension_slug );
+			$this->fence_child_write( $lock, $contract_id );
+		}
+
+		$history   = SchemaInstaller::get_table_name( SchemaInstaller::TABLE_CONTRACT_HISTORY );
+		$contracts = SchemaInstaller::get_table_name( SchemaInstaller::TABLE_CONTRACTS );
+		$cycles    = SchemaInstaller::get_table_name( SchemaInstaller::TABLE_CYCLES );
+		$columns   = $entry->to_storage();
+		$now       = current_time( 'mysql', true );
+		// HistoryEntry::create() refused a payload that cannot be encoded, so this encode succeeds.
+		$payload = null === $columns['payload'] ? null : wp_json_encode( $columns['payload'] );
+
+		$select = array( 'c.id', null === $cycle_id ? 'NULL' : 'y.id', '%s' );
+		$values = array( $columns['type'] );
+		foreach ( array( $columns['creation_key'], $payload ) as $value ) {
+			$select[] = null === $value ? 'NULL' : '%s';
+			if ( null !== $value ) {
+				$values[] = $value;
+			}
+		}
+		$select[] = '%s';
+		$values[] = $now;
+
+		$join = '';
+		if ( null !== $cycle_id ) {
+			$join     = " JOIN {$cycles} y ON y.id = %d AND y.contract_id = c.id";
+			$values[] = $cycle_id;
+		}
+		$where    = 'c.id = %d';
+		$values[] = $contract_id;
+		if ( null === $lock ) {
+			$where   .= ' AND c.' . self::OWNER_MATCH;
+			$values[] = $extension_slug;
+		}
+		$select_list = implode( ', ', $select );
+
+		// A duplicate creation key is an expected outcome, so `$wpdb` must not print or log it;
+		// every failure is still read from `last_error` and thrown below.
+		$suppressed = $wpdb->suppress_errors( true );
+		try {
+			// Table names and the select list are built here, never from input; every value is a placeholder.
+			// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
+			$inserted = $wpdb->query( $wpdb->prepare( "INSERT INTO {$history} ( contract_id, cycle_id, type, creation_key, payload, date_created_gmt ) SELECT {$select_list} FROM {$contracts} c{$join} WHERE {$where}", $values ) );
+		} finally {
+			$wpdb->suppress_errors( $suppressed );
+		}
+
+		if ( false === $inserted ) {
+			$db_error  = $wpdb->last_error;
+			$duplicate = self::get_duplicate_key_result();
+			if ( null === $duplicate && null !== $columns['creation_key'] ) {
+				$duplicate = $this->has_history_creation_key( $contract_id, $columns['creation_key'] );
+			}
+			// The only UNIQUE index an entry can hit is `creation`, and only with a key.
+			if ( true === $duplicate && null !== $columns['creation_key'] ) {
+				return null;
+			}
+			if ( null !== $lock ) {
+				$this->throw_if_lock_lost( $lock );
+			}
+			throw new \RuntimeException( esc_html( sprintf( 'Failed to add a history entry to contract %d: %s', $contract_id, $db_error ) ) );
+		}
+		if ( 1 !== (int) $inserted ) {
+			self::throw_history_target_not_found( $contract_id, $extension_slug, $cycle_id );
+		}
+
+		$columns['id']               = (int) $wpdb->insert_id;
+		$columns['date_created_gmt'] = $now;
+		// Hydrate from the stored JSON, so the returned entry matches a fresh read.
+		$columns['payload'] = $payload;
+
+		return HistoryEntry::from_storage( $columns );
+	}
+	// phpcs:enable Squiz.Commenting.FunctionCommentThrowTag.WrongNumber
+
+	/**
+	 * Whether the contract already has a history entry with this creation key: the fallback when
+	 * the driver gives no error number. A failed read reads as false, so the caller reports its
+	 * own insert failure.
+	 *
+	 * @param int    $contract_id  Contract id.
+	 * @param string $creation_key Creation key.
+	 */
+	private function has_history_creation_key( int $contract_id, string $creation_key ): bool {
+		global $wpdb;
+
+		$table = SchemaInstaller::get_table_name( SchemaInstaller::TABLE_CONTRACT_HISTORY );
+
+		// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.PreparedSQL.InterpolatedNotPrepared
+		$found = $wpdb->get_var( $wpdb->prepare( "SELECT 1 FROM {$table} WHERE contract_id = %d AND creation_key = %s LIMIT 1", $contract_id, $creation_key ) );
+
+		return null !== $found;
+	}
+
+	/**
+	 * Refuse a history insert that selected no row: the contract of that extension is missing or,
+	 * when a cycle is named, the cycle may not be one of its cycles.
+	 *
+	 * @param int      $contract_id    Contract id.
+	 * @param string   $extension_slug The expected owning extension.
+	 * @param int|null $cycle_id       The entry's cycle id, or null.
+	 * @return never
+	 * @throws \InvalidArgumentException Always.
+	 */
+	private static function throw_history_target_not_found( int $contract_id, string $extension_slug, ?int $cycle_id ): void {
+		if ( null === $cycle_id ) {
+			self::throw_not_found( $contract_id, $extension_slug );
+		}
+		throw new \InvalidArgumentException( esc_html( sprintf( 'No contract of extension "%s" has id %d, or cycle %d is not one of its cycles.', $extension_slug, $contract_id, $cycle_id ) ) );
+	}
+
+	/**
+	 * A window of a contract's history, newest first (insertion order).
+	 *
+	 * @param int $contract_id Contract id.
+	 * @param int $limit       Maximum entries to return.
+	 * @param int $offset      Entries to skip (for paging).
+	 * @return array<int, HistoryEntry> Entries newest first; empty for an unknown contract.
+	 * @throws \RuntimeException If the read fails: a failed read must not look like an empty history.
+	 */
+	public function find_history( int $contract_id, int $limit = 20, int $offset = 0 ): array {
+		global $wpdb;
+
+		$table = SchemaInstaller::get_table_name( SchemaInstaller::TABLE_CONTRACT_HISTORY );
+
+		// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.PreparedSQL.InterpolatedNotPrepared
+		$rows = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$table} WHERE contract_id = %d ORDER BY id DESC LIMIT %d OFFSET %d", $contract_id, $limit, $offset ), ARRAY_A );
+		if ( '' !== $wpdb->last_error ) {
+			throw new \RuntimeException( esc_html( sprintf( 'Failed to read the history of contract %d: %s', $contract_id, $wpdb->last_error ) ) );
+		}
+
+		$entries = array();
+		foreach ( is_array( $rows ) ? $rows : array() as $row ) {
+			if ( is_array( $row ) ) {
+				$entries[] = HistoryEntry::from_storage( Coercion::coerce_string_keyed( $row ) );
+			}
+		}
+
+		return $entries;
+	}
+
 	/**
 	 * All cycles linked to `$order_id`, across kinds and contracts. `order_id` is a
 	 * non-1:1 reference (an aggregate order may serve many cycles), so this returns
diff --git a/packages/php/woocommerce-subscriptions-engine/src/Integration/Storage/SchemaInstaller.php b/packages/php/woocommerce-subscriptions-engine/src/Integration/Storage/SchemaInstaller.php
index 30a9ce3325d..a618702d10f 100644
--- a/packages/php/woocommerce-subscriptions-engine/src/Integration/Storage/SchemaInstaller.php
+++ b/packages/php/woocommerce-subscriptions-engine/src/Integration/Storage/SchemaInstaller.php
@@ -1,6 +1,6 @@
 <?php
 /**
- * Owns the engine's baseline database tables (plan, contract, and cycle tables).
+ * Owns the engine's baseline database tables (plan, contract, cycle and contract history tables).
  * Mirrors the order/HPOS conventions: BIGINT UNSIGNED ids, `*_gmt` datetime
  * columns, JSON columns for policy bundles, no foreign-key constraints. A chain is
  * not a stored table: it is the pair `(contract_id, kind)` on the cycle rows.
@@ -65,13 +65,16 @@ final class SchemaInstaller {
 	 * 2.9.0 - owner columns compare binary: `extension_slug` on plans, contracts and cycles uses
 	 *         the table charset's `_bin` collation, so every owner match and the `creation`
 	 *         UNIQUE index are exact for case and accents. Pre-freeze, recreate the tables.
+	 * 2.10.0 - new contract_history table: per-contract extension records (type, optional cycle,
+	 *          opaque JSON payload, a binary-collated `creation_key` unique per contract), read
+	 *          newest first through the `contract` index. dbDelta creates it; nothing to recreate.
 	 *
 	 * Pre-freeze, tables are recreated rather than migrated. dbDelta adds columns but
 	 * does not change an existing column's nullability or drop unused ones, so a dev box
 	 * on an earlier schema must drop and recreate the tables (and clear VERSION_OPTION)
 	 * to pick up such changes - in-place ALTERs and backfills arrive with the freeze.
 	 */
-	private const VERSION = '2.9.0';
+	private const VERSION = '2.10.0';

 	/**
 	 * Option key tracking the installed schema version.
@@ -89,6 +92,7 @@ final class SchemaInstaller {
 	public const TABLE_CONTRACT_META      = 'contract_meta';
 	public const TABLE_CYCLES             = 'cycles';
 	public const TABLE_SNAPSHOTS          = 'snapshots';
+	public const TABLE_CONTRACT_HISTORY   = 'contract_history';

 	/**
 	 * Resolve a logical identifier to its prefixed table name.
@@ -198,6 +202,7 @@ final class SchemaInstaller {
 			self::TABLE_CONTRACT_META      => $prefix . 'wc_subscription_contract_meta',
 			self::TABLE_CYCLES             => $prefix . 'wc_subscription_cycles',
 			self::TABLE_SNAPSHOTS          => $prefix . 'wc_subscription_snapshots',
+			self::TABLE_CONTRACT_HISTORY   => $prefix . 'wc_subscription_contract_history',
 		);
 	}

@@ -222,6 +227,7 @@ final class SchemaInstaller {
 		$contract_meta      = $names[ self::TABLE_CONTRACT_META ];
 		$cycles             = $names[ self::TABLE_CYCLES ];
 		$snapshots          = $names[ self::TABLE_SNAPSHOTS ];
+		$contract_history   = $names[ self::TABLE_CONTRACT_HISTORY ];

 		// Mirrors the HPOS orders meta table indexes, including its meta_value prefix length.
 		$meta_value_index_length = max( min( absint( apply_filters( 'woocommerce_database_max_index_length', 191 ) ), 767 ) - 8 - 100 - 1, 20 );
@@ -414,6 +420,26 @@ final class SchemaInstaller {
   KEY parent (parent_id)
 ) {$collate};";

+		// The engine's generic per-contract record store, written on the owning extension's command
+		// (history is its first use): an extension `type` slug, an optional cycle of the contract,
+		// an opaque JSON `payload` and insertion order. `contract` serves the newest-first read
+		// (InnoDB appends `id` to it, so `ORDER BY id DESC` needs no filesort). `creation` makes an
+		// optional `creation_key` unique per contract (NULL keys never collide); binary, as the
+		// contract creation key, and trimmed by the entity because the collation ignores trailing
+		// spaces. `type` admits lowercase ASCII only, so it needs no binary collation.
+		$contract_history_sql = "CREATE TABLE {$contract_history} (
+  id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
+  contract_id BIGINT UNSIGNED NOT NULL,
+  cycle_id BIGINT UNSIGNED NULL,
+  type VARCHAR(64) NOT NULL,
+  creation_key VARCHAR(100){$binary_collate} NULL,
+  payload LONGTEXT NULL,
+  date_created_gmt DATETIME NOT NULL,
+  PRIMARY KEY  (id),
+  KEY contract (contract_id),
+  UNIQUE KEY creation (contract_id, creation_key)
+) {$collate};";
+
 		return array(
 			$plans_sql,
 			$plan_meta_sql,
@@ -423,6 +449,7 @@ final class SchemaInstaller {
 			$contract_meta_sql,
 			$cycles_sql,
 			$snapshots_sql,
+			$contract_history_sql,
 		);
 	}
 }
diff --git a/packages/php/woocommerce-subscriptions-engine/tests/integration/Api/ContractHistoryTest.php b/packages/php/woocommerce-subscriptions-engine/tests/integration/Api/ContractHistoryTest.php
new file mode 100644
index 00000000000..c4e092c5f3f
--- /dev/null
+++ b/packages/php/woocommerce-subscriptions-engine/tests/integration/Api/ContractHistoryTest.php
@@ -0,0 +1,317 @@
+<?php
+/**
+ * Integration tests for the contract history methods of the Contracts facade.
+ *
+ * @package Automattic\WooCommerce\SubscriptionsEngine
+ */
+
+declare( strict_types=1 );
+
+namespace Automattic\WooCommerce\SubscriptionsEngine\Tests\Integration\Api;
+
+use EngineIntegrationTestCase;
+use InvalidArgumentException;
+use Automattic\WooCommerce\SubscriptionsEngine\Api\Contracts;
+use Automattic\WooCommerce\SubscriptionsEngine\Api\View\HistoryEntryView;
+use Automattic\WooCommerce\SubscriptionsEngine\Core\Support\ArgumentValidator;
+use Automattic\WooCommerce\SubscriptionsEngine\Core\Support\ValidationErrorCode;
+use Automattic\WooCommerce\SubscriptionsEngine\Tests\Integration\AssertsValidationErrors;
+
+/**
+ * @covers \Automattic\WooCommerce\SubscriptionsEngine\Api\Contracts
+ */
+class ContractHistoryTest extends EngineIntegrationTestCase {
+
+	use AssertsValidationErrors;
+
+	private const EXTENSION_SLUG = 'acme-subs';
+
+	/**
+	 * A stored contract id of {@see self::EXTENSION_SLUG}.
+	 *
+	 * @var int
+	 */
+	private $id;
+
+	public function setUp(): void {
+		parent::setUp();
+		$this->id = $this->create_released( array( 'extension_slug' => self::EXTENSION_SLUG ) )->get_id();
+	}
+
+	/**
+	 * @testdox add_history_entry() with the caller's lock returns a view that matches a fresh read.
+	 */
+	public function test_a_locked_add_returns_the_entry(): void {
+		$cycle = $this->add_cycle_locked(
+			$this->id,
+			array(
+				'starts_at_gmt' => '2026-07-15 00:00:00',
+				'ends_at_gmt'   => '2026-08-15 00:00:00',
+				'currency'      => 'USD',
+			)
+		);
+		$this->assertNotNull( $cycle );
+		$lock = $this->take_lock( $this->id, 'renew' );
+
+		$view = Contracts::add_history_entry(
+			$this->id,
+			array(
+				'extension_slug' => self::EXTENSION_SLUG,
+				'type'           => 'renewal-paid',
+				'cycle_id'       => (string) $cycle->get_id(),
+				'payload'        => array( 'actor' => array( 'role' => 'system' ) ),
+				'creation_key'   => 'renewal-paid-' . $cycle->get_id(),
+			),
+			$lock
+		);
+
+		$this->assertInstanceOf( HistoryEntryView::class, $view );
+		$this->assertSame( $this->id, $view->get_contract_id() );
+		$this->assertSame( $cycle->get_id(), $view->get_cycle_id(), 'A digit-string id is cast.' );
+		$this->assertSame( 'renewal-paid', $view->get_type() );
+		$this->assertSame( array( 'actor' => array( 'role' => 'system' ) ), $view->get_payload() );
+		$this->assertMatchesRegularExpression( '/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/', $view->get_date_created_gmt() );
+		$this->assertEquals( array( $view ), Contracts::get_history( $this->id ) );
+	}
+
+	/**
+	 * @testdox add_history_entry() without a lock lands while another operation holds the contract's lock.
+	 */
+	public function test_an_unlocked_add_is_not_blocked_by_a_held_lock(): void {
+		$this->take_lock( $this->id, 'renew' );
+
+		$view = Contracts::add_history_entry(
+			$this->id,
+			array(
+				'extension_slug' => self::EXTENSION_SLUG,
+				'type'           => 'note',
+				'payload'        => array( 'text' => 'Called the customer.' ),
+			)
+		);
+
+		$this->assertInstanceOf( HistoryEntryView::class, $view );
+		$this->assertSame( 'renew', $this->get_lock_holder( $this->id )['operation'] );
+	}
+
+	/**
+	 * @testdox add_history_entry() reports every shape error at once and writes nothing.
+	 */
+	public function test_every_shape_error_is_reported_at_once(): void {
+		$this->assert_validation_errors(
+			function (): void {
+				Contracts::add_history_entry(
+					$this->id,
+					array(
+						'extension_slug' => 'Acme',
+						'type'           => 'Renewal Paid',
+						'cycle_id'       => 'x',
+						'payload'        => 'text',
+						'creation_key'   => 5,
+					)
+				);
+			},
+			array(
+				array( ValidationErrorCode::INVALID_PATTERN, 'extension_slug', array( 'pattern' => ArgumentValidator::SLUG_PATTERN ) ),
+				array( ValidationErrorCode::INVALID_PATTERN, 'type', array( 'pattern' => ArgumentValidator::SLUG_PATTERN ) ),
+				array( ValidationErrorCode::INVALID_TYPE, 'cycle_id', array( 'type' => 'integer' ) ),
+				array( ValidationErrorCode::INVALID_TYPE, 'payload', array( 'type' => 'object' ) ),
+				array( ValidationErrorCode::INVALID_TYPE, 'creation_key', array( 'type' => 'string' ) ),
+			)
+		);
+
+		$this->assertSame( array(), Contracts::get_history( $this->id ) );
+	}
+
+	/**
+	 * @testdox add_history_entry() reports missing required keys and an out-of-bounds cycle id.
+	 */
+	public function test_missing_required_keys_are_reported(): void {
+		$this->assert_validation_errors(
+			function (): void {
+				Contracts::add_history_entry( $this->id, array( 'cycle_id' => 0 ) );
+			},
+			array(
+				array( ValidationErrorCode::REQUIRED, 'extension_slug' ),
+				array( ValidationErrorCode::REQUIRED, 'type' ),
+				array( ValidationErrorCode::OUT_OF_BOUNDS, 'cycle_id', array( 'min' => 1 ) ),
+			)
+		);
+	}
+
+	/**
+	 * @testdox add_history_entry() reports the entity's errors together: a blank creation key and a payload that cannot be JSON-encoded.
+	 */
+	public function test_entity_errors_are_reported_together(): void {
+		$this->assert_validation_errors(
+			function (): void {
+				Contracts::add_history_entry(
+					$this->id,
+					array(
+						'extension_slug' => self::EXTENSION_SLUG,
+						'type'           => 'note',
+						'payload'        => array( 'text' => "\xB1\x31" ),
+						'creation_key'   => '  ',
+					)
+				);
+			},
+			array(
+				array( ValidationErrorCode::INVALID_VALUE, 'creation_key' ),
+				array( ValidationErrorCode::INVALID_VALUE, 'payload' ),
+			)
+		);
+
+		$this->assertSame( array(), Contracts::get_history( $this->id ) );
+	}
+
+	/**
+	 * @testdox add_history_entry() ignores unknown keys with a notice and stores the known ones.
+	 */
+	public function test_unknown_keys_are_ignored_with_a_notice(): void {
+		$this->setExpectedIncorrectUsage( Contracts::class . '::add_history_entry' );
+
+		$view = Contracts::add_history_entry(
+			$this->id,
+			array(
+				'extension_slug' => self::EXTENSION_SLUG,
+				'type'           => 'note',
+				'actor'          => 'merchant',
+			)
+		);
+
+		$this->assertInstanceOf( HistoryEntryView::class, $view );
+		$this->assertSame( 'note', $view->get_type() );
+		$this->assertNull( $view->get_payload(), 'The unknown key is not stored.' );
+	}
+
+	/**
+	 * @testdox add_history_entry() returns null for a taken creation key.
+	 */
+	public function test_a_taken_creation_key_returns_null(): void {
+		$args = array(
+			'extension_slug' => self::EXTENSION_SLUG,
+			'type'           => 'created',
+			'creation_key'   => 'created',
+		);
+
+		$this->assertInstanceOf( HistoryEntryView::class, Contracts::add_history_entry( $this->id, $args ) );
+		$this->assertNull( Contracts::add_history_entry( $this->id, $args ) );
+		$this->assertCount( 1, Contracts::get_history( $this->id ) );
+	}
+
+	/**
+	 * @testdox add_history_entry() refuses a contract of another extension and a lock of another extension.
+	 */
+	public function test_another_extensions_contract_or_lock_is_refused(): void {
+		$other = $this->create_released( array( 'extension_slug' => 'another-extension' ) )->get_id();
+		$args  = array(
+			'extension_slug' => self::EXTENSION_SLUG,
+			'type'           => 'held',
+		);
+
+		try {
+			Contracts::add_history_entry( $other, $args );
+			$this->fail( 'Expected a contract of another extension to be refused.' );
+		} catch ( InvalidArgumentException $e ) {
+			$this->assertStringContainsString( "has id {$other}", $e->getMessage() );
+		}
+
+		$lock = $this->take_lock( $other, 'hold' );
+		$this->expectException( InvalidArgumentException::class );
+		Contracts::add_history_entry( $other, $args, $lock );
+	}
+
+	/**
+	 * @testdox get_history() pages newest first with limit and offset.
+	 */
+	public function test_get_history_pages_newest_first(): void {
+		foreach ( array( 'a', 'b', 'c' ) as $type ) {
+			Contracts::add_history_entry(
+				$this->id,
+				array(
+					'extension_slug' => self::EXTENSION_SLUG,
+					'type'           => $type,
+				)
+			);
+		}
+
+		$this->assertSame( array( 'c', 'b', 'a' ), $this->types( Contracts::get_history( $this->id ) ) );
+		$page = Contracts::get_history(
+			$this->id,
+			array(
+				'limit'  => 1,
+				'offset' => '1',
+			)
+		);
+		$this->assertSame( array( 'b' ), $this->types( $page ) );
+		$this->assertSame( array(), Contracts::get_history( 999999 ) );
+	}
+
+	/**
+	 * @testdox get_history() takes no owner: any caller reads the history of another extension's contract.
+	 */
+	public function test_get_history_reads_another_extensions_contract(): void {
+		$other = $this->create_released( array( 'extension_slug' => 'another-extension' ) )->get_id();
+		Contracts::add_history_entry(
+			$other,
+			array(
+				'extension_slug' => 'another-extension',
+				'type'           => 'note',
+			)
+		);
+		Contracts::add_history_entry(
+			$this->id,
+			array(
+				'extension_slug' => self::EXTENSION_SLUG,
+				'type'           => 'held',
+			)
+		);
+
+		$this->assertSame( array( 'note' ), $this->types( Contracts::get_history( $other ) ) );
+		$this->assertSame( array( 'held' ), $this->types( Contracts::get_history( $this->id ) ), 'Each contract reads only its own entries.' );
+	}
+
+	/**
+	 * @testdox get_history() reports a negative limit and offset together.
+	 */
+	public function test_get_history_reports_invalid_paging(): void {
+		$this->assert_validation_errors(
+			function (): void {
+				Contracts::get_history(
+					$this->id,
+					array(
+						'limit'  => -1,
+						'offset' => -2,
+					)
+				);
+			},
+			array(
+				array( ValidationErrorCode::OUT_OF_BOUNDS, 'limit', array( 'min' => 0 ) ),
+				array( ValidationErrorCode::OUT_OF_BOUNDS, 'offset', array( 'min' => 0 ) ),
+			)
+		);
+	}
+
+	/**
+	 * @testdox get_history() ignores unknown keys with a notice.
+	 */
+	public function test_get_history_ignores_unknown_keys(): void {
+		$this->setExpectedIncorrectUsage( Contracts::class . '::get_history' );
+
+		$this->assertSame( array(), Contracts::get_history( $this->id, array( 'per_page' => 5 ) ) );
+	}
+
+	/**
+	 * The types of entry views, in order.
+	 *
+	 * @param array<int, HistoryEntryView> $views Views.
+	 * @return array<int, string>
+	 */
+	private function types( array $views ): array {
+		return array_map(
+			static function ( HistoryEntryView $view ): string {
+				return $view->get_type();
+			},
+			$views
+		);
+	}
+}
diff --git a/packages/php/woocommerce-subscriptions-engine/tests/integration/Api/ContractsTest.php b/packages/php/woocommerce-subscriptions-engine/tests/integration/Api/ContractsTest.php
index bb045bbcec5..96ceb553169 100644
--- a/packages/php/woocommerce-subscriptions-engine/tests/integration/Api/ContractsTest.php
+++ b/packages/php/woocommerce-subscriptions-engine/tests/integration/Api/ContractsTest.php
@@ -1579,7 +1579,7 @@ class ContractsTest extends EngineIntegrationTestCase {
 	 * @param int $cycle_id    Cycle id.
 	 */
 	private function cycle( int $contract_id, int $cycle_id ): Cycle {
-		foreach ( ( new ContractRepository() )->find_cycle_history( $contract_id ) as $cycle ) {
+		foreach ( ( new ContractRepository() )->find_cycles( $contract_id ) as $cycle ) {
 			if ( $cycle->get_id() === $cycle_id ) {
 				return $cycle;
 			}
@@ -1895,16 +1895,16 @@ class ContractsTest extends EngineIntegrationTestCase {
 		$id      = $this->contract_with_currency();
 		$created = $this->add_cycle( $id, $this->cycle_args( array( 'order_id' => 77 ) ) );

-		$history = Contracts::get_cycles( $id );
+		$cycles = Contracts::get_cycles( $id );

-		$this->assertCount( 1, $history );
-		$this->assertEquals( $history[0], $created, 'The returned view matches a fresh read.' );
+		$this->assertCount( 1, $cycles );
+		$this->assertEquals( $cycles[0], $created, 'The returned view matches a fresh read.' );
 		$cycle_id = $created->get_id();
 		$this->assertGreaterThan( 0, $cycle_id );
-		$this->assertInstanceOf( CycleView::class, $history[0] );
-		$this->assertSame( $cycle_id, $history[0]->get_id() );
-		$this->assertSame( CycleStatus::BILLED, $history[0]->get_status() );
-		$this->assertSame( 77, $history[0]->get_order_id() );
+		$this->assertInstanceOf( CycleView::class, $cycles[0] );
+		$this->assertSame( $cycle_id, $cycles[0]->get_id() );
+		$this->assertSame( CycleStatus::BILLED, $cycles[0]->get_status() );
+		$this->assertSame( 77, $cycles[0]->get_order_id() );
 	}

 	/**
@@ -2905,11 +2905,11 @@ class ContractsTest extends EngineIntegrationTestCase {
 		$contract_id = $contract->get_id();
 		$this->assertNotNull( $contract_id );

-		$history = Contracts::get_cycles( $contract_id );
-		$this->assertCount( 1, $history );
-		$this->assertInstanceOf( CycleView::class, $history[0] );
-		$this->assertSame( 1, $history[0]->get_count() );
-		$this->assertSame( CycleStatus::BILLED, $history[0]->get_status() );
+		$cycles = Contracts::get_cycles( $contract_id );
+		$this->assertCount( 1, $cycles );
+		$this->assertInstanceOf( CycleView::class, $cycles[0] );
+		$this->assertSame( 1, $cycles[0]->get_count() );
+		$this->assertSame( CycleStatus::BILLED, $cycles[0]->get_status() );
 	}

 	/**
diff --git a/packages/php/woocommerce-subscriptions-engine/tests/integration/Api/OwnerSlugValidationTest.php b/packages/php/woocommerce-subscriptions-engine/tests/integration/Api/OwnerSlugValidationTest.php
index 8ddab4df568..d63cea26967 100644
--- a/packages/php/woocommerce-subscriptions-engine/tests/integration/Api/OwnerSlugValidationTest.php
+++ b/packages/php/woocommerce-subscriptions-engine/tests/integration/Api/OwnerSlugValidationTest.php
@@ -16,6 +16,7 @@ use Automattic\WooCommerce\SubscriptionsEngine\Api\Plans;
 use Automattic\WooCommerce\SubscriptionsEngine\Api\ValidationException;
 use Automattic\WooCommerce\SubscriptionsEngine\Api\View\ContractView;
 use Automattic\WooCommerce\SubscriptionsEngine\Api\View\CycleView;
+use Automattic\WooCommerce\SubscriptionsEngine\Api\View\HistoryEntryView;
 use Automattic\WooCommerce\SubscriptionsEngine\Api\View\PlanView;
 use Automattic\WooCommerce\SubscriptionsEngine\Core\Entity\CycleStatus;
 use Automattic\WooCommerce\SubscriptionsEngine\Core\Support\ValidationErrorCode;
@@ -160,6 +161,10 @@ class OwnerSlugValidationTest extends EngineIntegrationTestCase {
 				$this->assertIsInt( $result );
 				$this->assertSame( 'x', Contracts::get_meta( $this->contract_id, 'note', true ) );
 				return;
+			case 'Contracts::add_history_entry':
+				$this->assertInstanceOf( HistoryEntryView::class, $result );
+				$this->assertSame( $this->contract_id, $result->get_contract_id() );
+				return;
 			case 'Contracts::list_for_customer':
 				$this->assertSame( array( $this->contract_id ), self::get_ids( $result ) );
 				return;
@@ -197,6 +202,7 @@ class OwnerSlugValidationTest extends EngineIntegrationTestCase {
 			'Contracts::add_meta',
 			'Contracts::update_meta',
 			'Contracts::delete_meta',
+			'Contracts::add_history_entry',
 			'Contracts::list_for_customer',
 			'Plans::create',
 			'Plans::update',
@@ -286,6 +292,15 @@ class OwnerSlugValidationTest extends EngineIntegrationTestCase {
 				return Contracts::update_meta( $this->contract_id, $slug, 'note', 'x', null, $this->lock );
 			case 'Contracts::delete_meta':
 				return Contracts::delete_meta( $this->contract_id, $slug, 'note', null, $this->lock );
+			case 'Contracts::add_history_entry':
+				return Contracts::add_history_entry(
+					$this->contract_id,
+					array(
+						'extension_slug' => $slug,
+						'type'           => 'note',
+					),
+					$this->lock
+				);
 			case 'Contracts::list_for_customer':
 				return Contracts::list_for_customer( self::CUSTOMER_ID, 20, 0, array( 'extension_slug' => $slug ) );
 			case 'Plans::create':
diff --git a/packages/php/woocommerce-subscriptions-engine/tests/integration/Integration/Storage/ContractHistoryTest.php b/packages/php/woocommerce-subscriptions-engine/tests/integration/Integration/Storage/ContractHistoryTest.php
new file mode 100644
index 00000000000..354eb88f7f8
--- /dev/null
+++ b/packages/php/woocommerce-subscriptions-engine/tests/integration/Integration/Storage/ContractHistoryTest.php
@@ -0,0 +1,460 @@
+<?php
+/**
+ * Integration tests for the contract history writes and reads on ContractRepository.
+ *
+ * @package Automattic\WooCommerce\SubscriptionsEngine
+ */
+
+declare( strict_types=1 );
+
+namespace Automattic\WooCommerce\SubscriptionsEngine\Tests\Integration\Integration\Storage;
+
+use EngineIntegrationTestCase;
+use InvalidArgumentException;
+use RuntimeException;
+use Automattic\WooCommerce\SubscriptionsEngine\Api\ContractLock;
+use Automattic\WooCommerce\SubscriptionsEngine\Api\ContractLockedException;
+use Automattic\WooCommerce\SubscriptionsEngine\Core\Entity\Contract;
+use Automattic\WooCommerce\SubscriptionsEngine\Core\Entity\HistoryEntry;
+use Automattic\WooCommerce\SubscriptionsEngine\Integration\Storage\ContractRepository;
+use Automattic\WooCommerce\SubscriptionsEngine\Integration\Storage\SchemaInstaller;
+
+/**
+ * @covers \Automattic\WooCommerce\SubscriptionsEngine\Integration\Storage\ContractRepository
+ */
+class ContractHistoryTest extends EngineIntegrationTestCase {
+
+	/**
+	 * Owning extension of the fixture contracts.
+	 */
+	private const OWNER = 'acme-subs';
+
+	/**
+	 * The System Under Test.
+	 *
+	 * @var ContractRepository
+	 */
+	private $sut;
+
+	/**
+	 * A stored contract id of {@see self::OWNER}.
+	 *
+	 * @var int
+	 */
+	private $id;
+
+	public function setUp(): void {
+		parent::setUp();
+		$this->sut = new ContractRepository();
+		$this->id  = $this->insert_released( Contract::create( array( 'extension_slug' => self::OWNER ) ) );
+	}
+
+	/**
+	 * @testdox With the caller's lock, the entry is written and returned with its id and UTC creation time.
+	 */
+	public function test_a_locked_write_stores_the_entry(): void {
+		$cycle_id = $this->add_cycle( $this->id );
+		$lock     = $this->sut->acquire_lock( $this->id, self::OWNER, 'renew' );
+		$this->assertInstanceOf( ContractLock::class, $lock );
+
+		$before = gmdate( 'Y-m-d H:i:s' );
+		$stored = $this->sut->add_history_entry(
+			$this->entry(
+				array(
+					'cycle_id' => $cycle_id,
+					'type'     => 'renewal-paid',
+					'payload'  => array( 'actor' => array( 'role' => 'system' ) ),
+				)
+			),
+			self::OWNER,
+			$lock
+		);
+		$after  = gmdate( 'Y-m-d H:i:s' );
+
+		$this->assertInstanceOf( HistoryEntry::class, $stored );
+		$this->assertIsInt( $stored->get_id() );
+		$this->assertSame( $this->id, $stored->get_contract_id() );
+		$this->assertSame( $cycle_id, $stored->get_cycle_id() );
+		$this->assertSame( 'renewal-paid', $stored->get_type() );
+		$this->assertSame( array( 'actor' => array( 'role' => 'system' ) ), $stored->get_payload() );
+		$created = (string) $stored->get_date_created_gmt();
+		$this->assertGreaterThanOrEqual( $before, $created );
+		$this->assertLessThanOrEqual( $after, $created );
+
+		$this->assertEquals( array( $stored ), $this->sut->find_history( $this->id ), 'The returned entry matches a fresh read.' );
+	}
+
+	/**
+	 * @testdox With a lost lock, the write throws ContractLockedException and writes nothing.
+	 */
+	public function test_a_lost_lock_refuses_the_write(): void {
+		$this->pin_db_clock( '2035-01-01 00:00:00' );
+		$old = $this->sut->acquire_lock( $this->id, self::OWNER, 'renew' );
+		$this->assertInstanceOf( ContractLock::class, $old );
+
+		$this->pin_db_clock( '2035-01-01 00:10:00' );
+		$this->assertInstanceOf( ContractLock::class, $this->sut->acquire_lock( $this->id, self::OWNER, 'cancel' ) );
+		$this->age_lock_trust( $old );
+
+		try {
+			$this->sut->add_history_entry( $this->entry(), self::OWNER, $old );
+			$this->fail( 'Expected the lost lock to be refused.' );
+		} catch ( ContractLockedException $e ) {
+			$this->assertSame( 'cancel', $e->get_operation() );
+		}
+
+		$this->assertSame( array(), $this->sut->find_history( $this->id ) );
+	}
+
+	/**
+	 * @testdox Without a lock, the entry is written in one insert and no lock is taken.
+	 */
+	public function test_an_unlocked_write_takes_no_lock(): void {
+		$stored     = null;
+		$statements = $this->statements_during(
+			function () use ( &$stored ): void {
+				$stored = $this->sut->add_history_entry( $this->entry(), self::OWNER );
+			}
+		);
+
+		$this->assertInstanceOf( HistoryEntry::class, $stored );
+		$this->assertCount( 1, $statements, 'One statement.' );
+		$this->assertStringStartsWith( 'INSERT INTO ' . SchemaInstaller::get_table_name( SchemaInstaller::TABLE_CONTRACT_HISTORY ), $statements[0] );
+		$this->assertNull( $this->get_lock_holder( $this->id )['operation'], 'No lock is held.' );
+		$this->assertInstanceOf( ContractLock::class, $this->sut->acquire_lock( $this->id, self::OWNER, 'hold' ), 'The contract is lockable.' );
+	}
+
+	/**
+	 * @testdox Without a lock, the entry is written while another operation holds the contract's lock.
+	 */
+	public function test_an_unlocked_write_lands_while_another_operation_holds_the_lock(): void {
+		$this->assertInstanceOf( ContractLock::class, $this->sut->acquire_lock( $this->id, self::OWNER, 'renew' ) );
+
+		$stored = $this->sut->add_history_entry( $this->entry( array( 'type' => 'note' ) ), self::OWNER );
+
+		$this->assertInstanceOf( HistoryEntry::class, $stored );
+		$this->assertCount( 1, $this->sut->find_history( $this->id ) );
+		$this->assertSame( 'renew', $this->get_lock_holder( $this->id )['operation'], 'The held lock is untouched.' );
+	}
+
+	/**
+	 * @testdox Without a lock, an unknown contract or one of another extension is refused and nothing is written.
+	 */
+	public function test_an_unlocked_write_to_a_missing_or_foreign_contract_is_refused(): void {
+		$other = $this->insert_released( Contract::create( array( 'extension_slug' => 'another-extension' ) ) );
+
+		foreach ( array( 999999, $other ) as $contract_id ) {
+			try {
+				$this->sut->add_history_entry( $this->entry( array( 'contract_id' => $contract_id ) ), self::OWNER );
+				$this->fail( "Expected contract {$contract_id} to be refused." );
+			} catch ( InvalidArgumentException $e ) {
+				$this->assertStringContainsString( "has id {$contract_id}.", $e->getMessage() );
+			}
+			$this->assertSame( array(), $this->sut->find_history( $contract_id ) );
+		}
+	}
+
+	/**
+	 * @testdox With a lock, a lock for another contract or another extension is refused and nothing is written.
+	 */
+	public function test_a_lock_for_another_contract_or_extension_is_refused(): void {
+		$sibling      = $this->insert_released( Contract::create( array( 'extension_slug' => self::OWNER ) ) );
+		$sibling_lock = $this->sut->acquire_lock( $sibling, self::OWNER, 'hold' );
+		$this->assertInstanceOf( ContractLock::class, $sibling_lock );
+
+		try {
+			$this->sut->add_history_entry( $this->entry(), self::OWNER, $sibling_lock );
+			$this->fail( 'Expected a lock for another contract to be refused.' );
+		} catch ( InvalidArgumentException $e ) {
+			$this->assertStringContainsString( "The lock belongs to contract {$sibling}, not contract {$this->id}.", $e->getMessage() );
+		}
+
+		$foreign      = $this->insert_released( Contract::create( array( 'extension_slug' => 'another-extension' ) ) );
+		$foreign_lock = $this->sut->acquire_lock( $foreign, 'another-extension', 'hold' );
+		$this->assertInstanceOf( ContractLock::class, $foreign_lock );
+
+		try {
+			$this->sut->add_history_entry( $this->entry( array( 'contract_id' => $foreign ) ), self::OWNER, $foreign_lock );
+			$this->fail( 'Expected a lock for a contract of another extension to be refused.' );
+		} catch ( InvalidArgumentException $e ) {
+			$this->assertStringContainsString( 'another extension', $e->getMessage() );
+		}
+
+		$this->assertSame( array(), $this->sut->find_history( $this->id ) );
+		$this->assertSame( array(), $this->sut->find_history( $sibling ) );
+		$this->assertSame( array(), $this->sut->find_history( $foreign ) );
+	}
+
+	/**
+	 * @testdox A cycle of another contract, or an unknown cycle, is refused with and without a lock; a cycle of this contract is stored.
+	 */
+	public function test_the_cycle_must_belong_to_the_contract(): void {
+		$other       = $this->insert_released( Contract::create( array( 'extension_slug' => self::OWNER ) ) );
+		$other_cycle = $this->add_cycle( $other );
+		$own_cycle   = $this->add_cycle( $this->id );
+		$lock        = $this->sut->acquire_lock( $this->id, self::OWNER, 'renew' );
+		$this->assertInstanceOf( ContractLock::class, $lock );
+
+		foreach ( array( $other_cycle, 999999 ) as $cycle_id ) {
+			$modes = array(
+				'locked'   => $lock,
+				'unlocked' => null,
+			);
+			foreach ( $modes as $mode => $with ) {
+				try {
+					$this->sut->add_history_entry( $this->entry( array( 'cycle_id' => $cycle_id ) ), self::OWNER, $with );
+					$this->fail( "Expected cycle {$cycle_id} to be refused ({$mode})." );
+				} catch ( InvalidArgumentException $e ) {
+					$this->assertStringContainsString( "cycle {$cycle_id}", strtolower( $e->getMessage() ), $mode );
+				}
+			}
+		}
+		$this->assertSame( array(), $this->sut->find_history( $this->id ), 'Nothing was written.' );
+
+		$locked   = $this->sut->add_history_entry( $this->entry( array( 'cycle_id' => $own_cycle ) ), self::OWNER, $lock );
+		$unlocked = $this->sut->add_history_entry( $this->entry( array( 'cycle_id' => $own_cycle ) ), self::OWNER );
+		$this->assertInstanceOf( HistoryEntry::class, $locked );
+		$this->assertInstanceOf( HistoryEntry::class, $unlocked );
+		$this->assertSame( array( $own_cycle, $own_cycle ), $this->cycle_ids( $this->sut->find_history( $this->id ) ) );
+	}
+
+	/**
+	 * @testdox A taken creation key returns null and writes nothing, with and without a lock; it is scoped to the contract.
+	 */
+	public function test_a_taken_creation_key_is_a_lost_race(): void {
+		$other = $this->insert_released( Contract::create( array( 'extension_slug' => self::OWNER ) ) );
+		$key   = array( 'creation_key' => 'renewal-paid-7' );
+
+		$this->assertInstanceOf( HistoryEntry::class, $this->sut->add_history_entry( $this->entry( $key ), self::OWNER ) );
+		$this->assertNull( $this->sut->add_history_entry( $this->entry( $key ), self::OWNER ), 'Unlocked repeat.' );
+
+		$lock = $this->sut->acquire_lock( $this->id, self::OWNER, 'renew' );
+		$this->assertInstanceOf( ContractLock::class, $lock );
+		$this->assertNull( $this->sut->add_history_entry( $this->entry( $key ), self::OWNER, $lock ), 'Locked repeat.' );
+		$this->assertCount( 1, $this->sut->find_history( $this->id ) );
+
+		$this->assertInstanceOf( HistoryEntry::class, $this->sut->add_history_entry( $this->entry( $key + array( 'contract_id' => $other ) ), self::OWNER ), 'Another contract may use the key.' );
+	}
+
+	/**
+	 * @testdox Creation keys differing only by surrounding spaces collide (trimmed); keys differing by case do not (binary).
+	 */
+	public function test_creation_keys_compare_trimmed_and_binary(): void {
+		$this->assertInstanceOf( HistoryEntry::class, $this->sut->add_history_entry( $this->entry( array( 'creation_key' => 'created' ) ), self::OWNER ) );
+		$this->assertNull( $this->sut->add_history_entry( $this->entry( array( 'creation_key' => 'created  ' ) ), self::OWNER ) );
+		$this->assertInstanceOf( HistoryEntry::class, $this->sut->add_history_entry( $this->entry( array( 'creation_key' => 'Created' ) ), self::OWNER ) );
+		$this->assertCount( 2, $this->sut->find_history( $this->id ) );
+	}
+
+	/**
+	 * @testdox The payload round-trips through storage: nested arrays, unicode and null.
+	 */
+	public function test_the_payload_round_trips(): void {
+		$payload = array(
+			'text'   => 'Café ☕ "quoted" <b>markup</b>',
+			'nested' => array(
+				'list' => array( 1, 2.5, true, null ),
+				'map'  => array( 'deep' => array( 'deeper' => 'yes' ) ),
+			),
+		);
+
+		$this->sut->add_history_entry( $this->entry( array( 'payload' => $payload ) ), self::OWNER );
+		$this->sut->add_history_entry( $this->entry( array( 'type' => 'held' ) ), self::OWNER );
+
+		$entries = $this->sut->find_history( $this->id );
+		$this->assertNull( $entries[0]->get_payload() );
+		$this->assertSame( $payload, $entries[1]->get_payload() );
+	}
+
+	/**
+	 * @testdox The returned entry's payload matches a fresh read: a nested object comes back as an array, and null stays null.
+	 */
+	public function test_the_returned_payload_matches_a_fresh_read(): void {
+		$with_object = $this->sut->add_history_entry( $this->entry( array( 'payload' => array( 'actor' => (object) array( 'role' => 'system' ) ) ) ), self::OWNER );
+		$without     = $this->sut->add_history_entry( $this->entry(), self::OWNER );
+		$this->assertNotNull( $with_object );
+		$this->assertNotNull( $without );
+
+		$this->assertSame( array( 'actor' => array( 'role' => 'system' ) ), $with_object->get_payload() );
+		$this->assertNull( $without->get_payload() );
+		$entries = $this->sut->find_history( $this->id );
+		$this->assertSame( $entries[1]->get_payload(), $with_object->get_payload() );
+	}
+
+	/**
+	 * @testdox A failed insert throws RuntimeException and stores nothing ($mode).
+	 * @dataProvider provide_failed_insert_modes
+	 *
+	 * @param string $mode     Case name.
+	 * @param bool   $locked   Whether the insert is made with the caller's lock.
+	 * @param bool   $with_key Whether the entry carries a creation key.
+	 */
+	public function test_a_failed_insert_throws( string $mode, bool $locked, bool $with_key ): void {
+		$lock = null;
+		if ( $locked ) {
+			$lock = $this->sut->acquire_lock( $this->id, self::OWNER, 'renew' );
+			$this->assertInstanceOf( ContractLock::class, $lock );
+		}
+		$entry = $this->entry( $with_key ? array( 'creation_key' => 'renewal-paid-9' ) : array() );
+
+		$this->fail_next_query( '/^INSERT INTO \S*contract_history/' );
+		try {
+			$this->sut->add_history_entry( $entry, self::OWNER, $lock );
+			$this->fail( "Expected the failed insert to throw ({$mode})." );
+		} catch ( ContractLockedException $e ) {
+			$this->fail( "The lock is still held, so the failure is not a lock conflict ({$mode})." );
+		} catch ( RuntimeException $e ) {
+			$this->assertStringContainsString( "Failed to add a history entry to contract {$this->id}", $e->getMessage() );
+		}
+
+		$this->assertSame( array(), $this->sut->find_history( $this->id ) );
+	}
+
+	/**
+	 * @return array<string, array{0: string, 1: bool, 2: bool}>
+	 */
+	public function provide_failed_insert_modes(): array {
+		return array(
+			'unlocked, no key' => array( 'unlocked, no key', false, false ),
+			'unlocked, keyed'  => array( 'unlocked, keyed', false, true ),
+			'locked, no key'   => array( 'locked, no key', true, false ),
+			'locked, keyed'    => array( 'locked, keyed', true, true ),
+		);
+	}
+
+	/**
+	 * @testdox A failed insert made with a lock lost meanwhile throws ContractLockedException.
+	 */
+	public function test_a_failed_insert_with_a_lost_lock_is_a_lock_conflict(): void {
+		$this->pin_db_clock( '2035-01-01 00:00:00' );
+		$old = $this->sut->acquire_lock( $this->id, self::OWNER, 'renew' );
+		$this->assertInstanceOf( ContractLock::class, $old );
+		$this->pin_db_clock( '2035-01-01 00:10:00' );
+		$this->assertInstanceOf( ContractLock::class, $this->sut->acquire_lock( $this->id, self::OWNER, 'cancel' ) );
+
+		// The old lock is still inside its trusted window, so the fence lets the insert run.
+		$this->fail_next_query( '/^INSERT INTO \S*contract_history/' );
+		try {
+			$this->sut->add_history_entry( $this->entry(), self::OWNER, $old );
+			$this->fail( 'Expected the lost lock to be reported.' );
+		} catch ( ContractLockedException $e ) {
+			$this->assertSame( 'cancel', $e->get_operation() );
+		}
+
+		$this->assertSame( array(), $this->sut->find_history( $this->id ) );
+	}
+
+	/**
+	 * @testdox The creation-key fallback read finds a key only on its own contract and matches it exactly.
+	 */
+	public function test_creation_key_fallback_read(): void {
+		$other = $this->insert_released( Contract::create( array( 'extension_slug' => self::OWNER ) ) );
+		$this->sut->add_history_entry( $this->entry( array( 'creation_key' => 'renewal-paid-7' ) ), self::OWNER );
+
+		$this->assertTrue( $this->call_private( $this->sut, 'has_history_creation_key', $this->id, 'renewal-paid-7' ) );
+		$this->assertFalse( $this->call_private( $this->sut, 'has_history_creation_key', $this->id, 'RENEWAL-PAID-7' ) );
+		$this->assertFalse( $this->call_private( $this->sut, 'has_history_creation_key', $other, 'renewal-paid-7' ) );
+	}
+
+	/**
+	 * @testdox find_history() returns entries newest first and pages with limit and offset.
+	 */
+	public function test_find_history_pages_newest_first(): void {
+		foreach ( array( 'a', 'b', 'c', 'd', 'e' ) as $type ) {
+			$this->sut->add_history_entry( $this->entry( array( 'type' => $type ) ), self::OWNER );
+		}
+
+		$this->assertSame( array( 'e', 'd', 'c', 'b', 'a' ), $this->types( $this->sut->find_history( $this->id ) ) );
+		$this->assertSame( array( 'e', 'd' ), $this->types( $this->sut->find_history( $this->id, 2, 0 ) ) );
+		$this->assertSame( array( 'c', 'b' ), $this->types( $this->sut->find_history( $this->id, 2, 2 ) ) );
+		$this->assertSame( array( 'a' ), $this->types( $this->sut->find_history( $this->id, 2, 4 ) ) );
+		$this->assertSame( array(), $this->sut->find_history( 999999 ) );
+	}
+
+	/**
+	 * @testdox find_history() throws on a failed read instead of returning an empty history.
+	 */
+	public function test_find_history_throws_on_a_failed_read(): void {
+		$this->fail_next_query( '/^SELECT \* FROM \S*contract_history/' );
+
+		$this->expectException( RuntimeException::class );
+		$this->sut->find_history( $this->id );
+	}
+
+	/**
+	 * @testdox delete() removes the contract's history with it, and no other contract's.
+	 */
+	public function test_delete_removes_the_history(): void {
+		$other = $this->insert_released( Contract::create( array( 'extension_slug' => self::OWNER ) ) );
+		$this->sut->add_history_entry( $this->entry(), self::OWNER );
+		$this->sut->add_history_entry( $this->entry( array( 'contract_id' => $other ) ), self::OWNER );
+
+		$this->assertTrue( $this->sut->delete( $this->id ) );
+
+		$this->assertSame( array(), $this->sut->find_history( $this->id ) );
+		$this->assertCount( 1, $this->sut->find_history( $other ) );
+	}
+
+	/**
+	 * A new entry on the fixture contract.
+	 *
+	 * @param array<string, mixed> $overrides Entry attributes to replace.
+	 */
+	private function entry( array $overrides = array() ): HistoryEntry {
+		return HistoryEntry::create(
+			$overrides + array(
+				'contract_id' => $this->id,
+				'type'        => 'held',
+			)
+		);
+	}
+
+	/**
+	 * Add a billing cycle to a contract and return its id.
+	 *
+	 * @param int $contract_id Contract id.
+	 */
+	private function add_cycle( int $contract_id ): int {
+		$cycle = $this->add_cycle_locked(
+			$contract_id,
+			array(
+				'starts_at_gmt' => '2026-07-15 00:00:00',
+				'ends_at_gmt'   => '2026-08-15 00:00:00',
+				'currency'      => 'USD',
+			)
+		);
+		$this->assertNotNull( $cycle );
+
+		return $cycle->get_id();
+	}
+
+	/**
+	 * The types of entries, in order.
+	 *
+	 * @param array<int, HistoryEntry> $entries Entries.
+	 * @return array<int, string>
+	 */
+	private function types( array $entries ): array {
+		return array_map(
+			static function ( HistoryEntry $entry ): string {
+				return $entry->get_type();
+			},
+			$entries
+		);
+	}
+
+	/**
+	 * The cycle ids of entries, in order.
+	 *
+	 * @param array<int, HistoryEntry> $entries Entries.
+	 * @return array<int, int|null>
+	 */
+	private function cycle_ids( array $entries ): array {
+		return array_map(
+			static function ( HistoryEntry $entry ): ?int {
+				return $entry->get_cycle_id();
+			},
+			$entries
+		);
+	}
+}
diff --git a/packages/php/woocommerce-subscriptions-engine/tests/integration/Integration/Storage/ContractLockTest.php b/packages/php/woocommerce-subscriptions-engine/tests/integration/Integration/Storage/ContractLockTest.php
index c520e2c2cc8..e82a4d3830c 100644
--- a/packages/php/woocommerce-subscriptions-engine/tests/integration/Integration/Storage/ContractLockTest.php
+++ b/packages/php/woocommerce-subscriptions-engine/tests/integration/Integration/Storage/ContractLockTest.php
@@ -659,7 +659,7 @@ class ContractLockTest extends EngineIntegrationTestCase {
 		$this->assertInstanceOf( Contract::class, $stored );
 		$this->assertSame( array(), $stored->get_items(), 'No item row is written.' );
 		$this->assertSame( array(), $stored->get_addresses(), 'No address row is written.' );
-		$this->assertSame( array(), $this->sut->find_cycle_history( $id ), 'No cycle row is written.' );
+		$this->assertSame( array(), $this->sut->find_cycles( $id ), 'No cycle row is written.' );
 	}

 	/**
diff --git a/packages/php/woocommerce-subscriptions-engine/tests/integration/Integration/Storage/ContractRepositoryTest.php b/packages/php/woocommerce-subscriptions-engine/tests/integration/Integration/Storage/ContractRepositoryTest.php
index bb4a2824429..d9ddff6b7a4 100644
--- a/packages/php/woocommerce-subscriptions-engine/tests/integration/Integration/Storage/ContractRepositoryTest.php
+++ b/packages/php/woocommerce-subscriptions-engine/tests/integration/Integration/Storage/ContractRepositoryTest.php
@@ -979,21 +979,21 @@ class ContractRepositoryTest extends EngineIntegrationTestCase {
 	}

 	/**
-	 * @testdox find_cycle_history returns a window of cycles newest first.
+	 * @testdox find_cycles returns a window of cycles newest first.
 	 */
-	public function test_find_cycle_history_pages_newest_first(): void {
+	public function test_find_cycles_pages_newest_first(): void {
 		$id = $this->insert_released( $this->make_contract() );

 		for ( $n = 1; $n <= 3; $n++ ) {
 			$this->append_cycle_locked( $this->make_cycle( $id, $n, $n, sprintf( '2026-%02d-15 00:00:00', 6 + $n ), sprintf( '2026-%02d-15 00:00:00', 7 + $n ) ) );
 		}

-		$page = $this->sut->find_cycle_history( $id, Cycle::KIND_BILLING, 2, 0 );
+		$page = $this->sut->find_cycles( $id, Cycle::KIND_BILLING, 2, 0 );
 		$this->assertCount( 2, $page );
 		$this->assertSame( 3, $page[0]->get_sequence_no() );
 		$this->assertSame( 2, $page[1]->get_sequence_no() );

-		$next = $this->sut->find_cycle_history( $id, Cycle::KIND_BILLING, 2, 2 );
+		$next = $this->sut->find_cycles( $id, Cycle::KIND_BILLING, 2, 2 );
 		$this->assertCount( 1, $next );
 		$this->assertSame( 1, $next[0]->get_sequence_no() );
 	}
@@ -1429,7 +1429,7 @@ class ContractRepositoryTest extends EngineIntegrationTestCase {
 			$this->assertStringContainsString( 'longer than the column allows', $e->getMessage() );
 		}
 		$this->assertNull( $over_long->get_id(), 'Nothing is inserted.' );
-		$this->assertSame( array(), $this->sut->find_cycle_history( $id, str_repeat( 'k', 21 ) ) );
+		$this->assertSame( array(), $this->sut->find_cycles( $id, str_repeat( 'k', 21 ) ) );

 		$fits = $this->make_cycle_of_kind( $id, str_repeat( 'k', 20 ) );
 		$this->append_cycle_locked( $fits );
@@ -1620,13 +1620,13 @@ class ContractRepositoryTest extends EngineIntegrationTestCase {
 	 * @param int $contract_id Contract id.
 	 */
 	private function find_newest_cycle( int $contract_id ): ?Cycle {
-		$history = $this->sut->find_cycle_history( $contract_id, Cycle::KIND_BILLING, 1 );
+		$cycles = $this->sut->find_cycles( $contract_id, Cycle::KIND_BILLING, 1 );

-		return $history[0] ?? null;
+		return $cycles[0] ?? null;
 	}

 	/**
-	 * Read a billing cycle by id through its chain history.
+	 * Read a billing cycle by id through its chain.
 	 *
 	 * @param int $cycle_id Cycle id.
 	 */
@@ -1637,7 +1637,7 @@ class ContractRepositoryTest extends EngineIntegrationTestCase {
 		// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.PreparedSQL.InterpolatedNotPrepared
 		$contract_id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT contract_id FROM {$table} WHERE id = %d", $cycle_id ) );

-		foreach ( $this->sut->find_cycle_history( $contract_id ) as $cycle ) {
+		foreach ( $this->sut->find_cycles( $contract_id ) as $cycle ) {
 			if ( $cycle->get_id() === $cycle_id ) {
 				return $cycle;
 			}
@@ -1688,9 +1688,9 @@ class ContractRepositoryTest extends EngineIntegrationTestCase {
 		$this->assertInstanceOf( Cycle::class, $head );
 		$this->assertSame( 'legacy-x', $head->get_status()->get_value() );

-		$history = $this->sut->find_cycle_history( $id );
-		$this->assertCount( 1, $history );
-		$this->assertSame( 'legacy-x', $history[0]->get_status()->get_value() );
+		$cycles = $this->sut->find_cycles( $id );
+		$this->assertCount( 1, $cycles );
+		$this->assertSame( 'legacy-x', $cycles[0]->get_status()->get_value() );
 	}

 	/**
@@ -2013,9 +2013,9 @@ class ContractRepositoryTest extends EngineIntegrationTestCase {
 	}

 	/**
-	 * @testdox find_cycle_history throws on a failed read instead of returning an empty chain.
+	 * @testdox find_cycles throws on a failed read instead of returning an empty chain.
 	 */
-	public function test_find_cycle_history_throws_on_a_failed_read(): void {
+	public function test_find_cycles_throws_on_a_failed_read(): void {
 		$id = $this->insert_released( $this->make_contract() );
 		$this->append_cycle_locked( $this->make_cycle( $id, 1, 1, '2026-07-15 00:00:00', '2026-08-15 00:00:00' ) );

@@ -2024,7 +2024,7 @@ class ContractRepositoryTest extends EngineIntegrationTestCase {
 		$this->expectException( \RuntimeException::class );
 		$this->expectExceptionMessage( "Failed to read the cycles of contract {$id}" );

-		$this->sut->find_cycle_history( $id );
+		$this->sut->find_cycles( $id );
 	}

 	/**
@@ -2118,7 +2118,7 @@ class ContractRepositoryTest extends EngineIntegrationTestCase {
 		$this->expectException( \RuntimeException::class );
 		$this->expectExceptionMessage( "Failed to read snapshot {$snapshot_ids[ $skip ]}:" );

-		$this->sut->find_cycle_history( $id );
+		$this->sut->find_cycles( $id );
 	}

 	/**
@@ -2159,10 +2159,10 @@ class ContractRepositoryTest extends EngineIntegrationTestCase {
 		$this->append_cycle_locked( $this->make_cycle( $id, 1, null, '2026-07-15 00:00:00', '2026-08-15 00:00:00' ) );
 		$this->append_cycle_locked( $this->make_cycle( $id, 2, null, '2026-08-15 00:00:00', '2026-09-15 00:00:00' ) );

-		$history = $this->sut->find_cycle_history( $id );
-		$this->assertCount( 2, $history );
-		$this->assertNull( $history[0]->get_count() );
-		$this->assertNull( $history[1]->get_count() );
+		$cycles = $this->sut->find_cycles( $id );
+		$this->assertCount( 2, $cycles );
+		$this->assertNull( $cycles[0]->get_count() );
+		$this->assertNull( $cycles[1]->get_count() );
 	}

 	/**
@@ -2419,7 +2419,7 @@ class ContractRepositoryTest extends EngineIntegrationTestCase {
 		} catch ( ContractLockedException $e ) {
 			$this->assertSame( 'cancel', $e->get_operation() );
 		}
-		$this->assertCount( 1, $this->sut->find_cycle_history( $id ), 'Nothing is appended.' );
+		$this->assertCount( 1, $this->sut->find_cycles( $id ), 'Nothing is appended.' );

 		try {
 			$this->sut->transition_cycle( $cycle_id, CycleStatus::FAILED, CycleStatus::BILLED, array(), $lock );
@@ -2441,7 +2441,7 @@ class ContractRepositoryTest extends EngineIntegrationTestCase {
 		$this->sut->append_cycle( $cycle, $lock );

 		$this->assertNotNull( $cycle->get_id() );
-		$this->assertCount( 1, $this->sut->find_cycle_history( $id ) );
+		$this->assertCount( 1, $this->sut->find_cycles( $id ) );
 	}

 	/**
diff --git a/packages/php/woocommerce-subscriptions-engine/tests/integration/Integration/Storage/SchemaInstallerTest.php b/packages/php/woocommerce-subscriptions-engine/tests/integration/Integration/Storage/SchemaInstallerTest.php
index 787ce296bdb..7cdb3b29589 100644
--- a/packages/php/woocommerce-subscriptions-engine/tests/integration/Integration/Storage/SchemaInstallerTest.php
+++ b/packages/php/woocommerce-subscriptions-engine/tests/integration/Integration/Storage/SchemaInstallerTest.php
@@ -34,6 +34,7 @@ class SchemaInstallerTest extends EngineIntegrationTestCase {
 			array( SchemaInstaller::TABLE_CONTRACT_META ),
 			array( SchemaInstaller::TABLE_CYCLES ),
 			array( SchemaInstaller::TABLE_SNAPSHOTS ),
+			array( SchemaInstaller::TABLE_CONTRACT_HISTORY ),
 		);
 	}

@@ -291,10 +292,10 @@ class SchemaInstallerTest extends EngineIntegrationTestCase {
 	}

 	/**
-	 * @testdox The schema version is 2.9.0 (binary owner columns).
+	 * @testdox The schema version is 2.10.0 (contract history table).
 	 */
-	public function test_schema_version_is_2_9_0(): void {
-		$this->assertSame( '2.9.0', SchemaInstaller::get_version() );
+	public function test_schema_version_is_2_10_0(): void {
+		$this->assertSame( '2.10.0', SchemaInstaller::get_version() );
 	}

 	/**
@@ -682,6 +683,52 @@ class SchemaInstallerTest extends EngineIntegrationTestCase {
 		);
 	}

+	/**
+	 * @testdox The contract history table has its columns, with a nullable cycle, key and payload.
+	 */
+	public function test_contract_history_table_columns(): void {
+		global $wpdb;
+
+		$table    = SchemaInstaller::get_table_name( SchemaInstaller::TABLE_CONTRACT_HISTORY );
+		$expected = array(
+			'id'               => 'NO',
+			'contract_id'      => 'NO',
+			'cycle_id'         => 'YES',
+			'type'             => 'NO',
+			'creation_key'     => 'YES',
+			'payload'          => 'YES',
+			'date_created_gmt' => 'NO',
+		);
+
+		// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.PreparedSQL.InterpolatedNotPrepared
+		$rows    = $wpdb->get_results( "SHOW FULL COLUMNS FROM {$table}", ARRAY_A );
+		$actual  = array();
+		$collate = array();
+		foreach ( is_array( $rows ) ? $rows : array() as $row ) {
+			if ( is_array( $row ) ) {
+				$field             = Coercion::coerce_string( $row['Field'] ?? null );
+				$actual[ $field ]  = Coercion::coerce_string( $row['Null'] ?? null );
+				$collate[ $field ] = $row['Collation'] ?? null;
+			}
+		}
+
+		$this->assertSame( $expected, $actual );
+		$this->assertSame( $wpdb->charset . '_bin', $collate['creation_key'], 'The creation key compares binary.' );
+	}
+
+	/**
+	 * @testdox The contract history table keys reads by contract and makes the creation key unique per contract.
+	 */
+	public function test_contract_history_table_indexes(): void {
+		$table = SchemaInstaller::get_table_name( SchemaInstaller::TABLE_CONTRACT_HISTORY );
+
+		$this->assertEqualsCanonicalizing( array( 'PRIMARY', 'contract', 'creation' ), $this->index_names( $table ) );
+		$this->assertSame( array( 'contract_id' ), $this->index_columns( $table, 'contract' ) );
+		$this->assertFalse( $this->index_is_unique( $table, 'contract' ) );
+		$this->assertSame( array( 'contract_id', 'creation_key' ), $this->index_columns( $table, 'creation' ) );
+		$this->assertTrue( $this->index_is_unique( $table, 'creation' ) );
+	}
+
 	/**
 	 * Whether `$table` has a column named `$column`.
 	 *
diff --git a/packages/php/woocommerce-subscriptions-engine/tests/unit/Api/View/HistoryEntryViewTest.php b/packages/php/woocommerce-subscriptions-engine/tests/unit/Api/View/HistoryEntryViewTest.php
new file mode 100644
index 00000000000..94bbca4579a
--- /dev/null
+++ b/packages/php/woocommerce-subscriptions-engine/tests/unit/Api/View/HistoryEntryViewTest.php
@@ -0,0 +1,62 @@
+<?php
+/**
+ * Unit tests for the HistoryEntryView DTO.
+ *
+ * @package Automattic\WooCommerce\SubscriptionsEngine
+ */
+
+declare( strict_types=1 );
+
+namespace Automattic\WooCommerce\SubscriptionsEngine\Tests\Unit\Api\View;
+
+use PHPUnit\Framework\TestCase;
+use Automattic\WooCommerce\SubscriptionsEngine\Api\View\HistoryEntryView;
+use Automattic\WooCommerce\SubscriptionsEngine\Core\Entity\HistoryEntry;
+
+/**
+ * @covers \Automattic\WooCommerce\SubscriptionsEngine\Api\View\HistoryEntryView
+ */
+class HistoryEntryViewTest extends TestCase {
+
+	public function test_every_getter_reads_the_stored_row(): void {
+		$entry = HistoryEntry::from_storage(
+			array(
+				'id'               => '9',
+				'contract_id'      => '10',
+				'cycle_id'         => '4',
+				'type'             => 'renewal-failed',
+				'creation_key'     => 'renewal-failed-4-77',
+				'payload'          => '{"order_id":77}',
+				'date_created_gmt' => '2026-02-01 00:00:00',
+			)
+		);
+
+		$view = HistoryEntryView::from_entry( $entry );
+
+		$this->assertSame( 9, $view->get_id() );
+		$this->assertSame( 10, $view->get_contract_id() );
+		$this->assertSame( 4, $view->get_cycle_id() );
+		$this->assertSame( 'renewal-failed', $view->get_type() );
+		$this->assertSame( array( 'order_id' => 77 ), $view->get_payload() );
+		$this->assertSame( '2026-02-01 00:00:00', $view->get_date_created_gmt() );
+		$this->assertFalse( ( new \ReflectionClass( HistoryEntryView::class ) )->hasMethod( 'get_creation_key' ), 'The creation key is not exposed.' );
+	}
+
+	public function test_an_entry_without_a_cycle_or_payload_reads_null(): void {
+		$entry = HistoryEntry::from_storage(
+			array(
+				'id'               => 1,
+				'contract_id'      => 2,
+				'cycle_id'         => null,
+				'type'             => 'held',
+				'payload'          => null,
+				'date_created_gmt' => '2026-02-01 00:00:00',
+			)
+		);
+
+		$view = HistoryEntryView::from_entry( $entry );
+
+		$this->assertNull( $view->get_cycle_id() );
+		$this->assertNull( $view->get_payload() );
+	}
+}
diff --git a/packages/php/woocommerce-subscriptions-engine/tests/unit/Core/Entity/HistoryEntryTest.php b/packages/php/woocommerce-subscriptions-engine/tests/unit/Core/Entity/HistoryEntryTest.php
new file mode 100644
index 00000000000..642d00d725e
--- /dev/null
+++ b/packages/php/woocommerce-subscriptions-engine/tests/unit/Core/Entity/HistoryEntryTest.php
@@ -0,0 +1,231 @@
+<?php
+/**
+ * Unit tests for the HistoryEntry entity.
+ *
+ * @package Automattic\WooCommerce\SubscriptionsEngine
+ */
+
+declare( strict_types=1 );
+
+namespace Automattic\WooCommerce\SubscriptionsEngine\Tests\Unit\Core\Entity;
+
+use ReflectionClass;
+use ReflectionMethod;
+use PHPUnit\Framework\TestCase;
+use Automattic\WooCommerce\SubscriptionsEngine\Core\Entity\HistoryEntry;
+use Automattic\WooCommerce\SubscriptionsEngine\Core\Support\ArgumentValidator;
+use Automattic\WooCommerce\SubscriptionsEngine\Core\Support\ValidationErrorCode;
+use Automattic\WooCommerce\SubscriptionsEngine\Tests\Unit\AssertsInvalidInput;
+
+/**
+ * @covers \Automattic\WooCommerce\SubscriptionsEngine\Core\Entity\HistoryEntry
+ */
+class HistoryEntryTest extends TestCase {
+
+	use AssertsInvalidInput;
+
+	/**
+	 * @testdox create() builds an unsaved entry from the given attributes.
+	 */
+	public function test_create_builds_an_unsaved_entry(): void {
+		$entry = HistoryEntry::create(
+			array(
+				'id'               => 99,
+				'contract_id'      => 7,
+				'cycle_id'         => 3,
+				'type'             => 'renewal-paid',
+				'creation_key'     => 'renewal-paid-3',
+				'payload'          => array( 'actor' => array( 'role' => 'system' ) ),
+				'date_created_gmt' => '2026-01-01 00:00:00',
+			)
+		);
+
+		$this->assertNull( $entry->get_id() );
+		$this->assertNull( $entry->get_date_created_gmt() );
+		$this->assertSame( 7, $entry->get_contract_id() );
+		$this->assertSame( 3, $entry->get_cycle_id() );
+		$this->assertSame( 'renewal-paid', $entry->get_type() );
+		$this->assertSame( 'renewal-paid-3', $entry->to_storage()['creation_key'] );
+		$this->assertSame( array( 'actor' => array( 'role' => 'system' ) ), $entry->get_payload() );
+	}
+
+	/**
+	 * @testdox create() reports every invalid attribute at once, each with its code and field.
+	 */
+	public function test_create_reports_every_error_at_once(): void {
+		$this->assert_invalid_inputs(
+			static function (): void {
+				HistoryEntry::create(
+					array(
+						'contract_id'  => 7,
+						'type'         => 'Not A Slug',
+						'creation_key' => '   ',
+						'payload'      => array( 'amount' => NAN ),
+					)
+				);
+			},
+			array(
+				array( ValidationErrorCode::INVALID_PATTERN, 'type', array( 'pattern' => ArgumentValidator::SLUG_PATTERN ) ),
+				array( ValidationErrorCode::INVALID_VALUE, 'creation_key', array() ),
+				array( ValidationErrorCode::INVALID_VALUE, 'payload', array() ),
+			)
+		);
+	}
+
+	/**
+	 * @testdox create() refuses an invalid $field value with $code.
+	 * @dataProvider provide_invalid_attributes
+	 *
+	 * @param array<string, mixed> $args  Entry attributes.
+	 * @param string               $code  Expected error code.
+	 * @param string               $field Expected field.
+	 */
+	public function test_create_refuses_an_invalid_attribute( array $args, string $code, string $field ): void {
+		$this->assert_invalid_inputs(
+			static function () use ( $args ): void {
+				HistoryEntry::create( $args + array( 'contract_id' => 7 ) );
+			},
+			array( array( $code, $field ) )
+		);
+	}
+
+	/**
+	 * @return array<string, array{0: array<string, mixed>, 1: string, 2: string}>
+	 */
+	public function provide_invalid_attributes(): array {
+		return array(
+			'missing type'          => array( array(), ValidationErrorCode::REQUIRED, 'type' ),
+			'empty type'            => array( array( 'type' => '' ), ValidationErrorCode::REQUIRED, 'type' ),
+			'non-string type'       => array( array( 'type' => 5 ), ValidationErrorCode::INVALID_TYPE, 'type' ),
+			'over-long type'        => array( array( 'type' => str_repeat( 'a', 65 ) ), ValidationErrorCode::INVALID_PATTERN, 'type' ),
+			'malformed type'        => array( array( 'type' => 'held!' ), ValidationErrorCode::INVALID_PATTERN, 'type' ),
+			'non-array payload'     => array(
+				array(
+					'type'    => 'note',
+					'payload' => 'text',
+				),
+				ValidationErrorCode::INVALID_TYPE,
+				'payload',
+			),
+			'non-encodable payload' => array(
+				array(
+					'type'    => 'note',
+					'payload' => array( 'text' => "\xB1\x31" ),
+				),
+				ValidationErrorCode::INVALID_VALUE,
+				'payload',
+			),
+			'non-string key'        => array(
+				array(
+					'type'         => 'note',
+					'creation_key' => 5,
+				),
+				ValidationErrorCode::INVALID_TYPE,
+				'creation_key',
+			),
+			'blank key'             => array(
+				array(
+					'type'         => 'note',
+					'creation_key' => '',
+				),
+				ValidationErrorCode::INVALID_VALUE,
+				'creation_key',
+			),
+			'over-long key'         => array(
+				array(
+					'type'         => 'note',
+					'creation_key' => str_repeat( 'k', 101 ),
+				),
+				ValidationErrorCode::INVALID_VALUE,
+				'creation_key',
+			),
+		);
+	}
+
+	/**
+	 * @testdox The creation key is trimmed of surrounding whitespace.
+	 */
+	public function test_create_trims_the_creation_key(): void {
+		$entry = HistoryEntry::create(
+			array(
+				'contract_id'  => 7,
+				'type'         => 'created',
+				'creation_key' => " created \n",
+			)
+		);
+
+		$this->assertSame( 'created', $entry->to_storage()['creation_key'] );
+	}
+
+	/**
+	 * @testdox The payload leaves to_storage() as an array and is decoded from JSON on hydration.
+	 */
+	public function test_payload_round_trips_through_storage(): void {
+		$payload = array(
+			'text'   => 'Café ☕',
+			'nested' => array( 1, 2, array( 'deep' => true ) ),
+		);
+		$entry   = HistoryEntry::create(
+			array(
+				'contract_id' => 7,
+				'type'        => 'note',
+				'payload'     => $payload,
+			)
+		);
+
+		$stored = $entry->to_storage();
+		$this->assertSame( $payload, $stored['payload'] );
+
+		$stored['payload']          = json_encode( $payload ); // phpcs:ignore WordPress.WP.AlternativeFunctions.json_encode_json_encode
+		$stored['id']               = 5;
+		$stored['date_created_gmt'] = '2026-01-01 00:00:00';
+		$hydrated                   = HistoryEntry::from_storage( $stored );
+
+		$this->assertSame( 5, $hydrated->get_id() );
+		$this->assertSame( '2026-01-01 00:00:00', $hydrated->get_date_created_gmt() );
+		$this->assertSame( $payload, $hydrated->get_payload() );
+	}
+
+	/**
+	 * @testdox A null payload stays null in storage and on hydration.
+	 */
+	public function test_null_payload_stays_null(): void {
+		$entry = HistoryEntry::create(
+			array(
+				'contract_id' => 7,
+				'type'        => 'held',
+			)
+		);
+
+		$this->assertNull( $entry->to_storage()['payload'] );
+		$this->assertNull( HistoryEntry::from_storage( $entry->to_storage() )->get_payload() );
+	}
+
+	/**
+	 * @testdox from_storage() does not validate stored values.
+	 */
+	public function test_from_storage_does_not_validate(): void {
+		$entry = HistoryEntry::from_storage(
+			array(
+				'id'          => '4',
+				'contract_id' => '7',
+				'type'        => 'Not A Slug',
+				'payload'     => 'not json',
+			)
+		);
+
+		$this->assertSame( 4, $entry->get_id() );
+		$this->assertSame( 'Not A Slug', $entry->get_type() );
+		$this->assertNull( $entry->get_payload() );
+	}
+
+	/**
+	 * @testdox The entity is immutable: it has no setters.
+	 */
+	public function test_the_entity_has_no_setters(): void {
+		$methods = ( new ReflectionClass( HistoryEntry::class ) )->getMethods( ReflectionMethod::IS_PUBLIC );
+		foreach ( $methods as $method ) {
+			$this->assertStringStartsNotWith( 'set_', $method->getName() );
+		}
+	}
+}
diff --git a/packages/php/woocommerce-subscriptions-engine/tests/unit/Core/Support/ArgumentValidatorTest.php b/packages/php/woocommerce-subscriptions-engine/tests/unit/Core/Support/ArgumentValidatorTest.php
index e3d93d261db..85cad4a4fd3 100644
--- a/packages/php/woocommerce-subscriptions-engine/tests/unit/Core/Support/ArgumentValidatorTest.php
+++ b/packages/php/woocommerce-subscriptions-engine/tests/unit/Core/Support/ArgumentValidatorTest.php
@@ -49,6 +49,10 @@ class ArgumentValidatorTest extends TestCase {
 			'extension slug'        => array( 'validate_extension_slug', array( 'extension_slug', 'woocommerce-subscriptions-lite' ), 'woocommerce-subscriptions-lite' ),
 			'extension slug chars'  => array( 'validate_extension_slug', array( 'extension_slug', 'acme_2-x' ), 'acme_2-x' ),
 			'extension slug 64'     => array( 'validate_extension_slug', array( 'extension_slug', str_repeat( 'a', 64 ) ), str_repeat( 'a', 64 ) ),
+			'slug'                  => array( 'validate_slug', array( 'type', 'renewal-paid_2' ), 'renewal-paid_2' ),
+			'creation key'          => array( 'validate_creation_key', array( 'renewal-paid-12' ), 'renewal-paid-12' ),
+			'creation key null'     => array( 'validate_creation_key', array( null ), null ),
+			'creation key 100'      => array( 'validate_creation_key', array( str_repeat( 'é', 100 ) ), str_repeat( 'é', 100 ) ),
 			'nullable string'       => array( 'validate_nullable_string', array( 'title', null ), null ),
 			'nullable id as digits' => array( 'validate_nullable_id', array( 'order_id', '42' ), 42 ),
 			'nullable id null'      => array( 'validate_nullable_id', array( 'order_id', null ), null ),
@@ -153,6 +157,12 @@ class ArgumentValidatorTest extends TestCase {
 			'slug 65 characters'    => array( 'validate_extension_slug', array( 'extension_slug', str_repeat( 'a', 65 ) ), ValidationErrorCode::INVALID_PATTERN, 'extension_slug', $slug_pattern ),
 			'slug empty'            => array( 'validate_extension_slug', array( 'extension_slug', '' ), ValidationErrorCode::REQUIRED, 'extension_slug', array() ),
 			'slug not string'       => array( 'validate_extension_slug', array( 'extension_slug', 5 ), ValidationErrorCode::INVALID_TYPE, 'extension_slug', $type_string ),
+			'type slug uppercase'   => array( 'validate_slug', array( 'type', 'Held' ), ValidationErrorCode::INVALID_PATTERN, 'type', $slug_pattern ),
+			'type slug null'        => array( 'validate_slug', array( 'type', null ), ValidationErrorCode::REQUIRED, 'type', array() ),
+			'type slug not string'  => array( 'validate_slug', array( 'type', 5 ), ValidationErrorCode::INVALID_TYPE, 'type', $type_string ),
+			'creation key int'      => array( 'validate_creation_key', array( 5 ), ValidationErrorCode::INVALID_TYPE, 'creation_key', $type_string ),
+			'creation key empty'    => array( 'validate_creation_key', array( '' ), ValidationErrorCode::INVALID_VALUE, 'creation_key', array() ),
+			'creation key 101'      => array( 'validate_creation_key', array( str_repeat( 'a', 101 ) ), ValidationErrorCode::INVALID_VALUE, 'creation_key', array() ),
 			'positive int type'     => array( 'validate_positive_int', array( 'quantity', null ), ValidationErrorCode::INVALID_TYPE, 'quantity', $type_integer ),
 			'positive int zero'     => array( 'validate_positive_int', array( 'quantity', 0 ), ValidationErrorCode::OUT_OF_BOUNDS, 'quantity', $min_one ),
 			'nullable id type'      => array( 'validate_nullable_id', array( 'order_id', "5\n" ), ValidationErrorCode::INVALID_TYPE, 'order_id', $type_integer ),