todo-49.1-session-mode-and-atomic-transcript-safety.md 2.7 KB

Todo 49.1 Session Mode and Atomic Transcript Safety Plan

Status: done

Goal

Prevent session restoration from changing architecture semantics or persisting invalid provider transcripts.

Scope

  • Before updating an existing session config, read its persisted tool_invocation_mode (default dual_agent for legacy config) and reject an incoming mismatch with a stable error; do not overwrite config.
  • Add SessionStore.append_messages() and implement one SQLite transaction for a direct assistant tool-call message plus all matching tool replies.
  • In direct mode with tool calls:
    • keep the assistant/tool transcript in active memory immediately;
    • persist the complete protocol group only after batch execution returns all replies;
    • cancellation/disconnect before completion leaves no partial protocol group.
  • Restore defensively from sessions created by earlier experimental code: drop an incomplete trailing assistant tool-call group or orphan tool replies rather than sending an invalid transcript.
  • Make SQLite column migration safe across concurrent store/process initialization using serialized migration and/or duplicate-column recheck.
  • UI replay skips assistant records whose content is empty and whose only purpose is tool protocol; tool rows retain existing tool styling.

Files

  • Modify: src/agent_lab/application/session_store.py
  • Modify: src/agent_lab/infrastructure/sqlite_store.py
  • Modify: src/agent_lab/application/runtime.py
  • Modify: src/agent_lab/presentation/static/app.js
  • Modify: tests/test_sqlite_store.py
  • Modify: tests/test_debug_runtime.py
  • Modify: tests/test_websocket_api.py

Requirement Execution Loop

Plan

  1. Add RED mode-mismatch tests proving config/history remain unchanged.
  2. Add RED cancellation tests proving no partial assistant/tool group is stored and reconnect remains valid.
  3. Add RED incomplete-tail repair and concurrent migration stress tests.
  4. Add RED static replay test for tool-call-only assistant suppression.
  5. Implement atomic persistence, restore repair, migration serialization, and UI filtering.
  6. Run focused/node/full verification and final reviews.

Verification

  • UV_CACHE_DIR=.uv-cache uv run pytest tests/test_sqlite_store.py tests/test_debug_runtime.py tests/test_websocket_api.py -q
  • node --check src/agent_lab/presentation/static/app.js
  • UV_CACHE_DIR=.uv-cache uv run pytest
  • git diff --check

Observe / Update

  • Persisted mode mismatches fail before config overwrite.
  • Direct assistant tool calls and replies commit as one SQLite transaction; cancellation leaves no unresolved protocol group.
  • Concurrent migration, orphan/incomplete legacy transcript repair, focused tests (138 passed), and full suite (385 passed at this checkpoint) passed.