VOOZH about

URL: https://deepwiki.com/inclusionAI/AReaL/13.2-session-tracing

⇱ Session Tracing | inclusionAI/AReaL | DeepWiki


Loading...
Last indexed: 7 May 2026 (2e12c1)
Menu

Session Tracing

Session tracing provides fine-grained lifecycle tracking for individual rollout sessions during RL training. Each session represents a single sample generation from prompt submission through reward computation and finalization. Session tracing records timestamped events, phase executions, and derived performance metrics for offline analysis and debugging.

For general method-level performance profiling, see Performance Tracing. For visualization tools, see Trace Visualization.


Overview

Session tracing tracks the complete lifecycle of rollout sessions through the async RL training loop. Unlike performance tracing which focuses on method execution times, session tracing follows individual data samples as they progress through generation, reward computation, and training phases.

Key capabilities:

The tracer is thread-safe and designed for concurrent async workflows where multiple sessions execute simultaneously using ContextVar for task and session identity propagation areal/utils/perf_tracer.py30-40

Sources: areal/utils/perf_tracer.py1-1150


Session Lifecycle Model

Natural Language to Code Entity Mapping

The following diagram bridges the conceptual lifecycle of an RL rollout to the specific SessionTraceEvent types and SessionRecord states used in the codebase.

Natural Language ConceptCode Entity / IdentifierFile Reference
Session StartSessionRecord.submit_tsareal/utils/perf_tracer.py425-476
Generation PhaseSessionTraceEvent.GENERATE_START / GENERATE_ENDareal/utils/perf_tracer.py244-293
Reward CalculationSessionTraceEvent.REWARD_START / REWARD_ENDareal/utils/perf_tracer.py244-293
Tool ExecutionSessionTraceEvent.TOOLCALL_START / TOOLCALL_ENDareal/utils/perf_tracer.py244-293
Session FinalizedSessionTraceEvent.FINALIZEDareal/utils/perf_tracer.py244-293

Sources: areal/utils/perf_tracer.py244-293 areal/utils/perf_tracer.py425-476

State Transitions


Lifecycle phases:

  1. Registration: Assign session_id, record submit_ts areal/utils/perf_tracer.py971-998
  2. Generate phase: Inference engine generates output tokens. Tracked via atrace_session_phase("generate") areal/workflow/rlvr.py129-130
  3. Reward phase: Compute reward from completion. Tracked via @trace_session("reward") areal/workflow/rlvr.py82-83
  4. Finalization: Training loop accepts/rejects session, record finalized_ts areal/utils/perf_tracer.py1044-1062

Sources: areal/utils/perf_tracer.py244-293 areal/utils/perf_tracer.py425-476 areal/workflow/rlvr.py82-136


Core Components

SessionTracer

The SessionTracer class manages the complete lifecycle of all sessions for a single rank/role.


Key methods:

MethodPurposeFile:Line
register_task(task_id)Register a dataset-level task that groups multiple sessionsareal/utils/perf_tracer.py960-969
register_session(task_id)Create new session, assign session_id, record submit_tsareal/utils/perf_tracer.py971-998
record_event(session_id, event, **payload)Record lifecycle event (e.g. GENERATE_START)areal/utils/perf_tracer.py1000-1033
increment_counter(session_id, name, value)Increment custom counter for sessionareal/utils/perf_tracer.py1035-1042
flush()Write ready sessions to disk in JSONL formatareal/utils/perf_tracer.py1064-1092

Sources: areal/utils/perf_tracer.py920-1062

SessionRecord and Phase Tracking

Represents the complete state and history of a single session. It calculates derived metrics during serialization.

Derived Metrics (Computed in to_dict):

MetricComputationDescription
total_sfinalized_ts - submit_tsTotal session duration areal/utils/perf_tracer.py644
generate_sSum of all generate phase spansTotal time in generation areal/utils/perf_tracer.py650-653
reward_sSum of all reward phase spansTotal time computing rewards areal/utils/perf_tracer.py655-658
toolcall_sSum of all toolcall phase spansTotal time in tool calls areal/utils/perf_tracer.py660-663

Sources: areal/utils/perf_tracer.py619-668


Usage Patterns

Context Manager Decorators

The @session_context() decorator automatically registers sessions and manages their lifecycle within a workflow. It is extensively used in RLVRWorkflow areal/workflow/rlvr.py110-136 and VisionRLVRWorkflow areal/workflow/vision_rlvr.py75-101

What @session_context() does:

  1. Retrieves current task_id from workflow_context areal/utils/perf_tracer.py773-774
  2. Registers new session with SessionTracer areal/utils/perf_tracer.py778
  3. Sets session_id in a ContextVar for nested calls areal/utils/perf_tracer.py780
  4. Automatically finalizes session on function exit areal/utils/perf_tracer.py793-800

Sources: areal/utils/perf_tracer.py745-814 areal/workflow/rlvr.py110-136 areal/workflow/vision_rlvr.py75-101

Phase Tracing

Use atrace_session_phase() or @trace_session() for automatic phase start/end pairing.

Sources: areal/utils/perf_tracer.py816-917 areal/workflow/rlvr.py82-108 areal/workflow/vision_rlvr.py45-101


Visualization and Tools

Trace Conversion and Plotting

The system includes tools to convert raw JSONL traces into interactive visualizations.


Key Tools:

  1. perf_trace_converter.py: Merges multi-rank performance traces into a single Chrome Trace format file areal/tools/perf_trace_converter.py121-214 It handles remapping of PIDs and TIDs for uniqueness across ranks areal/tools/perf_trace_converter.py121-160
  2. plot_session_trace.py: Generates interactive Plotly reports from session data, including timeline views and histograms of durations areal/tools/plot_session_trace.py413-576 It parses the nested phases structure from SessionRecord areal/tools/plot_session_trace.py196-230

Sources: areal/tools/perf_trace_converter.py1-214 areal/tools/plot_session_trace.py1-1264

Output Format

Default path: {fileroot}/logs/{user}/{experiment_name}/{trial_name}/session_tracer/{role}/sessions-r{rank}.jsonl areal/utils/perf_tracer.py199-242

Example record structure (as produced by SessionRecord.to_dict):

FieldTypeDescription
task_idintGlobal task identifier
session_idintUnique session identifier within task
statusstrFinal state (accepted, rejected, etc.)
submit_tsfloatUnix timestamp of registration
total_sfloatComputed duration finalized_ts - submit_ts
phasesdictNested start/end timestamps for phases

Sources: areal/utils/perf_tracer.py619-668


Performance and Thread Safety

SessionTracer is designed for high-concurrency RL environments:

Sources: areal/utils/perf_tracer.py1-1150