feat(tasks): add inherited context and resilient LLM execution

Add read-only task context inheritance, ordered task-level LLM failover, live Worker controls, cascading task cleanup, FIFO task concurrency, cancellation diagnostics, UI updates, tests, build script, and changelog.
This commit is contained in:
pphua committed 2026-08-20 18:34:24 +08:00
1 parent 7090b034f8
commit 9793b522d9
82 files changed
+11094 -1712

No files matched your search

+16 -7
View File
@@ -73,14 +73,8 @@ func main() {
sigCtx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop()
// re-wrap with a named cause so a run cancelled by shutdown says "后端进程正在
// 关停" in its trace instead of a bare context.Canceled (see agent/cancelcause.go).
ctx, shutdown := context.WithCancelCause(sigCtx)
ctx, shutdown := shutdownContext(sigCtx)
defer shutdown(agent.AbortShutdown)
go func() {
<-sigCtx.Done()
shutdown(agent.AbortShutdown)
}()
mgr, err := server.NewManager(*dataDir, *proxy)
if err != nil {
@@ -113,3 +107,18 @@ func main() {
defer cancel()
_ = httpSrv.Shutdown(shutdownCtx)
}
// shutdownContext deliberately does not derive from signalCtx. If it did, the
// parent's plain context.Canceled could win the race before AbortShutdown was
// attached to the child, losing the diagnostic cause in every running Agent.
func shutdownContext(signalCtx context.Context) (context.Context, context.CancelCauseFunc) {
ctx, shutdown := context.WithCancelCause(context.Background())
go func() {
select {
case <-signalCtx.Done():
shutdown(agent.AbortShutdown)
case <-ctx.Done():
}
}()
return ctx, shutdown
}
+19
View File
@@ -0,0 +1,19 @@
package main
import (
"context"
"testing"
"github.com/Autumn-27/artex/agent"
)
func TestShutdownContextPreservesNamedCause(t *testing.T) {
signalCtx, signalCancel := context.WithCancel(context.Background())
ctx, shutdown := shutdownContext(signalCtx)
defer shutdown(nil)
signalCancel()
<-ctx.Done()
if code, _, _, ok := agent.AbortReason(ctx); !ok || code != "shutdown" {
t.Fatalf("code=%q ok=%v, want shutdown", code, ok)
}
}