]> git.giacomolli.uk - onechat/blobdiff - subagent_run.go
Resume queued appends at their saved log ID
[onechat] / subagent_run.go
index 0780393db3f87c96e5d6aef425535106c102b4f3..8084c390a7012d5213019f1f784ec3214ce08bbe 100644 (file)
@@ -256,6 +256,18 @@ func (r *SubagentRuns) Resume(ctx context.Context) error {
        return r.save()
 }
 
        return r.save()
 }
 
+// Snapshot locks the run state, memory, and subagent logs while snapshot reads
+// the agent files. The lock order agrees with Stop, which logs under the run
+// lock.
+func (r *SubagentRuns) Snapshot(ctx context.Context, snapshot func() error) error {
+       r.mutex.Lock()
+       defer r.mutex.Unlock()
+
+       return r.memory.Snapshot(ctx, func() error {
+               return r.subagents.Snapshot(ctx, snapshot)
+       })
+}
+
 // Close ends every run and waits for them. No subagent starts after Close.
 func (r *SubagentRuns) Close() {
        r.mutex.Lock()
 // Close ends every run and waits for them. No subagent starts after Close.
 func (r *SubagentRuns) Close() {
        r.mutex.Lock()