Repository navigation
Description
Turn progress lives in three places, and each one is written separately: the conversation event log (SQL), the Turn record (Redis), and the agent run's history in memory. A checkpoint or a pause saves the in-memory history to the log, then writes Turn state to Redis. When memory lags behind the log, a pause can save stale history or stale flags. #3705 hit this again and again while it fixed #3687.
Findings
- Compaction is already atomic.
replaceHistoryinserts one event under the conversation event lock, after a history-version check (conversations/sql/history.ts). The log does not end up half-written. - The agent run keeps its own copy of the history and a resume baseline (
agent/resume.ts). A pause saves that copy (savePausedintask-execution/checkpoint.ts). After a compaction committed, a pause before the run switched its copy saved the pre-compaction history on top of the compacted log. - Turn state (
state,committedSeq,historyVersion,promptSaved,turnStartSeq) is a Redis record (task-execution/turn-cursor.ts), written after the SQL commit. A crash or a failed write between the two leaves them in disagreement. Run every agent on one Conversation execution core #2567 lists this in Appendix B. - A fact about progress, such as "the prompt is saved", is correct only when the write that saves it also holds that progress. fix(agent): Decide Turn membership by event seq #3705 needed these ordering fixes:
- The prompt flag was set before the input checkpoint succeeded.
- The prompt flag was set before the replacement checkpoint succeeded.
- The pause snapshot took the live history from before the replacement.
- The seqs of the old history stayed paired with the new history after a failed replacement checkpoint.
- Fork history committed after a Turn started joined that Turn.
Proposal (from @dcramer): make the event log the only durable record of Turn progress. Resume rebuilds the history from the log. Turn facts such as "prompt added" become log events, written in the same transaction as the messages they describe. Then a pause has nothing of its own to save.
Related: #2567 (one execution core), #3687, #3705. TJ is working on this area.
via @dcramer.
--
Activity