Hardcode agent stale timeout

This commit is contained in:
Brandon Zhang
2026-03-27 18:32:25 +08:00
parent 07e31ce215
commit c690d0c483
15 changed files with 14 additions and 92 deletions

View File

@@ -22,8 +22,7 @@ func handleUpdateConfig(stores Stores, broker *events.Broker) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
// Decode partial patch
var patch struct {
DefaultWaitSeconds *int `json:"default_wait_seconds"`
AgentStaleAfterSeconds *int `json:"agent_stale_after_seconds"`
DefaultWaitSeconds *int `json:"default_wait_seconds"`
}
if err := json.NewDecoder(r.Body).Decode(&patch); err != nil {
writeError(w, http.StatusBadRequest, "Invalid JSON")
@@ -41,9 +40,6 @@ func handleUpdateConfig(stores Stores, broker *events.Broker) http.HandlerFunc {
if patch.DefaultWaitSeconds != nil {
current.DefaultWaitSeconds = *patch.DefaultWaitSeconds
}
if patch.AgentStaleAfterSeconds != nil {
current.AgentStaleAfterSeconds = *patch.AgentStaleAfterSeconds
}
if err := stores.Settings.Update(current); err != nil {
writeError(w, http.StatusInternalServerError, err.Error())

View File

@@ -45,7 +45,7 @@ func handleStatus(stores Stores) http.HandlerFunc {
}
if latest != nil {
connected := time.Since(latest.LastSeenAt).Seconds() <= float64(cfg.AgentStaleAfterSeconds)
connected := time.Since(latest.LastSeenAt).Seconds() <= float64(config.AgentStaleAfterSeconds)
agent = map[string]any{
"connected": connected,
"last_seen_at": latest.LastSeenAt.Format(time.RFC3339Nano),
@@ -69,7 +69,6 @@ func handleStatus(stores Stores) http.HandlerFunc {
"settings": models.Settings{
DefaultWaitSeconds: cfg.DefaultWaitSeconds,
DefaultEmptyResponse: cfg.DefaultEmptyResponse,
AgentStaleAfterSeconds: cfg.AgentStaleAfterSeconds,
},
}

View File

@@ -8,6 +8,7 @@ import (
const (
AppVersion = "1.0.1"
AgentStaleAfterSeconds = 30
DefaultEmptyResponse = "call this tool `get_user_request` again to fetch latest user input..."
)
@@ -18,7 +19,6 @@ type Config struct {
DBPath string
LogLevel string
DefaultWaitSeconds int
AgentStaleAfterSeconds int
MCPStateless bool
APIToken string
}
@@ -31,7 +31,6 @@ func Load() Config {
DBPath: getEnv("DB_PATH", "data/local_mcp.sqlite3"),
LogLevel: getEnv("LOG_LEVEL", "INFO"),
DefaultWaitSeconds: getEnvInt("DEFAULT_WAIT_SECONDS", 10),
AgentStaleAfterSeconds: getEnvInt("AGENT_STALE_AFTER_SECONDS", 30),
MCPStateless: getEnvBool("MCP_STATELESS", true),
APIToken: getEnv("API_TOKEN", ""),
}

View File

@@ -42,8 +42,8 @@ CREATE TABLE IF NOT EXISTS agent_activity (
// defaultSettings seeds initial values; OR IGNORE means existing rows are unchanged.
const defaultSettings = "" +
"INSERT OR IGNORE INTO settings (key, value) VALUES ('default_wait_seconds', '10');\n" +
"INSERT OR IGNORE INTO settings (key, value) VALUES ('agent_stale_after_seconds', '30');\n" +
"DELETE FROM settings WHERE key = 'default_empty_response';\n"
"DELETE FROM settings WHERE key = 'default_empty_response';\n" +
"DELETE FROM settings WHERE key = 'agent_stale_after_seconds';\n"
// Open opens (creating if necessary) a SQLite database at dbPath, applies the
// schema, and seeds default settings.

View File

@@ -27,7 +27,6 @@ type Instruction struct {
type Settings struct {
DefaultWaitSeconds int `json:"default_wait_seconds"`
DefaultEmptyResponse string `json:"default_empty_response"`
AgentStaleAfterSeconds int `json:"agent_stale_after_seconds"`
}
// AgentActivity tracks the last time an agent called get_user_request.

View File

@@ -30,7 +30,6 @@ func (s *SettingsStore) Get() (models.Settings, error) {
cfg := models.Settings{
DefaultWaitSeconds: 10,
DefaultEmptyResponse: config.DefaultEmptyResponse,
AgentStaleAfterSeconds: 30,
}
for rows.Next() {
@@ -43,10 +42,6 @@ func (s *SettingsStore) Get() (models.Settings, error) {
if n, err := strconv.Atoi(value); err == nil {
cfg.DefaultWaitSeconds = n
}
case "agent_stale_after_seconds":
if n, err := strconv.Atoi(value); err == nil {
cfg.AgentStaleAfterSeconds = n
}
}
}
return cfg, rows.Err()
@@ -57,10 +52,8 @@ func (s *SettingsStore) Get() (models.Settings, error) {
func (s *SettingsStore) Update(patch models.Settings) error {
_, err := s.db.Exec(`
INSERT OR REPLACE INTO settings (key, value) VALUES
('default_wait_seconds', ?),
('agent_stale_after_seconds', ?)`,
('default_wait_seconds', ?)` ,
strconv.Itoa(patch.DefaultWaitSeconds),
strconv.Itoa(patch.AgentStaleAfterSeconds),
)
return err
}