gateway: one instance per session dir; drop the keys the sidebar left behind
Two daemons poll getUpdates and race: one reads the update, the other never sees it, so a message is answered by nobody or twice. The gateway now holds flock on <session_dir>/gateway.pid and a second start says who has it. Removing the sidebar left 12 catalogue keys nobody reads (sidebar.*, widget.*, status.title, ui.running); they are gone from all three catalogues and test_i18n checks keys that still exist. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
be2ab165f7
commit
5054393e17
5 files changed
+54
-42
No files matched your search
@@ -8,11 +8,7 @@ ui.ready = bereit. Enter sendet, Ctrl-D beendet.
|
||||
ui.working = laeuft...
|
||||
ui.steering_queued = Steuerung eingereiht
|
||||
|
||||
sidebar.session = Sitzung
|
||||
sidebar.last_turn = letzter Turn
|
||||
sidebar.tokens = %zu Tok (ein %zu)
|
||||
|
||||
status.title = splinter %s
|
||||
|
||||
role.you = du
|
||||
role.agent = modell
|
||||
@@ -169,14 +165,6 @@ connect.later = Spaeter
|
||||
reply.empty = (leer)
|
||||
|
||||
# Agent-Profile, Kontingent, Seitenleiste (mit den Profilen dazugekommen)
|
||||
sidebar.model = Modell
|
||||
sidebar.usage = Kontingent
|
||||
sidebar.turn_line = %.1f s, %zu Schritte, %zu Tools
|
||||
widget.focus = Ziel
|
||||
widget.plan = Plan
|
||||
widget.tasks = Aufgaben
|
||||
widget.tmux = tmux
|
||||
ui.running = laeuft %lds%s |%s Enter = steuern, Strg-C = abbrechen
|
||||
ui.limit_wait = Nutzungslimit: weiter um %s (Strg-C stoppt, /resume macht weiter)
|
||||
agent.switched = Agent: %s - %s %s
|
||||
agent.readonly = [nur lesen]
|
||||
|
||||
@@ -7,11 +7,7 @@ ui.ready = ready. Enter sends, Ctrl-D quits.
|
||||
ui.working = working...
|
||||
ui.steering_queued = steering queued
|
||||
|
||||
sidebar.session = session
|
||||
sidebar.last_turn = last turn
|
||||
sidebar.tokens = %zu tok (in %zu)
|
||||
|
||||
status.title = splinter %s
|
||||
|
||||
role.you = you
|
||||
role.agent = agent
|
||||
@@ -168,14 +164,6 @@ connect.later = Later
|
||||
reply.empty = (empty)
|
||||
|
||||
# agent profiles, usage, sidebar (added with the profiles)
|
||||
sidebar.model = model
|
||||
sidebar.usage = usage
|
||||
sidebar.turn_line = %.1f s, %zu steps, %zu tools
|
||||
widget.focus = goal
|
||||
widget.plan = plan
|
||||
widget.tasks = tasks
|
||||
widget.tmux = tmux
|
||||
ui.running = running %lds%s |%s Enter = steer, Ctrl-C = cancel
|
||||
ui.limit_wait = usage limit: continuing at %s (Ctrl-C stops, /resume goes on)
|
||||
agent.switched = agent: %s - %s %s
|
||||
agent.readonly = [read-only]
|
||||
|
||||
@@ -12,11 +12,7 @@ ui.steer_mark = direcionar>
|
||||
ui.swarm_locked = [enxame bloqueado]
|
||||
ui.approve = executar %s (%s) %.60s? y/N
|
||||
|
||||
sidebar.session = sessao
|
||||
sidebar.last_turn = ultimo turno
|
||||
sidebar.tokens = %zu tok (entrada %zu)
|
||||
|
||||
status.title = splinter %s
|
||||
|
||||
role.you = voce
|
||||
role.agent = modelo
|
||||
@@ -172,14 +168,6 @@ connect.later = Depois
|
||||
reply.empty = (vazio)
|
||||
|
||||
# perfis de agente, uso, barra lateral (junto com os perfis)
|
||||
sidebar.model = modelo
|
||||
sidebar.usage = uso
|
||||
sidebar.turn_line = %.1f s, %zu passos, %zu ferramentas
|
||||
widget.focus = meta
|
||||
widget.plan = plano
|
||||
widget.tasks = tarefas
|
||||
widget.tmux = tmux
|
||||
ui.running = executando %lds%s |%s Enter = guiar, Ctrl-C = cancelar
|
||||
ui.limit_wait = limite de uso: continua as %s (Ctrl-C para, /resume continua)
|
||||
agent.switched = agente: %s - %s %s
|
||||
agent.readonly = [somente leitura]
|
||||
|
||||
+49
-1
@@ -8,10 +8,12 @@
|
||||
* configuration error, 3 the environment could not be set up (session dir).
|
||||
*/
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <sys/file.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@@ -1212,6 +1214,45 @@ setup_conversation(const struct opts *o, struct sp_agent *ag,
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* One gateway per session directory. Two pollers race for getUpdates: one of
|
||||
* them reads the update and the other never sees it, so a message is answered
|
||||
* by nobody or twice. The lock is the pid file itself and lives as long as
|
||||
* the process: flock is released by the kernel when it exits, even on a kill.
|
||||
*/
|
||||
static int
|
||||
daemon_lock(const char *dir, struct sp_buf *err)
|
||||
{
|
||||
char path[700], other[32];
|
||||
int fd, n;
|
||||
ssize_t r;
|
||||
|
||||
snprintf(path, sizeof(path), "%s/gateway.pid", dir);
|
||||
fd = open(path, O_RDWR | O_CREAT | O_CLOEXEC, 0600);
|
||||
if (fd < 0) {
|
||||
sp_buf_printf(err, "gateway: cannot open %s: %s", path,
|
||||
strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
if (flock(fd, LOCK_EX | LOCK_NB) != 0) {
|
||||
r = read(fd, other, sizeof(other) - 1);
|
||||
other[r > 0 ? (size_t)r : 0] = '\0';
|
||||
n = (int)strcspn(other, "\n");
|
||||
other[n] = '\0';
|
||||
sp_buf_printf(err, "gateway already running%s%s", other[0] ? " (pid " : "",
|
||||
other[0] ? other : "");
|
||||
if (other[0] != '\0')
|
||||
sp_buf_puts(err, ")");
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
(void)ftruncate(fd, 0);
|
||||
n = snprintf(other, sizeof(other), "%ld\n", (long)getpid());
|
||||
(void)!write(fd, other, (size_t)n);
|
||||
/* fd stays open on purpose: closing it would drop the lock */
|
||||
return fd;
|
||||
}
|
||||
|
||||
/* --daemon: answer on Telegram until SIGINT */
|
||||
static int
|
||||
run_daemon(struct sp_agent *ag, struct sp_agent_config *cfg,
|
||||
@@ -1219,7 +1260,7 @@ run_daemon(struct sp_agent *ag, struct sp_agent_config *cfg,
|
||||
struct sp_config *conf, struct sp_buf *err)
|
||||
{
|
||||
char token[256], tpath[700];
|
||||
int rc;
|
||||
int rc, lockfd;
|
||||
|
||||
snprintf(tpath, sizeof(tpath), "%s/telegram.token", sess->dir);
|
||||
if (sp_telegram_token(token, sizeof(token), tpath) != 0) {
|
||||
@@ -1232,10 +1273,17 @@ run_daemon(struct sp_agent *ag, struct sp_agent_config *cfg,
|
||||
"be answered\n");
|
||||
return 2;
|
||||
}
|
||||
lockfd = daemon_lock(sess->dir, err);
|
||||
if (lockfd < 0) {
|
||||
fprintf(stderr, "splinter: %s\n",
|
||||
err->len > 0 ? err->p : "gateway already running");
|
||||
return 2;
|
||||
}
|
||||
cfg->stream = daemon_stream;
|
||||
cfg->stream_ctx = NULL;
|
||||
rc = sp_telegram_run(ag, host, token, conf->telegram_allow, conf,
|
||||
err);
|
||||
close(lockfd); /* the flock goes with it */
|
||||
if (rc != 0)
|
||||
fprintf(stderr, "splinter: %s\n",
|
||||
err->len > 0 ? err->p : "gateway failed");
|
||||
|
||||
+5
-5
@@ -34,7 +34,7 @@ main(void)
|
||||
/* ---- English: the fallback ---- */
|
||||
CHECK(sp_i18n_load(&err, "en") == 0);
|
||||
CHECK(strcmp(sp_i18n_lang(), "en") == 0);
|
||||
CHECK(strcmp(sp_t("sidebar.session"), "session") == 0);
|
||||
CHECK(strcmp(sp_t("cmd.available"), "available:") == 0);
|
||||
CHECK(strcmp(sp_t("ui.ready"), "ready. Enter sends, Ctrl-D quits.") == 0);
|
||||
|
||||
/* a key that exists nowhere is shown as itself, never as an empty line */
|
||||
@@ -44,11 +44,11 @@ main(void)
|
||||
/* ---- German ---- */
|
||||
CHECK(sp_i18n_load(&err, "de") == 0);
|
||||
CHECK(strcmp(sp_i18n_lang(), "de") == 0);
|
||||
CHECK(strcmp(sp_t("sidebar.session"), "Sitzung") == 0);
|
||||
CHECK(strcmp(sp_t("sidebar.last_turn"), "letzter Turn") == 0);
|
||||
CHECK(strcmp(sp_t("cmd.available"), "verfuegbar:") == 0);
|
||||
CHECK(strcmp(sp_t("ui.ready"), "bereit. Enter sendet, Ctrl-D beendet.") == 0);
|
||||
|
||||
/* format strings keep their placeholders, so printf still works */
|
||||
CHECK(strstr(sp_t("sidebar.turn_line"), "%zu") != NULL);
|
||||
CHECK(strstr(sp_t("model.probe_start"), "%zu") != NULL);
|
||||
|
||||
/* ---- completeness: every English key has a German one ---- */
|
||||
n_en = (size_t)sp_i18n_fallback_count();
|
||||
@@ -69,7 +69,7 @@ main(void)
|
||||
/* ---- an unknown language falls back to English, without failing ---- */
|
||||
sp_buf_clear(&err);
|
||||
CHECK(sp_i18n_load(&err, "xx") == 0);
|
||||
CHECK(strcmp(sp_t("sidebar.session"), "session") == 0);
|
||||
CHECK(strcmp(sp_t("cmd.available"), "available:") == 0);
|
||||
|
||||
sp_buf_free(&err);
|
||||
if (failures == 0)
|
||||
|
||||
Reference in new issue
Block a user