Skip to content

Allow step end_time overwrite #170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 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.

1 participant