Skip to content

fix(tui): guard gantt cache updates with generation IDs - #1302

Open
lyn1dev wants to merge 1 commit into
Kohei-Wada:mainfrom
lyn1dev:fix/gantt-cache-race-1145
Open

lyn1dev wants to merge 1 commit into
Kohei-Wada:mainfrom
lyn1dev:fix/gantt-cache-race-1145

Conversation

@lyn1dev

@lyn1dev lyn1dev commented Nov 26, 2026

Copy link
Copy Markdown

Description

TaskdogTUI._flush_reload and TaskdogTUI.on_gantt_resize_requested run in separate exclusive Textual worker groups ("reload" and "gantt"). When both run concurrently, whichever finishes last overwrote TUIState.gantt_cache, allowing a slower stale gantt fetch or an older full reload to clobber newer gantt window or task data.

This adds monotonic reload_generation and gantt_generation counters to TUIState and stamps each worker snapshot (FetchParams and GanttFetchParams) on the UI thread when the fetch starts:

  • A full reload advances both reload_generation and gantt_generation.
  • A gantt pan/resize advances gantt_generation only.
  • On completion on the UI thread:
    • apply_gantt and _finish_gantt_reload drop results and error/loading updates if gantt_generation has been superseded.
    • apply_task_data drops the entire update if reload_generation has been superseded, and skips overwriting gantt_cache / GanttWidget when reload_generation is current but gantt_generation has been superseded by a newer gantt pan/resize.

Related Issue

Closes #1145

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Changes Made

  • packages/taskdog-ui/src/taskdog/tui/state/tui_state.py: Added gantt_generation, reload_generation, next_gantt_generation(), and next_reload_generation().
  • packages/taskdog-ui/src/taskdog/tui/services/task_ui_manager.py: Added generation tokens to FetchParams and GanttFetchParams, generation validation helpers (is_current_reload_generation, is_current_gantt_generation), and selective gantt cache/widget gating in apply_task_data, _update_cache, _refresh_ui, and apply_gantt.
  • packages/taskdog-ui/src/taskdog/tui/app.py: Propagated generation tokens through _reload_in_thread / _finish_reload and _gantt_reload_in_thread / _finish_gantt_reload and gated loading/error cleanup.
  • packages/taskdog-ui/tests/tui/test_app_worker_race.py: Added end-to-end Textual async regression tests covering both stale-gantt-after-reload and stale-reload-after-gantt-pan worker races.
  • packages/taskdog-ui/tests/tui/services/test_task_ui_manager.py and packages/taskdog-ui/tests/tui/state/test_tui_state.py: Added unit tests for generation counters and stale-token filtering.

Testing

Test Environment

  • OS: Windows
  • Python version: 3.13.18
  • UV version: 0.13.7

Tests Performed

  • Unit tests pass (pytest packages/taskdog-ui/tests/ --cov=taskdog --cov-fail-under=70 -q: 1197 passed, 83.77% coverage)
  • Both new tests in packages/taskdog-ui/tests/tui/test_app_worker_race.py fail before the fix (reproducing the stale gantt_cache overwrite) and pass after the fix (2 passed)

Code Quality Checklist

  • Linter passes (ruff check --config pyproject.toml packages/taskdog-ui/src/ packages/taskdog-ui/tests/ — all checks passed)
  • Type checker passes (mypy --config-file pyproject.toml packages/taskdog-ui/src/ — 0 issues in 193 source files)
  • Code is formatted (ruff format --check --config pyproject.toml packages/taskdog-ui/src/ packages/taskdog-ui/tests/ — 309 files formatted)
  • Dead code and spell checks pass (vulture and codespell — 0 issues)

Package Affected

  • taskdog-ui

This branch has not been deployed

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

fix(tui): gantt cache race between independent exclusive worker groups

1 participant