fix: report accurate is_running after trader update to stop redundant start

Live verification of the relaunch (update) branch surfaced this: the update
response omitted is_running, so the launcher fired a redundant start that got
400 'Trader is already running', showing an error toast and skipping the
dashboard navigation even though the relaunch succeeded.

- PUT /traders/:id now reports is_running (a running trader is restarted with
  the new config, so it stays running).
- The already-running rejection carries error_key trader.start.already_running
  and the shared launcher treats it as success (launch is idempotent).
This commit is contained in:
tinkle-community
2026-07-05 23:36:53 +09:00
parent a744328313
commit 9b70455e7f
3 changed files with 45 additions and 3 deletions

View File

@@ -731,7 +731,10 @@ func (s *Server) handleUpdateTrader(c *gin.Context) {
"trader_id": traderID,
"trader_name": req.Name,
"ai_model": req.AIModelID,
"message": "Trader updated successfully",
// A running trader is restarted with the new config (async above), so
// report it as running — callers must not fire a redundant start.
"is_running": wasRunning,
"message": "Trader updated successfully",
})
}
@@ -792,7 +795,10 @@ func (s *Server) handleStartTrader(c *gin.Context) {
if existingTrader != nil {
status := existingTrader.GetStatus()
if isRunning, ok := status["is_running"].(bool); ok && isRunning {
c.JSON(http.StatusBadRequest, gin.H{"error": "Trader is already running"})
c.JSON(http.StatusBadRequest, gin.H{
"error": "Trader is already running",
"error_key": "trader.start.already_running",
})
return
}
// Trader exists but is stopped - remove from memory to reload fresh config