mirror of
https://github.com/RuoJi6/ARTEX.git
synced 2026-12-06 05:01:50 +08:00
fix(chat): show the sandbox container a conversation actually uses
A reporter chat bound to one task ran commands in that task's sandbox, while the chat page kept querying the empty session container. Save the task or session target on the conversation and point the badge, uploads, and later turns at it.
This commit is contained in:
1 parent
8bac4960e7
commit
b18cf89b77
9 files changed
+531
-57
No files matched your search
+18
-14
@@ -63,6 +63,7 @@ func (s *Server) pgListConversations(w http.ResponseWriter, r *http.Request) {
|
||||
writeErr(w, 500, err.Error())
|
||||
return
|
||||
}
|
||||
s.fillConversationSandboxes(cs)
|
||||
items := make([]conversationListItem, 0, len(cs))
|
||||
s.chatMu.Lock()
|
||||
for _, c := range cs {
|
||||
@@ -126,6 +127,7 @@ func (s *Server) pgCreateConversation(w http.ResponseWriter, r *http.Request) {
|
||||
writeErr(w, 500, err.Error())
|
||||
return
|
||||
}
|
||||
s.fillConversationSandbox(c)
|
||||
writeJSON(w, 200, c)
|
||||
}
|
||||
|
||||
@@ -217,6 +219,7 @@ func (s *Server) pgRenameConversation(w http.ResponseWriter, r *http.Request) {
|
||||
writeErr(w, 404, "conversation not found")
|
||||
return
|
||||
}
|
||||
s.fillConversationSandbox(updated)
|
||||
writeJSON(w, 200, updated)
|
||||
}
|
||||
|
||||
@@ -677,6 +680,7 @@ func (s *Server) runConversationTurn(ctx context.Context, cancel context.CancelC
|
||||
webSearch = a.WebSearch
|
||||
}
|
||||
sessionID := s.convBusyKey(c.ID) // "conv-<id>" transcript session
|
||||
ctx = s.ensureConversationSandbox(ctx, c)
|
||||
emit := func(rec db.Activity) {
|
||||
if _, err := pg.AppendConvActivity(c.ID, rec); err != nil {
|
||||
log.Printf("[conv %d] append activity failed: %v", c.ID, err)
|
||||
@@ -982,26 +986,26 @@ func (s *Server) runTriggeredRun(item triggeredRun) {
|
||||
s.chatMu.Lock()
|
||||
s.chatBusy[busyKey] = true
|
||||
s.chatMu.Unlock()
|
||||
var preset sandbox.Target
|
||||
if mgr := sandbox.Default(); mgr != nil && mgr.Enabled() {
|
||||
if item.agentKey == "reporter" && item.taskID > 0 && !item.multiTask {
|
||||
preset = sandbox.Target{Scope: sandbox.ScopeTask, OwnerID: strconv.FormatInt(item.taskID, 10)}
|
||||
}
|
||||
target := sandboxTargetForTrigger(item.agentKey, item.taskID, item.multiTask, c.ID)
|
||||
if err := pg.SetConversationSandbox(c.ID, string(target.Scope), target.OwnerID); err != nil {
|
||||
log.Printf("[trigger] save sandbox binding for conv %d failed: %v", c.ID, err)
|
||||
} else {
|
||||
c.SandboxScope = string(target.Scope)
|
||||
c.SandboxOwnerID = target.OwnerID
|
||||
}
|
||||
if preset.Valid() {
|
||||
s.runConversationSync(c, msg, busyKey, preset)
|
||||
if mgr := sandbox.Default(); mgr != nil && mgr.Enabled() {
|
||||
if t, ok := s.m.Task(preset.OwnerID); !ok || s.resolvedTaskStatus(t) != "running" {
|
||||
mgr.RequestIdleStop(preset)
|
||||
if mgr := sandbox.Default(); mgr != nil && mgr.Enabled() && target.Valid() {
|
||||
s.runConversationSync(c, msg, busyKey, target)
|
||||
if target.Scope == sandbox.ScopeTask {
|
||||
if t, ok := s.m.Task(target.OwnerID); !ok || s.resolvedTaskStatus(t) != "running" {
|
||||
mgr.RequestIdleStop(target)
|
||||
}
|
||||
} else {
|
||||
// Triggered one-shot sessions (no bound task) do not need to sit idle for 20m.
|
||||
mgr.RequestIdleStop(target)
|
||||
}
|
||||
return
|
||||
}
|
||||
s.runConversationSync(c, msg, busyKey)
|
||||
// Triggered one-shot sessions (no bound task) do not need to sit idle for 20m.
|
||||
if mgr := sandbox.Default(); mgr != nil && mgr.Enabled() {
|
||||
mgr.RequestIdleStop(sandbox.Target{Scope: sandbox.ScopeSession, OwnerID: busyKey})
|
||||
}
|
||||
}
|
||||
|
||||
// firstLine returns a single-line, length-capped preview (shared with summaries).
|
||||
|
||||
Reference in new issue
Block a user