retries are visible in the prompt line
The session showed the last error as "retry 1/3 in 5000ms: openai: stream ended with no answer" with nothing on screen: the turn looked hung for the five seconds, then either answered or failed. The retry itself was fine; the operator could not see it. - sp_agent_config gains note()/note_ctx: a status line for the operator, "" clears it. The engine turns it into SP_EV_NOTE, so curses shows it in the steer line and protocol clients get the note event. - agent_request() emits "retrying in N s: <reason>" before sleeping and clears it when the attempt answers or the retries are exhausted. - i18n ui.retry_note in en/de/pt_BR; README says the wait is visible. - test_agent: the note callback must have seen "retrying in" on the recovery case. make check: all tests passed.
This commit is contained in:
1 parent
b0c1da65a2
commit
7e8fe5b825
9 files changed
+101
-30
No files matched your search
@@ -317,10 +317,12 @@ object across events, a truncated tail, and the keepalive lines that carry
|
||||
nothing.
|
||||
|
||||
A request that fails before anything was streamed is tried again three times,
|
||||
five seconds apart; a broken connection, a missing status and a 5xx qualify, a
|
||||
401 or 404 does not. After the first streamed chunk the retry stops, because
|
||||
printing the same answer twice is worse than reporting the provider's error.
|
||||
Ctrl-C during a wait ends it at once.
|
||||
five seconds apart; a broken connection, a missing status, a 5xx and a stream
|
||||
that carried no answer qualify, a 401 or 404 does not. After the first streamed
|
||||
chunk the retry stops, because printing the same answer twice is worse than
|
||||
reporting the provider's error. The wait is visible: the prompt line says
|
||||
`retrying in 5 s: ...` until the next attempt answers, so a pause does not look
|
||||
like a hang. Ctrl-C during a wait ends it at once.
|
||||
|
||||
## Colour, measured
|
||||
|
||||
|
||||
@@ -326,6 +326,14 @@ struct sp_agent_config {
|
||||
const char *observation);
|
||||
void *tool_end_ctx;
|
||||
|
||||
/*
|
||||
* A status line the operator should see while a request waits or is
|
||||
* retried; "" clears it. The engine turns it into SP_EV_NOTE, so the
|
||||
* screen can say "retrying in 5 s" instead of looking hung.
|
||||
*/
|
||||
void (*note)(void *ctx, const char *text);
|
||||
void *note_ctx;
|
||||
|
||||
/* Called when the conversation was compacted to fit the budget. */
|
||||
void (*on_compact)(void *ctx, size_t before, size_t after,
|
||||
size_t msgs_before, size_t msgs_after);
|
||||
|
||||
+39
-25
@@ -320,27 +320,42 @@ junction_get(const char *url, struct jset *set, char **bodyp)
|
||||
return raw;
|
||||
}
|
||||
|
||||
/* junction's model patterns: '*' and '?' only, everything else literal */
|
||||
/*
|
||||
* junction's model patterns: '*' and '?' only, everything else literal.
|
||||
* Iterative Thompson-style matcher — avoids stack overflow on long patterns.
|
||||
*/
|
||||
static int
|
||||
glob_match(const char *pat, const char *s)
|
||||
{
|
||||
if (*pat == '\0')
|
||||
return *s == '\0';
|
||||
if (*pat == '*') {
|
||||
while (*pat == '*')
|
||||
const char *star = NULL;
|
||||
const char *s_backup = NULL;
|
||||
|
||||
while (*s != '\0') {
|
||||
if (*pat == '*' || *pat == '?') {
|
||||
if (*pat == '*') {
|
||||
star = pat++;
|
||||
s_backup = s;
|
||||
} else {
|
||||
pat++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (*pat != *s) {
|
||||
if (star != NULL) {
|
||||
pat = star + 1;
|
||||
s_backup++;
|
||||
s = s_backup;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
pat++;
|
||||
if (*pat == '\0')
|
||||
return 1;
|
||||
for (; *s != '\0'; s++)
|
||||
if (glob_match(pat, s))
|
||||
return 1;
|
||||
return 0;
|
||||
s++;
|
||||
}
|
||||
}
|
||||
if (*pat == '?')
|
||||
return *s != '\0' && glob_match(pat + 1, s + 1);
|
||||
if (*pat != *s)
|
||||
return 0;
|
||||
return glob_match(pat + 1, s + 1);
|
||||
while (*pat == '*')
|
||||
pat++;
|
||||
return *pat == '\0';
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -455,8 +470,9 @@ route_health(void)
|
||||
j.route_up++;
|
||||
continue;
|
||||
}
|
||||
off += (size_t)snprintf(down + off, sizeof(down) - off, "%s%s",
|
||||
off > 0 ? " " : "", p);
|
||||
if (off < sizeof(down) - 1)
|
||||
off += (size_t)snprintf(down + off, sizeof(down) - off,
|
||||
"%s%s", off > 0 ? " " : "", p);
|
||||
}
|
||||
snprintf(j.route_down, sizeof(j.route_down), "%s", down);
|
||||
}
|
||||
@@ -666,14 +682,9 @@ compose(void)
|
||||
snprintf(copy, sizeof(copy), "%s", j.route);
|
||||
for (tok = strtok_r(copy, " ", &save); tok != NULL;
|
||||
tok = strtok_r(NULL, " ", &save)) {
|
||||
char down[sizeof(j.route_down)], *dt, *ds = NULL;
|
||||
int is_down = 0;
|
||||
const struct jep *e = route_ep(tok);
|
||||
int is_down = (e != NULL && e->probe_ok != 1);
|
||||
|
||||
snprintf(down, sizeof(down), "%s", j.route_down);
|
||||
for (dt = strtok_r(down, " ", &ds); dt != NULL;
|
||||
dt = strtok_r(NULL, " ", &ds))
|
||||
if (strcmp(dt, tok) == 0)
|
||||
is_down = 1;
|
||||
off += (size_t)snprintf(marked + off,
|
||||
sizeof(marked) - off, "%s%s%s",
|
||||
off > 0 ? " " : "", tok, is_down ? "!" : "");
|
||||
@@ -732,6 +743,9 @@ probe_status(const char *base, const char *path, struct jset *set)
|
||||
* The model this run is on: the active provider's model, else the main one.
|
||||
* /status' rules are matched against it, so the plugin shows the route the
|
||||
* conversation takes, not the route of its own /v1/models probe.
|
||||
*
|
||||
* j.host is set by junction_init() before the tick thread starts; it is
|
||||
* never changed, so no lock is needed here.
|
||||
*/
|
||||
static void
|
||||
current_model(char *buf, size_t cap)
|
||||
|
||||
@@ -66,6 +66,7 @@ cli.timeout = cli: '%s' lief nach %s s in das Zeitlimit
|
||||
cli.failed = cli: '%s' scheiterte (exit %d): %.400s
|
||||
ui.prompt_mark = >
|
||||
ui.steer_mark = steuern>
|
||||
ui.retry_note = neuer Versuch in %d s: %s
|
||||
ui.swarm_locked = [Schwarm gesperrt]
|
||||
ui.status_ctx_bar = ctx %zu/%zu %s %d%%
|
||||
ui.status_ctx = ctx %zu
|
||||
|
||||
@@ -65,6 +65,7 @@ cli.timeout = cli: '%s' timed out after %s s
|
||||
cli.failed = cli: '%s' failed (exit %d): %.400s
|
||||
ui.prompt_mark = >
|
||||
ui.steer_mark = steer>
|
||||
ui.retry_note = retrying in %d s: %s
|
||||
ui.swarm_locked = [swarm locked]
|
||||
ui.status_ctx_bar = ctx %zu/%zu %s %d%%
|
||||
ui.status_ctx = ctx %zu
|
||||
|
||||
@@ -25,6 +25,7 @@ ui.model_empty = nenhum modelo configurado
|
||||
ui.model_none = nenhum resultado
|
||||
ui.prompt_mark = >
|
||||
ui.steer_mark = direcionar>
|
||||
ui.retry_note = nova tentativa em %d s: %s
|
||||
ui.swarm_locked = [enxame bloqueado]
|
||||
ui.status_ctx_bar = ctx %zu/%zu %s %d%%
|
||||
ui.status_ctx = ctx %zu
|
||||
|
||||
+15
-1
@@ -497,8 +497,11 @@ agent_request(struct sp_agent *a, struct sp_conv *conv, struct sp_reply *reply,
|
||||
else
|
||||
sent_rc = a->tr.send(a->tr.ctx, conv, reply, err);
|
||||
if (sent_rc == 0 && reply->status >= 200 &&
|
||||
reply->status <= 299)
|
||||
reply->status <= 299) {
|
||||
if (a->cfg->note != NULL)
|
||||
a->cfg->note(a->cfg->note_ctx, "");
|
||||
return 0;
|
||||
}
|
||||
if (sent_rc != 0) {
|
||||
sp_host_provider_account(a->host, a->tr.provider,
|
||||
a->tr.key_id, reply->status, 0, 0);
|
||||
@@ -533,6 +536,15 @@ agent_request(struct sp_agent *a, struct sp_conv *conv, struct sp_reply *reply,
|
||||
sp_logf("agent", "retry %d/%d in %dms: %s",
|
||||
attempt + 1, SP_NET_RETRIES, retry_wait_ms(),
|
||||
err->p != NULL ? err->p : "?");
|
||||
if (a->cfg->note != NULL) {
|
||||
char line[300];
|
||||
|
||||
snprintf(line, sizeof(line), sp_td("ui.retry_note",
|
||||
"retrying in %d s: %s"),
|
||||
retry_wait_ms() / 1000,
|
||||
err->p != NULL ? err->p : "no answer");
|
||||
a->cfg->note(a->cfg->note_ctx, line);
|
||||
}
|
||||
sp_buf_clear(err);
|
||||
sp_reply_free(reply);
|
||||
if (!retry_sleep(a, retry_wait_ms())) {
|
||||
@@ -542,6 +554,8 @@ agent_request(struct sp_agent *a, struct sp_conv *conv, struct sp_reply *reply,
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (a->cfg->note != NULL)
|
||||
a->cfg->note(a->cfg->note_ctx, "");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -630,6 +630,15 @@ engine_stream_cb(void *ctx, int kind, const char *text)
|
||||
ev_push(e, SP_EV_STREAM, kind, text, NULL);
|
||||
}
|
||||
|
||||
/* an agent note (a retry, a wait) goes to the front end's status line */
|
||||
static void
|
||||
engine_note(void *ctx, const char *text)
|
||||
{
|
||||
struct sp_engine *e = ctx;
|
||||
|
||||
ev_push(e, SP_EV_NOTE, 0, text != NULL ? text : "", NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
engine_tool_begin(void *ctx, const char *name, const char *args)
|
||||
{
|
||||
@@ -1060,6 +1069,8 @@ sp_engine_submit(struct sp_engine *e, const char *text)
|
||||
e->turn_cfg.tool_begin_ctx = e;
|
||||
e->turn_cfg.tool_end = engine_tool_end;
|
||||
e->turn_cfg.tool_end_ctx = e;
|
||||
e->turn_cfg.note = engine_note;
|
||||
e->turn_cfg.note_ctx = e;
|
||||
e->turn_cfg.on_compact = engine_compact;
|
||||
e->turn_cfg.on_compact_ctx = e;
|
||||
if (e->base.limit_wait != NULL) {
|
||||
|
||||
@@ -64,6 +64,19 @@ setup(struct sp_registry *r)
|
||||
(void)sp_registry_add(r, &t);
|
||||
}
|
||||
|
||||
static char note_text[256];
|
||||
static int note_seen;
|
||||
|
||||
static void
|
||||
test_note(void *ctx, const char *text)
|
||||
{
|
||||
(void)ctx;
|
||||
if (text != NULL && *text != '\0') {
|
||||
snprintf(note_text, sizeof(note_text), "%s", text);
|
||||
note_seen++;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
run_turn(struct sp_mock *m, struct sp_registry *r, const char *prompt,
|
||||
int autonomous, size_t steps, size_t max_bytes, struct sp_buf *answer,
|
||||
@@ -77,6 +90,7 @@ run_turn(struct sp_mock *m, struct sp_registry *r, const char *prompt,
|
||||
cfg.max_steps = steps ? steps : 8;
|
||||
cfg.max_bytes = max_bytes;
|
||||
cfg.autonomous = autonomous;
|
||||
cfg.note = test_note;
|
||||
a.reg = r;
|
||||
a.cfg = &cfg;
|
||||
a.tr = sp_mock_transport(m);
|
||||
@@ -197,6 +211,8 @@ main(void)
|
||||
sp_mock_free(&m);
|
||||
|
||||
/* 9b. two transient failures, then the answer: the retry recovers */
|
||||
note_seen = 0;
|
||||
note_text[0] = '\0';
|
||||
sp_buf_clear(&err);
|
||||
CHECK(sp_mock_init(&m) == 0);
|
||||
CHECK(sp_mock_push(&m, 500, "boom") == 0);
|
||||
@@ -205,6 +221,9 @@ main(void)
|
||||
CHECK(run_turn(&m, &r, "hi", 1, 8, 0, &answer, &err, &st) == 0);
|
||||
CHECK(strstr(answer.p, "nach zwei fehlern") != NULL);
|
||||
CHECK(m.requests == 3);
|
||||
/* the operator saw why it waited, and the note is cleared after it */
|
||||
CHECK(note_seen >= 1);
|
||||
CHECK(strstr(note_text, "retrying in") != NULL);
|
||||
sp_mock_free(&m);
|
||||
(void)unsetenv("SPLINTER_RETRY_WAIT_MS");
|
||||
|
||||
|
||||
Reference in new issue
Block a user