0027-value-date-separate-from-commit-time.md 6.5 KB

Value date, separate from commit time and inside the content address

  • Status: accepted
  • Authors: Cesar Rodas
  • Date: 2026-11-23
  • Targeted modules: kuatia-types (value_date, transfer, envelope, canonical), kuatia-core (posting_resolution), kuatia-storage, kuatia-storage-sql, kuatia (ledger)
  • Associated tickets/PRs: N/A

Context and Problem Statement

A commit stamped every transfer with now_millis() and nothing else. So the ledger knew when it recorded an entry, and never knew when that entry takes effect.

A bank and a fintech both need both dates. An entry that the ledger books today can be valued last week, as a correction or a late settlement. It can be valued next week, as a standing order with a future date. A report for a period asks for the entries valued in that period, and not the entries that someone typed in it.

A transfer query filtered on the commit clock alone. So nothing could express a report that is correct for a period.

The obvious shape is unsafe here, and that shape is a created_at that the caller sets. created_at is the clock that the balance cache folds its tail against. balance reads the closest cache point, then adds every transfer that committed after that point's watermark.

A backdated created_at would place a transfer behind a watermark that exists. The cached balance would then leave that transfer out without a word, and balance_exact would include it. That breaks the invariant which the projection suite exists to assert.

Decision Drivers

  • A report for a period is worth nothing when the date it groups by is the clock of the person who typed the entry.
  • The correctness of the balance cache depends on one clock that means one thing.
  • A value date is a business fact that a timezone must not be able to shift.
  • The trap of a duplicate transfer (ADR-0026) must not reopen on a backdated entry.

Considered Options

Let the caller set created_at

Pros:

  • Good, because it adds no field, no column and no migration.

Cons:

  • Bad, because it breaks a cached balance, as above. The failure says nothing, and the two balance reads then disagree.
  • Bad, because one column would then mean two things, and no later reader could tell which one it meant.

A separate value_date, outside the content address

Pros:

  • Good, because a correction could then fix a wrong value date in place.

Cons:

  • Bad, because two backdated deposits of one amount to one account would still collapse into one transfer, unless the caller also set a reference. So the trap of ADR-0026 stays open on exactly the path where a correction is most likely.
  • Bad, because a mutable field on a record that is otherwise immutable invites a second mutable field.

A separate value_date, inside the content address (chosen)

Pros:

  • Good, because the commit clock still means one thing, and nothing touches the balance cache.
  • Good, because two entries that differ only in the day they take effect are two transfers. That closes the duplicate trap for a dated entry, and the caller needs no reference.
  • Good, because the same tamper evidence covers the date and the rest of the entry.

Cons:

  • Bad, because nothing can correct a value date in place. The ledger reverses an entry with a wrong value and reposts it.
  • Bad, because the preimage changed. So CANONICAL_VERSION moves up, and a content address that something computed under an earlier version does not come back the same.

Decision Outcome

Chosen option: a separate ValueDate on Transfer and Envelope, inside the content address.

ValueDate is a calendar day, held as days since 1970-01-01, and it is not an instant. A value date is a business fact. An entry valued 20 November is valued 20 November wherever a reader reads it, and an instant would tie that to the reader's timezone.

ValueDate::new rejects a date that does not exist. So TransferBuilder::value_date stays infallible, and it does not repeat the Result that sits mid-chain on deposit.

None means the entry takes effect on the day of its commit. The preimage tags that case rather than leaves it out. So "no value date" and "valued on day zero" cannot encode to the same bytes.

A reversal carries the value date of the original. So the period an entry landed in is the period of its reversal. A compensating entry with a later value would leave the first period with a report of the amount that the entry is meant to cancel. A caller that wants another date builds the envelope and commits that.

TransferQuery gains from_value_date and to_value_date. They stay apart from from_ts and to_ts, because a report asks for one clock or the other and never for both at once. An entry with no value date falls outside an explicit window, rather than inside every window.

Migration 013 adds a nullable transfers.value_date column, with an index. It is a projection of the envelope's field that a filter can use. A commit writes it, and nothing reads it back. So the database can answer a query for a period and load no candidate row. The book column is the same arrangement.

Positive Consequences

  • A report that is correct for a period is now expressible. The as-of balance and the trial balance on the roadmap both have a date to group by.
  • A backdated deposit repeats safely with no reference, because the date separates it from the first one.
  • Nothing touches the balance projection. created_at still means the instant at which the ledger committed the entry.

Negative Consequences

  • CANONICAL_VERSION moves to 6, so every content address changes. That is acceptable in a cycle that has not shipped, and which already changed them once. The version byte exists to gate exactly this.
  • A correction to a value date means a reverse and a repost. That is more ceremony than an update, and it is also the trail an auditor expects.
  • The ledger stores the value date twice, in the envelope JSON and in its own column. The column is derived, and nothing reads it back. book already makes the same compromise, for the same reason.

Links

  • Follows ADR-0026. Its reference closed the trap of a duplicate transfer, and this record extends that to a dated entry.
  • Constrained by ADR-0019. The cache folds its tail by commit time, which is the reason the value date needed a new field.
  • Extends the transfer log of ADR-0010, with the second date that a caller needs for a report.