Dayward AIWeChat Mini Program
Build Your Own Coding Agent in 21 Days
Week 1 · D7🔒 LockedAbout 4 hours

Session Persistence and Recovery: an Append-Only Event Log, Resume and Forking, Week One Retrospective

Stop a conversation from vanishing with the process: use an append-only JSONL event log to record every message, tool call, and usage figure, replay the log to restore state after a restart, and fork a new session from any event — then look back at how these seven layers stacked up over week one.

Today's goals 0/3

Sign in to tick these off and save your progress.

Today's Goals

  1. Design an append-only session event log, and explain why a snapshot-style session object won't work
  2. Restore a session by replaying events, and handle a corrupted log and version incompatibility
  3. Fork a new session from any event, and explain the difference between forking and rolling back

This is week one's last day. When you finish, scroll back up and tick the three goals off.

Plain-Language Walkthrough

The shift handover: they clock off and someone else continues tomorrow

Yesterday's new hire can now handle failures on their own. But they leave at six, and someone else takes over the next day.

How well the handover goes depends on what they left behind. Leave "I looked at that bug" and the next person investigates from scratch; leave a record — what was done when, which command was run, what it output, what was concluded — and the next person picks it up in five minutes.

The Agent's situation is identical, except that "clocking off" happens far more often: the user pressed Ctrl+C, the terminal was closed, the machine rebooted, you changed a line of code and restarted. Every time, the in-memory message array is gone, including the facts it took three tool calls to establish.

One misconception to clear up: today's work is not giving the model memory. Day one already said the model has no memory; history is something we re-carry in every turn. Today only moves that carrying from memory to disk — recovery does not mean it remembered, it means the history was carried back in. The distinction is more than wording: precisely because we carry the history ourselves, we can choose how much to carry (day twelve's compaction) and up to which point (today's forking).

So the question becomes a plain engineering one: what shape should this record take? The first layer of the answer is the shape, the second is how to read it back, the third is what else you can do with it once read. Today covers all three.

Sign in and link WeChat to read

Sign in, then link your WeChat mini program account on the account page. Linked accounts share one free article per day. Unlock additional articles with rewarded videos in the mini program.

Mini program QR code

Scan in WeChat to open Dayward AI. Open the same course and chapter, choose the rewarded video, then refresh this page after completion.

Interview questions

  • For session persistence, would you use an append-only event log or store a session snapshot? What does each cost?会话持久化你选事件日志还是存会话快照?各自的代价是什么?
    Common in ChinaCommon overseasBasic#persistence#event-log

    🔒 Unlock this chapter to see the answer keys.

  • How does an append-only log handle a last line that was cut off mid-write?只追加的日志怎么处理写到一半崩掉的最后一行?
    Common in ChinaCommon overseasIntermediate#durability#event-log

    🔒 Unlock this chapter to see the answer keys.

  • What is the difference between forking a new session at some point in history and rolling back to that point?从历史某一步分叉出一条新会话,和回滚到那一步有什么区别?
    Common in ChinaCommon overseasDeep dive#fork#session-state

    🔒 Unlock this chapter to see the answer keys.

Comments