Skip to content

Fix history indices, cursor results, lazy values, and vector lookups - #30

Open
codeboost wants to merge 3 commits into
masterfrom
codex/fix-history-cursors-and-vector-lookups
Open

codeboost wants to merge 3 commits into
masterfrom
codex/fix-history-cursors-and-vector-lookups

Conversation

@codeboost

Copy link
Copy Markdown
Owner

Summary

Fix four correctness issues in history results, cursors, nested values, and vector lookups:

  • Return the zero-based committed history index so it can be passed directly to deref-at.
  • Reject nested lazy sequences before vector conversion can realize them. Failed writes preserve the prior value and history.
  • Return the value at a cursor's path from swap! and reset!, including scoped before/after values when history returns are enabled.
  • Validate vector lookup keys and bounds before coercing indices. Invalid get keys return nil or the supplied default; nth without a default and single-argument vector invocation retain their throwing behavior. Stored nil remains distinct from a missing element.

These changes correct observable API behavior without changing the storage format.

Validation

  • Regression tests reproduced all four issues before the fixes.
  • Added coverage for history bookmarks across later writes, nested cursor updates, rejection without lazy-sequence evaluation, and vector lookups in read, transaction, and frozen views on memory and file databases, including reopened files.
  • clojure -M:test: 254 tests, 4,266 assertions, no failures or errors.
  • git diff --check passes.

codeboost and others added 3 commits September 16, 2026 13:44
Extract index-in-bounds?, index-out-of-bounds!, indexed-nth, indexed-lookup
and indexed-invoke into xitdb.util.collection and use them from both
array-list wrappers, replacing four copies of the bounds check and two
identical valAt bodies. Restore the comment explaining why an in-range
index can have no cursor. Route the three lazy-sequence checks in
conversion through validation/validate-not-lazy-seq at the same point in
each converter.

No behavior change: 254 tests, 4266 assertions, 0 failures.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Fixes from the spec review of the history/cursor/vector lookup change:

- Both write wrappers implement IFn, so a vector or list can be invoked
  inside a transaction with the same contract as the read view.
- Linked-list wrappers use the shared index helpers: get returns nil or
  the default for negative, float, nil and keyword keys, nth throws out
  of bounds, and a stored nil stays distinct from a missing element.
- validation/lazy-seq? also rejects repeat/cycle/iterate seqs and walks
  existing cons and chunked-cons cells to a lazy tail without realizing
  it. A seq of a lazy concat is therefore rejected too; LazySeqTest now
  builds its list with (apply list ...).
- The deprecated history-index returns the latest zero-based index, the
  value deref-at accepts, and the return-history comment is accurate.

The vector lookup test is renamed to indexed_lookup_test and runs over
list storage in read, transaction, frozen and reopened-file views.

256 tests, 4867 assertions, 0 failures.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant