Kaynağa Gözat

docs: plan session restore race fixes

Problem: Todo 49 review found stale session loads can overwrite the selected session UI, and restoration needs visible-text edge coverage.

Risk: The follow-up touches asynchronous UI state and provider transcript repair, so it requires focused race and protocol regression tests.
zhenyu.hu 2 hafta önce
ebeveyn
işleme
9894aab5a2

+ 36 - 0
docs/plans/todo-49.2-session-load-race-and-visible-repair.md

@@ -0,0 +1,36 @@
+# Todo 49.2 Session Load Race and Visible Repair Plan
+
+**Status:** in_progress
+
+## Goal
+
+Close reviewed session restoration races without changing the completed Todo 49/49.1 records.
+
+## Scope
+
+- Guard asynchronous session replay with a monotonically increasing load token and the selected session id so stale responses cannot overwrite current UI state.
+- Ignore stale success and failure status updates from superseded loads.
+- Treat whitespace-only assistant content with `tool_calls` as protocol-only in replay.
+- When repairing an incomplete persisted tool-call group, retain non-blank assistant content as a provider-valid assistant message without `tool_calls`; continue dropping orphan tool replies.
+
+## Files
+
+- Modify: `src/agent_lab/application/runtime.py`
+- Modify: `src/agent_lab/presentation/static/app.js`
+- Modify: `tests/test_debug_runtime.py`
+- Modify: `tests/test_websocket_api.py`
+
+## Requirement Execution Loop
+
+### Plan
+
+1. Add RED tests for out-of-order session replay, whitespace-only protocol messages, and incomplete tool rounds with visible text.
+2. Add the smallest load-token and transcript-repair changes.
+3. Run focused tests, JS syntax, full tests, diff check, and bounded review.
+
+## Verification
+
+- `uv run pytest tests/test_debug_runtime.py tests/test_websocket_api.py -q`
+- `node --check src/agent_lab/presentation/static/app.js`
+- `uv run pytest`
+- `git diff --check`

+ 1 - 0
docs/plans/todos.md

@@ -94,5 +94,6 @@
 | 48.3 | done | `docs/plans/todo-48.3-strict-canonical-types-and-scope-token-cleanup.md` | Align canonical-key equality with strict JSON types and replace retained generation tombstones with unique releasable scope tokens. | Strict nested JSON types and 1000-cycle scope cleanup pass; final bounded gate APPROVED. |
 | 49 | in_progress | `docs/plans/todo-49-tool-mode-ui-session-restore.md` | Add UI mode selection, workspace/session restoration, and clear EventAgent applicability feedback. | Static/WebSocket tests prove requests, snapshots, loaded sessions, and audit context preserve the selected mode. |
 | 49.1 | in_progress | `docs/plans/todo-49.1-session-mode-and-atomic-transcript-safety.md` | Enforce persisted mode, atomically store direct tool rounds, repair incomplete legacy tails, serialize SQLite migration, and hide empty protocol bubbles. | Mode mismatches are rejected without config overwrite; disconnect cannot leave unresolved tool calls; concurrent migration succeeds; replay shows only visible assistant content. |
+| 49.2 | in_progress | `docs/plans/todo-49.2-session-load-race-and-visible-repair.md` | Prevent stale session loads from overwriting the selected session and preserve visible text while stripping incomplete tool protocol. | Out-of-order loads cannot mutate the active session UI; whitespace-only protocol bubbles stay hidden; incomplete tool rounds retain provider-valid visible content. |
 | 50 | pending | `docs/plans/todo-50-comparable-model-tool-metrics.md` | Record mode-aware model/tool spans and include EventAgent usage so both architectures can be compared fairly. | Persistence/API tests report agent, call kind, tokens, TTFT, tool latency, fallback usage, and total turn wall time without double counting. |
 | 51 | pending | `docs/plans/todo-51-comparison-matrix-closeout.md` | Add repeatable comparison fixtures, update project documentation, and close the experimental implementation. | Both modes pass the same scenario matrix; full tests, JS syntax, app import, and documentation checks pass. |