Repository navigation
Port RunID from the archive; add internal/clock (part of #702) - #714
Conversation
internal/id keeps the ULID encoding, the monotonic Generator, Random and the seeded Deterministic entropy source, and RunID with its text and JSON forms. The other six kinds, Metadata and the clock.Clock interface are not ported. The Generator takes a func() time.Time; internal/clock.Clock is the one place that reads the time. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Review of PR #714 (RunID + clock only): overall this is a reasonable, contained first increment. It reuses the archived ULID code and avoids bringing back the seven-ID framework or simulated-clock machinery. I see no reason to block it on the rest of journaling, but please address the following. Must fix — PR description will close #702 prematurely. The body includes Should simplify — archive preservation. The diff deletes several files in One correctness/design question — wall clock moving backwards. Minor — deterministic entropy in production package. Tests: Good coverage of text/JSON encoding, concurrency, monotonic IDs, bad inputs, clock normalization. After the PR description fix and clock-policy decision, I am comfortable merging this as a standalone first step. The next PR still needs to prove that a service-initiated backtest uses it and journals every run. |
…millisecond (#702) The port copies instead of moving, so _archive/internal/id is as it was. The Generator no longer fails when the clock steps back: it carries on from the last millisecond it used, so a run can always get an ID and IDs still sort in order. ErrClockMovedBackward is gone. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Addressed in d511c26 (not merged).
|
|
Re-review at |
Part of #702. First step only: the RunID the journal will use. #702 stays open for the run directories, events, EMAX example and parity.
What
internal/idis copied from_archive/internal/idand trimmed, as agreed on #702._archiveitself is untouched (it stays the reference):internal/id/internal/ulid: the ULID encoding, unchanged.RunID: text formrun_<26-char ULID>;ParseRunID,MustParseRunID,String,IsZero,Equal,Time(the creation instant), text and JSON marshaling. The zero value is unset and refuses to marshal; the all-zero ULID is refused on parse.Generator: monotonic within a millisecond, safe for concurrent use, reportsErrEntropyExhausted. If the clock steps backwards it carries on from the last millisecond it used instead of failing (an NTP correction must not stop a run getting an ID; uniqueness and order matter more than an exact timestamp during an adjustment). The archivedErrClockMovedBackwardis gone.Random(crypto/rand) and the seededDeterministicare the entropy sources.internal/clock:Clock() time.Timeis the one place Trader reads the time.NewGeneratortakes afunc() time.Time(clock.Clockin production, a fixed function in tests), so a Trader clock of its own can replaceClock's body later without touching callers. The archivedclock.Clockinterface (real and simulated, about 1,700 lines with tests) is not ported.Not ported
The other six ID kinds,
Metadata/Sourceand theParse*/Generate*wrappers for them, and the archived third-party-library architecture test (replaced by a small import test). Order ids stay the broker's (sim-1); more kinds can come when something needs a generated identity for them._archive/internal/idstill holds all of it as the donor for those kinds.Tests
Parse round trip and every rejection (wrong prefix, bad body, all-zero, trailing text); zero value;
Equal;Timeto the millisecond; text and JSON round trips as a string; generator monotonic order (same and advancing milliseconds), entropy error, exhaustion, a clock stepping back (still increasing, stamped with the last millisecond, follows the clock again once it passes), concurrent uniqueness; the seeded sequence reproduces;Clockis UTC without a monotonic reading; the package imports only the standard library and its ULID.make checkpasses. Nothing calls it yet.🤖 Generated with Claude Code