Skip to content

Fix stale first-batch status text after query completion #23

Closed

Description

@Honguan

Bug report

The query status text can get stuck on the temporary first-batch message even after the background query has already completed.

A visible example is:

已顯示第一批 501 筆 · 背景查詢中…

The results grid is already populated, but the status area still says that the background query is running and does not update to the final query summary.

Reproduction

  1. Run a query that returns enough events to trigger the first-batch preview.
  2. Wait until the full result list is already visible.
  3. Observe the status text near the language selector / result summary area.
  4. The text may remain on the first-batch / background-querying state instead of changing to the final completed summary.

Likely cause

ShowFirstBatch posts its UI update using Dispatcher.BeginInvoke and sets the operation status to the localized FirstBatch message.

The final query path later sets StatusText.Text to the completed QuerySummary, but a queued first-batch dispatcher callback can still run afterward and overwrite the final text with the stale preview status.

In other words, the first-batch update is asynchronous and is only guarded by cancellation. It is not guarded against the query already having completed or a newer final status already having been committed.

Required behavior

The status area must follow the actual query lifecycle:

  1. Query starts → show Querying...
  2. First batch arrives → optionally show First batch ... · background query running...
  3. Full query completes → replace it with the final query summary
  4. After completion, no queued preview callback may overwrite the final status

The final completed status should remain stable until another operation intentionally changes it.

Implementation guidance

Use a query generation / operation version or explicit completion flag for UI callbacks.

For example, the first-batch callback should only update the UI when all of these are still true:

  • the callback belongs to the current query operation
  • the operation has not been cancelled
  • the query has not already reached its final completed state

Possible approaches include:

  • assign each query an incrementing generation ID and reject stale dispatcher callbacks
  • track an isQueryCompleted flag captured by the first-batch callback
  • route all query-status transitions through one state-aware status method instead of directly mixing SetOperationStatus(...) and StatusText.Text = ...

Do not fix this with a timer or arbitrary delay.

Related UI behavior

The same stale-callback protection should apply to any first-batch preview UI that can race with final results, including the results grid if necessary. A delayed preview callback must not replace a newer final result set.

Language switching should still re-render the currently valid status text in the selected language without reviving an obsolete background querying state.

Acceptance criteria

  • After a query finishes, the status text always shows the final query summary rather than the first-batch/background-querying message.
  • A queued first-batch dispatcher callback cannot overwrite the final completed status.
  • Starting a newer query prevents callbacks from an older query from changing the current status.
  • Cancellation still shows the correct cancelled state.
  • Query errors still show the correct error state.
  • Language switching preserves the correct current lifecycle state and only changes its localization.
  • Add a regression test or deterministic UI/state test for the first-batch-versus-final-status race.

Activity

  1. added a commit that references this issue on Aug 25, 2026
  2. Honguan commented on Aug 25, 2026

    @Honguan
    OwnerAuthor

    Completed. Branch: issue/23-query-status-race; PR: #25; Merge commit: a35cf1006203075e8c54d9e826c662b44ad7ec8a; Main verification: passed; Tests: Release build, deterministic query lifecycle test, full integration/UI suite, and both PR CI runs passed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions