Skip to content
This repository was archived by the owner on Aug 5, 2025. It is now read-only.

Allow step end_time overwrite #170

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gabrielBarbutti
Copy link

Minor fix: Preserve manually set end_time on Step.end()

Context

When using the with syntax to log a step, we sometimes manually set start_time and end_time (e.g. to match historical timestamps or upsert an existing thread).
However, the current implementation of Step.end() always overwrites end_time with utc_now(), which can lead to inaccurate timing data.

Change

Updated the end() method to preserve the manually-set end_time if it already exists:

self.end_time = utc_now() if self.end_time is None else self.end_time

Example of end_time overwriting

async with self.client.step(
    id=self.generate_uuid_v5_from_id(run.id),
    thread_id=self.generate_uuid_v5_from_id(thread_id),
    parent_id=self.generate_uuid_v5_from_id(parent_id),
    type="run",
    name=assistant_name,
) as step:
    step.created_at = created_at
    step.start_time = created_at
    step.end_time = completed_at
    step.input = input
    step.output = output
    step.generation = generation

Now correctly logs completed_at instead of the current time.

Why it matters

This ensures accurate time tracking when steps are being reconstructed or backfilled, and avoids unintentionally overwriting data.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant