cli: the main transport falls back at the limit, too
cli_fallback = claude1, claude0 names cli delegates whose cmd and env= take over when cli_cmd answers with its limit. The main command is benched as "cli", a fallback under its own id, on the same bench the delegation uses (sp_limit_parse, sp_cooldown_until, sp_cooldown_set are now exported from libsplinter). The session key stays, so claude resumes the same conversation under the next account. With everyone benched the turn fails with the first reset, as WAIT_QUOTA ready_at=. A fallback's env= goes through a 0600 file the shell sources, not a command line. A delegate's child is benched under the delegate's id (SPLINTER_CLI_ID), never as "cli". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ca8cdb6d13
commit
808039cd58
7 files changed
+302
-21
No files matched your search
@@ -419,6 +419,8 @@ load_one(struct sp_config *c, const char *path, struct sp_buf *err)
|
||||
set_str(c->session_dir, sizeof(c->session_dir), val);
|
||||
else if (!strcmp(key, "cli_cmd"))
|
||||
set_str(c->cli_cmd, sizeof(c->cli_cmd), val);
|
||||
else if (!strcmp(key, "cli_fallback"))
|
||||
set_str(c->cli_fallback, sizeof(c->cli_fallback), val);
|
||||
else if (!strcmp(key, "cli_env")) {
|
||||
if (add_env(c->cli_env, &c->ncli_env, val, err, path,
|
||||
lineno) != 0) {
|
||||
@@ -549,6 +551,7 @@ sp_config_write_example(const char *path, struct sp_buf *err)
|
||||
"#transport = cli\n"
|
||||
"#cli_cmd = claude -p\n"
|
||||
"#cli_env = CLAUDE_CODE_OAUTH_TOKEN=sk-ant-...\n"
|
||||
"#cli_fallback = claude1, claude0\n"
|
||||
"\n"
|
||||
"# Plugins to load, one per line. Paths are relative to the working\n"
|
||||
"# directory unless absolute.\n"
|
||||
|
||||
@@ -85,6 +85,7 @@ struct sp_config {
|
||||
char cli_cmd[512];
|
||||
char cli_env[SP_CONFIG_MAX_ENV][SP_CONFIG_ENV_LEN]; /* NAME=VALUE */
|
||||
size_t ncli_env;
|
||||
char cli_fallback[256]; /* cli delegate ids, comma separated */
|
||||
char memory_url[512];
|
||||
char memory_key_env[64];
|
||||
char telegram_allow[256]; /* comma separated user ids */
|
||||
|
||||
+24
-15
@@ -208,7 +208,6 @@ lower(char *dst, size_t cap, const char *src)
|
||||
* the description. Ties go to the earlier entry: predictable beats clever when
|
||||
* someone is reading the log at night.
|
||||
*/
|
||||
static long cooldown_until(const char *id);
|
||||
|
||||
static const struct sp_delegate *
|
||||
choose(const struct sp_config *cfg, const char *task, const char *wanted,
|
||||
@@ -228,7 +227,7 @@ choose(const struct sp_config *cfg, const char *task, const char *wanted,
|
||||
int score = 0;
|
||||
char reason[192] = "";
|
||||
|
||||
if (cooldown_until(d->id) != 0)
|
||||
if (sp_cooldown_until(d->id) != 0)
|
||||
continue; /* benched: at its limit until the reset */
|
||||
|
||||
snprintf(tags, sizeof(tags), "%s", d->tags);
|
||||
@@ -392,6 +391,8 @@ exec_delegate(const struct del_ctx *c, const struct sp_delegate *d,
|
||||
{
|
||||
const char *ps = getenv("SPLINTER_CLI_SESSION");
|
||||
|
||||
if (cli && !remote)
|
||||
(void)setenv("SPLINTER_CLI_ID", d->id, 1);
|
||||
if (cli && ps != NULL && *ps != '\0') {
|
||||
snprintf(clisess, sizeof(clisess), "%s:%s", ps, d->id);
|
||||
if (!remote)
|
||||
@@ -406,9 +407,17 @@ exec_delegate(const struct del_ctx *c, const struct sp_delegate *d,
|
||||
|
||||
if (sp_buf_init(&line) != 0)
|
||||
_exit(127);
|
||||
if ((d->nenv > 0 || clisess[0] != '\0') &&
|
||||
if ((d->nenv > 0 || clisess[0] != '\0' || cli) &&
|
||||
sp_buf_puts(&line, "env ") != 0)
|
||||
_exit(127);
|
||||
if (cli) {
|
||||
char kv[64];
|
||||
|
||||
snprintf(kv, sizeof(kv), "SPLINTER_CLI_ID=%s", d->id);
|
||||
if (shell_quote(&line, kv) != 0 ||
|
||||
sp_buf_puts(&line, " ") != 0)
|
||||
_exit(127);
|
||||
}
|
||||
if (clisess[0] != '\0') {
|
||||
char kv[300];
|
||||
|
||||
@@ -739,8 +748,8 @@ cooldown_path(const char *id, char *buf, size_t len)
|
||||
}
|
||||
|
||||
/* the epoch the delegate is benched until, 0 when it is free */
|
||||
static long
|
||||
cooldown_until(const char *id)
|
||||
long
|
||||
sp_cooldown_until(const char *id)
|
||||
{
|
||||
char path[700];
|
||||
FILE *f;
|
||||
@@ -760,8 +769,8 @@ cooldown_until(const char *id)
|
||||
return until;
|
||||
}
|
||||
|
||||
static void
|
||||
cooldown_set(const char *id, long until, const char *why)
|
||||
void
|
||||
sp_cooldown_set(const char *id, long until, const char *why)
|
||||
{
|
||||
char path[700], *slash;
|
||||
FILE *f;
|
||||
@@ -869,8 +878,8 @@ parse_reset(const char *e)
|
||||
}
|
||||
|
||||
/* Is this error a limit, and until when? Returns 1 and sets *until. */
|
||||
static int
|
||||
looks_limit(const char *e, long *until)
|
||||
int
|
||||
sp_limit_parse(const char *e, long *until)
|
||||
{
|
||||
long t;
|
||||
|
||||
@@ -912,16 +921,16 @@ run_child_fb(const struct del_ctx *c, const struct sp_delegate **dp,
|
||||
|
||||
sp_buf_clear(reply);
|
||||
sp_buf_clear(err);
|
||||
if ((until = cooldown_until(d->id)) != 0) {
|
||||
if ((until = sp_cooldown_until(d->id)) != 0) {
|
||||
/* named explicitly, but benched: do not spend a call */
|
||||
sp_buf_printf(err, "delegate '%s' at its limit (WAIT_QUOTA "
|
||||
"ready_at=%ld)", d->id, until);
|
||||
rc = -1;
|
||||
} else {
|
||||
rc = run_child(c, d, task, reply, err);
|
||||
if (rc == 0 || !looks_limit(err->p, &until))
|
||||
if (rc == 0 || !sp_limit_parse(err->p, &until))
|
||||
break;
|
||||
cooldown_set(d->id, until, err->p);
|
||||
sp_cooldown_set(d->id, until, err->p);
|
||||
}
|
||||
{
|
||||
char when[32];
|
||||
@@ -1265,9 +1274,9 @@ par_fallback(struct del_ctx *c, struct job *jobs, size_t njobs, size_t i,
|
||||
time_t tt;
|
||||
struct tm tm;
|
||||
|
||||
if (j->out.p == NULL || !looks_limit(j->out.p, &until))
|
||||
if (j->out.p == NULL || !sp_limit_parse(j->out.p, &until))
|
||||
return 0;
|
||||
cooldown_set(j->d->id, until, j->out.p);
|
||||
sp_cooldown_set(j->d->id, until, j->out.p);
|
||||
tt = (time_t)until;
|
||||
strftime(when, sizeof(when), "%Y-%m-%d %H:%M", localtime_r(&tt, &tm));
|
||||
nl = strlen(j->note);
|
||||
@@ -1705,7 +1714,7 @@ static int
|
||||
looks_quota_wait(const char *e, long *ready_at)
|
||||
{
|
||||
long until = 0;
|
||||
int r = looks_limit(e, &until);
|
||||
int r = sp_limit_parse(e, &until);
|
||||
|
||||
if (ready_at != NULL)
|
||||
*ready_at = r ? until : 0;
|
||||
|
||||
Reference in new issue
Block a user