Skip to content

scripts: add filter preparation and time window computation#12841

Merged
lev-starkware merged 1 commit intomainfrom
pr3-finish-filter-preparation
Mar 4, 2026
Merged

scripts: add filter preparation and time window computation#12841
lev-starkware merged 1 commit intomainfrom
pr3-finish-filter-preparation

Conversation

@lev-starkware
Copy link
Contributor

@lev-starkware lev-starkware commented Feb 24, 2026

Note

Medium Risk
Adds new time-window selection logic that shells out to gcloud logging read and performs timezone/RFC3339 parsing; incorrect parsing or missing markers could lead to wrong log ranges or script failures.

Overview
Adds end-to-end time window computation to generate_logs_and_report.py and wires it into prepare_filter to return the final bounded log filter plus start_time/end_time.

Introduces --auto windowing by querying the first Running consensus for height N (and optionally N+1) timestamp via gcloud logging read, applying a default 15m end and ±30s buffer when needed. Also adds --near (±2h) and explicit --start/--end handling using local Asia/Jerusalem timestamps converted to UTC, along with argument conflict validation and a --print-filters debug path.

Written by Cursor Bugbot for commit 393bf5c. This will update automatically on new commits. Configure here.

@reviewable-StarkWare
Copy link

This change is Reviewable

@lev-starkware lev-starkware force-pushed the pr2-start-filter-preparation branch from 1b27127 to 6636684 Compare February 25, 2026 09:30
@lev-starkware lev-starkware force-pushed the pr3-finish-filter-preparation branch from a20f02e to f817d2e Compare February 25, 2026 09:30
Copy link
Contributor Author

@lev-starkware lev-starkware left a comment

Choose a reason for hiding this comment

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

@lev-starkware made 1 comment and resolved 1 discussion.
Reviewable status: 0 of 1 files reviewed, all discussions resolved (waiting on TzahiTaub).

@lev-starkware lev-starkware force-pushed the pr2-start-filter-preparation branch from 6636684 to cc111a9 Compare February 25, 2026 12:12
@lev-starkware lev-starkware force-pushed the pr3-finish-filter-preparation branch from f817d2e to 81ab843 Compare February 25, 2026 12:12
@lev-starkware lev-starkware force-pushed the pr3-finish-filter-preparation branch from 81ab843 to 57214d4 Compare February 25, 2026 12:54
@lev-starkware lev-starkware force-pushed the pr2-start-filter-preparation branch from cc111a9 to 3b420b8 Compare February 25, 2026 12:54
Copy link
Contributor Author

@lev-starkware lev-starkware left a comment

Choose a reason for hiding this comment

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

@lev-starkware made 1 comment and resolved 1 discussion.
Reviewable status: 0 of 1 files reviewed, all discussions resolved (waiting on TzahiTaub).

@lev-starkware lev-starkware force-pushed the pr3-finish-filter-preparation branch from 57214d4 to c7868aa Compare February 25, 2026 14:38
@lev-starkware lev-starkware force-pushed the pr2-start-filter-preparation branch from 3b420b8 to 0122e93 Compare February 25, 2026 14:39
@lev-starkware lev-starkware force-pushed the pr3-finish-filter-preparation branch from c7868aa to aa0baa6 Compare March 1, 2026 12:55
@lev-starkware lev-starkware force-pushed the pr2-start-filter-preparation branch from 0122e93 to bf74f70 Compare March 1, 2026 12:55
@lev-starkware lev-starkware force-pushed the pr3-finish-filter-preparation branch from aa0baa6 to 0a970e1 Compare March 1, 2026 15:38
@lev-starkware lev-starkware force-pushed the pr2-start-filter-preparation branch from bf74f70 to 96006b3 Compare March 1, 2026 15:38
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

@lev-starkware lev-starkware force-pushed the pr2-start-filter-preparation branch from 96006b3 to 0debfae Compare March 1, 2026 15:48
@lev-starkware lev-starkware force-pushed the pr3-finish-filter-preparation branch 2 times, most recently from e852665 to 81af1a1 Compare March 1, 2026 17:15
Copy link
Contributor Author

@lev-starkware lev-starkware left a comment

Choose a reason for hiding this comment

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

@lev-starkware resolved 1 discussion.
Reviewable status: 0 of 1 files reviewed, 1 unresolved discussion (waiting on TzahiTaub).

@lev-starkware lev-starkware force-pushed the pr2-start-filter-preparation branch from 0debfae to fe16b20 Compare March 2, 2026 21:09
@lev-starkware lev-starkware force-pushed the pr3-finish-filter-preparation branch from 81af1a1 to 393bf5c Compare March 2, 2026 21:09
@graphite-app graphite-app bot changed the base branch from pr2-start-filter-preparation to graphite-base/12841 March 3, 2026 11:57
Copy link
Contributor

@TzahiTaub TzahiTaub left a comment

Choose a reason for hiding this comment

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

@TzahiTaub made 7 comments.
Reviewable status: 0 of 1 files reviewed, 7 unresolved discussions (waiting on lev-starkware).


scripts/consensus_report/generate_logs_and_report.py line 182 at r7 (raw file):

def first_timestamp(project: str, flt: str) -> str:

To hint a remote query.

Suggestion:

def retrieve_first_timestamp(

scripts/consensus_report/generate_logs_and_report.py line 77 at r7 (raw file):

    dt_naive = datetime.fromisoformat(ts)
    israel_tz = ZoneInfo("Asia/Jerusalem")
    dt_ist = dt_naive.replace(tzinfo=israel_tz)

The script should be runnable in every time zone. Calling astimezone on a non aware datetime treats the original object as in local time.

Suggestion:

    dt_without_tz = datetime.fromisoformat(ts)
    dt_with_tz = dt_naive.astimezone()

scripts/consensus_report/generate_logs_and_report.py line 108 at r7 (raw file):

    Convert IST (Israel Standard Time) datetime to UTC.
    """
    return ist_time.astimezone(timezone.utc)

Function works for every timezone, and the script shouldn't limit usage to a specific timezone.

Suggestion:

def to_utc(local_time: datetime) -> datetime:
    """
    Converts local datetime to UTC.
    """
    return local_time.astimezone(timezone.utc)

scripts/consensus_report/generate_logs_and_report.py line 217 at r7 (raw file):

        raise RuntimeError(
            "--auto, --near, --start/--end, and --last-24-hours are mutually exclusive"
        )

Consider removing and using add_mutually_exclusive_group as suggested below

Code quote:

    # Check for conflicts between time options
    options = [args.auto, args.near, (args.start or args.end), args.last_24_hours]
    if sum(bool(o) for o in options) > 1:
        raise RuntimeError(
            "--auto, --near, --start/--end, and --last-24-hours are mutually exclusive"
        )

scripts/consensus_report/generate_logs_and_report.py line 223 at r7 (raw file):

            raise RuntimeError("--auto requires environment config")
        start_ts = first_timestamp(
            environment.project, consensus_height_filter(common_filter_prefix, args.height)

As this will always be called with no optional args, we can simplify the code a bit.

Suggestion:

def determine_search_window(
    args: argparse.Namespace,
    environment: EnvConfig,
    common_filter_prefix: str,
) -> Tuple[datetime, datetime]:
    """Determine the search time window based on provided arguments.

    Priority/validation:
      - --auto, --near, --start/--end, --last-24-hours are mutually exclusive
      - --start/--end must be provided together
      - --last-24-hours (or no args) uses (current_time - 24 hours) to current_time window
      - --auto requires environment and common_filter_prefix parameters
    """

    # Check for conflicts between time options
    options = [args.auto, args.near, (args.start or args.end), args.last_24_hours]
    if sum(bool(o) for o in options) > 1:
        raise RuntimeError(
            "--auto, --near, --start/--end, and --last-24-hours are mutually exclusive"
        )

    if args.auto:
        start_ts = first_timestamp(
            environment.project, consensus_height_filter(common_filter_prefix, args.height)

scripts/consensus_report/generate_logs_and_report.py line 227 at r7 (raw file):

        if not start_ts:
            raise RuntimeError(
                f"START_MARKER not found: Running consensus for height {args.height}"

Use the const you defined

Code quote:

Running consensus for height

scripts/consensus_report/generate_logs_and_report.py line 305 at r7 (raw file):

        action="store_true",
        help=f"Auto-detect time window by searching for '{RUNNING_CONSENSUS_FOR_HEIGHT} N' markers",
    )

Consider using the builtin argparse option for mutuallu exclusive flags

Suggestion:

    time_group = ap.add_mutually_exclusive_group()
    time_group.add_argument(
        "--auto",
        action="store_true",
        help=f"Auto-detect time window by searching for '{RUNNING_CONSENSUS_FOR_HEIGHT} N' markers",
    )

@lev-starkware lev-starkware force-pushed the pr3-finish-filter-preparation branch from 393bf5c to 0790c70 Compare March 3, 2026 14:56
@lev-starkware lev-starkware changed the base branch from graphite-base/12841 to pr2-start-filter-preparation March 3, 2026 14:57
@lev-starkware lev-starkware changed the base branch from pr2-start-filter-preparation to graphite-base/12841 March 3, 2026 20:38
@lev-starkware lev-starkware force-pushed the pr3-finish-filter-preparation branch from 0790c70 to bbed192 Compare March 3, 2026 20:38
Copy link
Contributor Author

@lev-starkware lev-starkware left a comment

Choose a reason for hiding this comment

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

@lev-starkware made 6 comments and resolved 3 discussions.
Reviewable status: 0 of 1 files reviewed, 4 unresolved discussions (waiting on TzahiTaub).


scripts/consensus_report/generate_logs_and_report.py line 77 at r7 (raw file):

Previously, TzahiTaub (Tzahi) wrote…

The script should be runnable in every time zone. Calling astimezone on a non aware datetime treats the original object as in local time.

Done.


scripts/consensus_report/generate_logs_and_report.py line 108 at r7 (raw file):

Previously, TzahiTaub (Tzahi) wrote…

Function works for every timezone, and the script shouldn't limit usage to a specific timezone.

Done.


scripts/consensus_report/generate_logs_and_report.py line 182 at r7 (raw file):

Previously, TzahiTaub (Tzahi) wrote…

To hint a remote query.

Done


scripts/consensus_report/generate_logs_and_report.py line 223 at r7 (raw file):

Previously, TzahiTaub (Tzahi) wrote…

As this will always be called with no optional args, we can simplify the code a bit.

Done.


scripts/consensus_report/generate_logs_and_report.py line 227 at r7 (raw file):

Previously, TzahiTaub (Tzahi) wrote…

Use the const you defined

Done.


scripts/consensus_report/generate_logs_and_report.py line 305 at r7 (raw file):

Previously, TzahiTaub (Tzahi) wrote…

Consider using the builtin argparse option for mutuallu exclusive flags

Done + changed --start/--end to --range START END

@lev-starkware lev-starkware changed the base branch from graphite-base/12841 to main March 3, 2026 20:38
Copy link
Contributor

@TzahiTaub TzahiTaub left a comment

Choose a reason for hiding this comment

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

@TzahiTaub reviewed 1 file and all commit messages, and resolved 4 discussions.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on lev-starkware).

@lev-starkware lev-starkware added this pull request to the merge queue Mar 4, 2026
Merged via the queue into main with commit 6b7f1b8 Mar 4, 2026
33 of 45 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Mar 6, 2026
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.

3 participants