Skip to content

[fix] Track watch iterations independently to ensure proper time tracking (#1565)#1580

Open
scottnemes wants to merge 1 commit intodbcli:mainfrom
scottnemes:bug/1565/multi-statement-watch-time-incorrect
Open

[fix] Track watch iterations independently to ensure proper time tracking (#1565)#1580
scottnemes wants to merge 1 commit intodbcli:mainfrom
scottnemes:bug/1565/multi-statement-watch-time-incorrect

Conversation

@scottnemes
Copy link
Contributor

Description

This fixes a bug where if the watch query is ran as part of a multi-query statement it will return the incorrect run time for the first iteration. I.e.

Before:
image

After:
image

Resolves #1565

Checklist

  • I added this contribution to the changelog.md file.
  • I added my name to the AUTHORS file (or it's already there).
  • To lint and format the code, I ran
    uv run ruff check && uv run ruff format && uv run mypy --install-types .

@scottnemes scottnemes self-assigned this Feb 18, 2026
@github-actions
Copy link

Findings (Correctness)

  1. Watch sleep adjustment is still applied to every watch result after the first, even within the same watch iteration.
    In mycli/main.py:915, watch_count flips to >0 after the first watch result and never changes. That means for a watch query that produces multiple SQL results per iteration (e.g., watch 5 select 1; select 2;), the second result in the same iteration will still subtract the sleep time, under-reporting execution time.
    Suggested fix: only apply the sleep offset on the first result of each watch iteration. Options:
    • Tag the first SQL in each watch iteration in watch_query (e.g., command["watch_iteration"]=iteration_id or command["watch_is_first"]=True) and key off that in output_res.
    • Or track per-iteration boundaries in output_res by incrementing a watch_iteration_id from the generator rather than a simple boolean.

Tests / Edge Cases

  1. Add a regression test for multi-statement watch: watch 5 select 1; select 2;
    Assertions: only the first result of each watch iteration should subtract the sleep duration.
  2. Add a regression test for mixed multi-query input: select 1; watch 5 select 2;
    Assertion: the first watch iteration should not offset time because of the preceding non-watch statement.

No security concerns found in this change.

Copy link
Contributor

@rolandwalker rolandwalker left a comment

Choose a reason for hiding this comment

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

Sweet!

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.

Watch command returns incorrect time on first iteration when run as a multi-part statement

2 participants