Skip to content

fold: deterministic CreatedAt from persisted applied_at#54

Merged
MSD21091969 merged 2 commits into
masterfrom
feat/t250-createdat-determinism
Jul 9, 2026
Merged

fold: deterministic CreatedAt from persisted applied_at#54
MSD21091969 merged 2 commits into
masterfrom
feat/t250-createdat-determinism

Conversation

@MSD21091969

@MSD21091969 MSD21091969 commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

HG URN: urn:moos:session:sam.kernel-proper

Summary

  • thread explicit timestamps through fold evaluation via EvaluateAt and EvaluateProgramAt
  • use persisted rewrite time (AppliedAt with Timestamp fallback) during replay instead of wall clock
  • align runtime apply/program/reactive/local_t paths so fold CreatedAt matches persisted AppliedAt
  • strengthen replay determinism tests to assert full-node equality and timestamp fallback behavior

Why

Replay determinism previously depended on runtime wall clock for ADD/LINK CreatedAt, which made reconstructed state time-dependent. This changes fold state derivation so structural CreatedAt is deterministic from persisted log payload.

Finding provenance

Validation

  • go test ./... (module root)

Notes

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR makes fold replay and runtime application deterministic by threading explicit timestamps through fold evaluation, so node/relation CreatedAt is derived from persisted log timestamps (AppliedAt, with Timestamp fallback) rather than the wall clock.

Changes:

  • Add fold.EvaluateAt / fold.EvaluateProgramAt and update runtime paths to pass the exact persisted AppliedAt so CreatedAt matches the log.
  • Update replay to use persisted timestamps (AppliedAtTimestamp → zero time) to keep replay deterministic even for legacy/malformed log lines.
  • Strengthen determinism tests to assert full node equality and validate the timestamp fallback behavior.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
internal/kernel/runtime.go Threads a single captured AppliedAt into fold evaluation for Apply/ApplyProgram/reactive/local_t so persisted timestamps match fold CreatedAt.
internal/fold/replay.go Uses persisted AppliedAt/Timestamp (else stable zero time) when folding during replay to avoid wall-clock dependence.
internal/fold/program.go Introduces EvaluateProgramAt to accept caller-supplied per-envelope timestamps for deterministic CreatedAt in batch evaluation.
internal/fold/evaluate.go Introduces EvaluateAt and updates ADD/LINK folding to use provided timestamps for CreatedAt.
internal/fold/fold_test.go Updates CI-4 determinism test to compare full nodes and asserts CreatedAt preservation + timestamp fallback.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/fold/program.go
Comment on lines 26 to +30
for i, env := range envelopes {
next, result, err := Evaluate(working, env)
ts := time.Now().UTC()
if i < len(appliedAt) {
ts = appliedAt[i]
}
Fold Copilot PR #54 catch: partially-filled appliedAt now errors instead of falling back to wall-clock timestamps, preserving replay determinism guarantees.

authored-by: agent:vscode.hp-laptop.wolfram / session:sam.kernel-proper / t250-createdat-determinism
@MSD21091969

Copy link
Copy Markdown
Collaborator Author

Folded Copilot catch from #147 conventions brief:

  • EvaluateProgramAt now validates appliedAt length strictly (0 or len(envelopes) only)
  • partial slices now return an error instead of silently reintroducing wall-clock fallback
  • added regression test: TestProgramAt_PartialAppliedAtRejected

Validation: go test ./... passed.
Commit: d7e18a4

@MSD21091969 MSD21091969 merged commit a1511c3 into master Jul 9, 2026
1 check passed
@MSD21091969 MSD21091969 deleted the feat/t250-createdat-determinism branch July 9, 2026 10:51
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.

2 participants