0027-value-date-separate-from-commit-time.md 5.9 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

Every transfer was stamped with now_millis() at commit and nothing else, so the ledger knew when an entry was recorded and never when it takes effect. Banks and fintechs need both: an entry booked today can be valued last week (a correction, a late settlement) or next week (a future-dated standing order), and a period report asks for the entries valued in that period, not the ones typed in it. Transfer queries filtered only on the commit clock, so period-correct reporting was not expressible.

The obvious shape, letting a caller set created_at, is unsafe here. created_at is the clock the balance cache folds its tail against: balance reads the closest cache point and adds every transfer committed after its watermark. A backdated created_at would place a transfer behind an existing watermark, so the cached balance would silently omit it while balance_exact included it, breaking the invariant the projection suite exists to assert.

Decision Drivers

  • A period report is worth nothing if the date it groups by is the typist's clock.
  • The balance cache's correctness depends on one clock meaning one thing.
  • A value date is a business fact that a timezone must not be able to shift.
  • The duplicate-transfer trap (ADR-0026) should not reopen on backdated entries.

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 cached balances, as above. The failure is silent and the two balance reads disagree.
  • Bad, because one column would then mean two things, and no later reader could tell which.

A separate value_date, outside the content address

Pros:

  • Good, because a value date entered wrongly could be corrected in place.

Cons:

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

A separate value_date, inside the content address (chosen)

Pros:

  • Good, because the commit clock keeps its single meaning and the balance cache is untouched.
  • Good, because two entries differing only in the day they take effect are two transfers, which closes the duplicate trap for dated entries without a reference.
  • Good, because the date is covered by the same tamper evidence as the rest of the entry.

Cons:

  • Bad, because a value date cannot be corrected in place: an entry valued wrongly is reversed and reposted.
  • Bad, because the preimage changed, so CANONICAL_VERSION is bumped and content addresses computed under an earlier version do not reproduce.

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, not an instant, because a value date is a business fact: an entry valued 20 November is valued 20 November wherever it is read, and an instant would make that depend on a reader's timezone. ValueDate::new rejects a date that does not exist, so TransferBuilder::value_date stays infallible and does not repeat the mid-chain Result that deposit has.

None means the entry takes effect the day it was committed, and is tagged in the preimage rather than omitted, so "no value date" and "valued on day zero" cannot encode identically.

A reversal carries the original's value date, so the period an entry landed in is the period it is undone in. A compensating entry valued later would leave the first period still reporting the amount it is meant to cancel. A caller who wants it dated otherwise builds the envelope and commits that.

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

Migration 013 adds a nullable transfers.value_date column with an index. It is a filterable projection of the envelope's field, written at commit and never read back, so the database can answer a period query without loading every candidate row. The book column is the same arrangement.

Positive Consequences

  • Period-correct reporting is expressible, and the as-of balance and trial balance on the roadmap now have a date to group by.
  • A backdated deposit repeats safely without a reference, because the date distinguishes it.
  • The balance projection is untouched: created_at still means the instant the ledger committed the entry.

Negative Consequences

  • CANONICAL_VERSION moves to 6, so every content address changes. Acceptable in an unreleased cycle that has already changed them once, and the version byte exists to gate exactly this.
  • Correcting a value date means reverse and repost, which is more ceremony than an update and is also the trail an auditor expects.
  • The value date is stored twice, in the envelope JSON and in its own column. The column is derived and never read back, the same compromise book already makes for the same reason.

Links

  • Follows ADR-0026, whose reference closed the duplicate-transfer trap this extends to dated entries.
  • Constrained by ADR-0019: the cache folds its tail by commit time, which is why the value date had to be a new field.
  • Extends ADR-0010's transfer log with the second date a reporting caller needs.