TrajectoryRepository
TrajectoryRepository() -> NoneOwns canonical trajectories and materializes retained references on demand.
Methods
add_recordings
add_recordings(recordings: list[TrajectoryRecording], *, priority: float = 0.0, archive_eligible: bool = True) -> list[TrajectoryReferenceRecording]diagnostics
diagnostics(directly_visible_trajectory_ids: set[int] | None = None) -> TrajectoryRepositoryDiagnosticsReturn live repository diagnostics for debugging retention growth.
frame_stack_coverage
frame_stack_coverage() -> tuple[int, int]Return (restorable segments with a frame stack, total restorable segments) across all paths.
Only start-eligible segments count: they are the ones midpoint sampling may draw, and gating makes an unseeded segment unsampleable, so this ratio is the fraction of the store restarts can reach.
Returns:
tuple[int, int]– The seeded and total start-eligible restorable segment counts.
load_state_dict
load_state_dict(state: dict[str, Any]) -> NoneReconstruct full routes from the deduplicated snapshot pool, restoring blob sharing.
materialize
materialize(recording: TrajectoryReferenceRecording) -> TrajectoryRecordingmaterialize_prefix_segments
materialize_prefix_segments(reference: TrajectorySliceReference) -> list[TrajectoryRecording]materialize_slice
materialize_slice(trajectory_id: int, *, start_segment: int, min_actions: int = 16, max_actions: int = 48) -> TrajectoryRecordingMaterialize one contiguous multi-segment slice of a stored route for behaviour cloning.
Starting from start_segment the window is extended forward, accumulating whole segments, until it holds at least min_actions actions without exceeding max_actions. min_actions is a hard floor: when the forward tail from start_segment is too short (the chosen start sat near the end of the route) the start is backed up one segment at a time until the window reaches the floor while staying within max_actions. Only when the entire route holds fewer than min_actions actions is the whole route returned. Every emitted slice therefore carries a genuine stored initial_state, so a deterministic replay reproduces its frames.
Parameters:
trajectory_id(int) – The stored route to slice.start_segment(int) – The preferred first segment of the slice.min_actions(int) – The minimum number of actions the slice must contain.max_actions(int) – The maximum number of actions the slice may contain.
Returns:
TrajectoryRecording– The materialized slice recording.
path
path(trajectory_id: int) -> TrajectoryRepositoryPath | NoneReturn the stored route for trajectory_id, or None when absent.
path_priorities
path_priorities() -> dict[int, float]Return the route-level priority of every ARCHIVE-ELIGIBLE stored route keyed by trajectory id.
Consumed by the best-route archive's rebuild on restore, so ineligible paths (bare mid-route tails) are excluded here exactly as they are excluded from live admission.
paths_needing_frame_stacks
paths_needing_frame_stacks(limit: int) -> list[tuple[int, TrajectoryRepositoryPath]]Return up to limit stored paths with at least one restorable segment missing its frame stack.
Newest paths first. A fresh path reflects the current policy's reach, so seeding it first gets the deepest bands sampleable soonest; older unseeded paths are ground away by retention anyway.
Parameters:
limit(int) – The maximum number of paths to return.
Returns:
list[tuple[int, TrajectoryRepositoryPath]]–(trajectory_id, path)pairs needing a frame-stack replay.
release
release(reference: TrajectorySliceReference) -> Noneretain
retain(reference: TrajectorySliceReference) -> Nonesegment
segment(reference: TrajectorySliceReference) -> TrajectoryRepositorySegment | NoneReturn the segment a restart from reference would restore to, or None when gone.
A restart resumes at the END of the referenced slice, so this is the stop_index - 1 segment.
Parameters:
reference(TrajectorySliceReference) – The slice reference to resolve.
Returns:
TrajectoryRepositorySegment | None– The final segment of the slice, orNonewhen the path or index is absent.
set_frame_stacks
set_frame_stacks(trajectory_id: int, frame_stacks: dict[int, bytes]) -> boolAttach rebuilt observation frame stacks to a stored route's segments.
Parameters:
trajectory_id(int) – The route to attach to.frame_stacks(dict[int, bytes]) – Segment index -> the stack at that segment's end state.
Returns:
bool– Whether the route was present and updated.
state_dict
state_dict() -> dict[str, Any]Serialise the repository as full routes with deduplicated state snapshots.
Every unique state snapshot blob (the heavy ~tens-of-KB emulator states) is written once into a pool and referenced by index, so a stitched route's shared prefix segments do not duplicate the prefix's snapshots on disk -- matching how they are shared by identity in memory. Each path is stored whole (its action buffer, priority, and segments referencing pool blobs), so loading reconstructs the full multi-segment routes, not flattened single segments.
whole_path_reference
whole_path_reference(trajectory_id: int) -> TrajectorySliceReferenceBuild a reference spanning every segment of one stored route.
Parameters:
trajectory_id(int) – The route to reference.
Returns:
TrajectorySliceReference– A reference covering the whole route.