Skip to content

Persist tracing sessions - #318

Merged
hhubert6 merged 22 commits into
mainfrom
hubertkasprzycki/voy-328-persist-tracing-sessions-and-traces
Oct 30, 2026
Merged

hhubert6 merged 22 commits into
mainfrom
hubertkasprzycki/voy-328-persist-tracing-sessions-and-traces

Conversation

@hhubert6

Copy link
Copy Markdown
Member

No description provided.

@hhubert6
hhubert6 added this pull request to stack #306 October 19, 2026 10:12
@hhubert6
hhubert6 force-pushed the hubertkasprzycki/voy-328-persist-tracing-sessions-and-traces branch from 1c0ab45 to b57c976 Compare October 19, 2026 10:27
@hhubert6

Copy link
Copy Markdown
Member Author

@claude review

@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @hhubert6's task in 2m 0s —— View job


🦀 Review

Severity: 🔴 blocking · 🟡 should-fix · 🟢 nit

  • 🟢 85% lib/voyager/services/tracer.ex:30 — the # ponytail: comment carries the tool's prefix and a note about future work ("per-key LRU if pairs go missing"). Cut it down to the reason only.
  • 🟢 85% lib/voyager/services/tracer.ex:300 — the # ponytail: comment has the same prefix and a future-tense "prune per batch if that bites". Either drop it or keep one line stating the disk peak.

<verdict: 0 blocking, 0 should-fix, 2 nit>

Comment thread lib/voyager/services/tracer.ex Resolved
Comment thread lib/voyager/services/tracer.ex Resolved
@hhubert6 hhubert6 mentioned this pull request Oct 21, 2026
@hhubert6
hhubert6 force-pushed the hubertkasprzycki/voy-328-persist-tracing-sessions-and-traces branch from c3b863e to dfc4ec2 Compare October 23, 2026 10:00
@hhubert6

Copy link
Copy Markdown
Member Author

@claude review

@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @hhubert6's task in 3m 41s —— View job


🦀 Review

Severity: 🔴 blocking · 🟡 should-fix · 🟢 nit

  • 🟡 85% lib/voyager/services/tracer.ex:429: no test covers the new :storage_limit stop (stop_over_limit/1). Add a tracer test that sets a tiny :trace_storage_limit_mb and asserts the run stops with :storage_limit.

  • 🟢 65% lib/voyager/actions/trace_sessions.ex:77: interrupt_running/0 sets no stopped_at and writes no :stopped entry. A loaded interrupted session has a log ending at :started and stopped_at: nil.

  • 🦐 70% lib/voyager/schemas/trace_session.ex:40-41: delete: unused has_many :session_events / :events. The FK on_delete: :delete_all already cascades.

<verdict: 0 blocking, 1 should-fix, 1 nit, 1 ponytail · net: -2 lines possible>

Comment thread lib/voyager/services/tracer.ex Resolved
Comment thread lib/voyager/actions/trace_sessions.ex Resolved
Comment thread lib/voyager/schemas/trace_session.ex Resolved
@hhubert6

Copy link
Copy Markdown
Member Author

@claude review

@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @hhubert6's task in 1m 36s —— View job


🦀 Review

Severity: 🔴 blocking · 🟡 should-fix · 🟢 nit

  • 🟡 80% lib/voyager/services/tracer.ex:170: entries/2 still specs pos_integer(), but unsaved sessions now get negative ids. Change it to integer().

  • 🦐 65% lib/voyager/schemas/trace_session.ex:46-57: yagni: the changeset casts ten fields, but create/1 only passes origin and status. Use cast(attrs, [:origin, :status]).

<verdict: 0 blocking, 1 should-fix, 0 nit, 1 ponytail · net: -9 lines possible>

Comment thread lib/voyager/services/tracer.ex Resolved
Comment thread lib/voyager/schemas/trace_session.ex Resolved
@hhubert6

Copy link
Copy Markdown
Member Author

@claude review

@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @hhubert6's task in 1m 13s —— View job


🦀 Review

No findings above the confidence threshold. The earlier points (the entries/2 spec, the changeset cast, stopped_at on interrupt, the storage-limit test, the unused associations) are all fixed.

<verdict: 0 blocking, 0 should-fix, 0 nit>

@hhubert6
hhubert6 force-pushed the hubertkasprzycki/voy-328-persist-tracing-sessions-and-traces branch from 0a08532 to 4bfbbe9 Compare October 27, 2026 10:13
@hhubert6
hhubert6 marked this pull request as ready for review October 27, 2026 10:20
@hhubert6
hhubert6 requested review from GuzekAlan and srzeszut and removed request for GuzekAlan and srzeszut October 27, 2026 10:20
@hhubert6

Copy link
Copy Markdown
Member Author

@claude review

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @hhubert6's task in 1m 20s —— View job


🦀 Review

No findings above the confidence threshold in the new Writer, supervisor and stop-path commits.

<verdict: 0 blocking, 0 should-fix, 0 nit>

@hhubert6
hhubert6 requested review from GuzekAlan and srzeszut and a balanced review from Copilot October 27, 2026 12:54
Supervise Writer and Tracer together, move the boot-time DB write out of
init, and end a run with :write_failed when its entries cannot be saved.
The Writer absorbs casts into its state at once, so its mailbox stayed
short while a flush held an unbounded backlog.
Row encoding was the Writer's CPU ceiling. Rows are now prepared on
the task supervisor while the single inserter runs, and a full queue is
flushed at once, so the pending-entries backpressure only trips when the
database really lags.
@hhubert6
hhubert6 force-pushed the hubertkasprzycki/voy-328-persist-tracing-sessions-and-traces branch from c51aeb1 to 4a65bef Compare October 27, 2026 12:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Buffered writes can undermine restart recovery and lose saved entries during normal shutdown.

5 open issues
What changed in this PR

Adds database-backed tracing sessions to Voyager, allowing saved sessions to be loaded, resumed, queried, and deleted.

Changes:

  • Adds trace storage schemas, queries, serialization, and retention controls.
  • Introduces a buffered writer and integrates persistence into the tracer lifecycle.
  • Adds call-duration tracking and tests for persistence, limits, and writer failures.
File Description
test/​voyager/​trace_sessions_test.exs Tests storage, pagination, pruning, and serialization.
test/​voyager/​services/​tracer_test.exs Tests persistence, writer behavior, and durations.
test/​support/​recursive.ex Adds a recursive tracing fixture.
priv/​repo/​migrations/​20261023090945_create_trace_sessions_and_events.exs Creates session and event tables.
lib/​voyager/​stored_term.ex Encodes and compresses stored Erlang terms.
lib/​voyager/​services/​tracer/​writer.ex Buffers and persists trace entries.
lib/​voyager/​services/​tracer/​supervisor.ex Supervises the writer and tracer together.
lib/​voyager/​services/​tracer/​session.ex Adds storage accounting to session state.
lib/​voyager/​services/​tracer/​run.ex Tracks pending calls for duration calculation.
lib/​voyager/​services/​tracer.ex Integrates persistence, recovery, and duration tracking.
lib/​voyager/​schemas/​trace_session.ex Defines saved session metadata.
lib/​voyager/​schemas/​trace_session_event.ex Defines lifecycle and dropped-event records.
lib/​voyager/​schemas/​trace_event.ex Defines persisted trace records.
lib/​voyager/​queries/​trace_sessions.ex Retrieves saved sessions.
lib/​voyager/​queries/​trace_entries.ex Reads both event tables as one ordered log.
lib/​voyager/​application.ex Starts the tracing supervisor.
lib/​voyager/​actions/​trace_sessions.ex Creates, updates, prunes, and recovers sessions.
lib/​voyager/​actions/​trace_entries.ex Prepares event rows and estimates storage usage.

Review effort: Balanced

Comment thread lib/voyager/services/tracer.ex Resolved
Comment thread lib/voyager/services/tracer/writer.ex Resolved
Comment thread lib/voyager/services/tracer.ex Resolved
Comment thread lib/voyager/services/tracer.ex Resolved
Comment thread test/voyager/services/tracer_test.exs Resolved
Flush the surviving Writer before interrupting sessions on a Tracer
restart, drain the Writer on shutdown, drop open-call stacks when events
were dropped, bound retained timestamps instead of keys, and make the
recursive duration test tolerant of equal microsecond timestamps.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved persistence failure handling and Writer overload behavior can leave sessions unusable or allow unbounded queue growth.

3 open issues
2 previously missed issues

In code that hasn't changed since last review

Medium severity Include serialized configuration size in storage estimates

lib/​voyager/​actions/​trace_entries.ex:121

🟡 should-fix · 98%: Configured entries store their config as a map, so this filter excludes the entire serialized config from the storage estimate. Short saved sessions configured with many PIDs can consequently store kilobytes per configuration while counting only the fixed overhead and node string, substantially exceeding the byte-based stop/pruning limit. Include the encoded config's size in the total.

Medium severity Apply Writer backpressure only to saved sessions

lib/​voyager/​services/​tracer.ex:612

🟡 should-fix · 97%: The global Writer backlog also makes unsaved runs shed events. A saved run can stop with more than 10,000 rows still queued, and create/2 does not flush them, so an immediately started save: false session drops traces despite never using the Writer and having an empty mailbox. Pass the session's save flag into this check and apply Writer backpressure only to saved sessions.

5 resolved since last review

Review effort: Balanced

Comment thread lib/voyager/services/tracer.ex Resolved
Comment thread lib/voyager/services/tracer.ex Resolved
Comment thread lib/voyager/services/tracer.ex Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Non-transactional table reads can permanently skip trace entries, while write failures after a run stops can silently discard batches and leave stale saved data despite flush reporting success.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

High severity Read trace tables in one transaction for consistent pagination

lib/​voyager/​queries/​trace_entries.ex:21

🔴 blocking · 98%: The Writer can commit between these two table reads. An ascending page can then contain trace seq 2 but omit the configured/started entries at seq 0 and 1 committed in the same batch; advancing since skips those entries permanently. Read both tables in one transaction so the merged page uses a consistent snapshot.

3 resolved since last review

Review effort: Balanced

Comment thread lib/voyager/services/tracer.ex Resolved
Comment thread lib/voyager/services/tracer.ex Resolved

@kraleppa kraleppa left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Overall, it looks solid abd I could not find any blocking issues - only some nitpicks I mentioned above

Approve from my side 🦈

Comment thread lib/voyager/services/tracer/writer.ex Resolved
Comment thread lib/voyager/services/tracer/writer.ex Resolved
@hhubert6
hhubert6 requested a review from srzeszut October 30, 2026 11:57

@srzeszut srzeszut left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approval recommended 🐋

@hhubert6
hhubert6 merged commit 1042442 into main Oct 30, 2026
3 checks passed
@hhubert6
hhubert6 deleted the hubertkasprzycki/voy-328-persist-tracing-sessions-and-traces branch October 30, 2026 12:18
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.

4 participants