返回 DeepSeek-Reasonix
tool_transcript_checkpoint.go
根目录 / internal / control / tool_transcript_checkpoint.go
1 package control
2
3 import (
4 "context"
5 "log/slog"
6 "reasonix/internal/agent"
7 )
8
9 // CheckpointSession implements agent.SessionCheckpointer. The boundary is
10 // intentionally semantic: ordinary todo, approval, assistant and turn-end
11 // events remain eligible for the write-behind batch.
12 func (c *Controller) CheckpointSession(ctx context.Context, boundary agent.SessionCheckpointBoundary) error {
13 switch boundary {
14 case agent.CheckpointBeforeModel, agent.CheckpointBeforeTopTool:
15 if _, err := c.flushSessionEvents(ctx); err != nil {
16 return err
17 }
18 return nil
19 case agent.CheckpointUserAdmitted:
20 // An event store recorded the message when it was admitted; only a
21 // legacy transcript still holds it in memory alone.
22 if c.sessionEventStore() != nil || c.SessionPath() == "" {
23 return nil
24 }
25 if err := c.snapshot(false, false, false); err != nil {
26 slog.Warn("controller: save admitted user message", "err", err)
27 }
28 return nil
29 default:
30 return nil
31 }
32 }
33
33 lines GO