X-Git-Url: https://git.giacomolli.uk/onechat/blobdiff_plain/790279faf0fda789d93a75f6f5996e65d5de4a18..723f6e18adc6482ed913e1618c8a76e981720c2b:/subagent_run.go?ds=inline diff --git a/subagent_run.go b/subagent_run.go index 0780393..8084c39 100644 --- a/subagent_run.go +++ b/subagent_run.go @@ -256,6 +256,18 @@ func (r *SubagentRuns) Resume(ctx context.Context) error { 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()