ui, model, cost and idle timeouts
- lcm: the sidebar widget and /status segment show the context, the number of
compactions, messages and bytes of the last cut, and how many old tool
outputs were trimmed. The counters are the compactor's own, not an estimate.
- cost: a provider-reported USD cost (usage.cost/cost_usd) is carried through
sse/openai, the agent and the engine. /cost reports it with the cache share
and splits judged from plain turns; the notes say that an upstream judge is
not visible in the provider's usage. The status plugin and junction prefer
the reported number over list-price arithmetic.
- curses: the running turn's seconds moved from the input line to the status
bar. Notes and errors are transcript rows below the cause, never text in the
input line or the status bar; a failed backend request is a status row and is
retried by the agent. The steer prompt is only "steer> " and what was typed.
- model: /model probe works in the chat. The picker lists the configuration at
once, then asks the endpoint the session is on what it serves and adds those
models, so a router's whole menu is selectable. provider/model selectors now
apply the right provider instead of becoming a model name. The choice is
written to <session>.model and restored when that session is reopened; /new
carries the current model into the new session.
- sidebar: plugin titles are bold and underlined (this curses has no italic
attribute), with a rule between the plugin blocks.
- run/cli: a command timeout is an idle window. Every chunk on stdout or
stderr resets it, and the process is asked with waitpid(WNOHANG) whether it
is still there before the window is extended. A long build that keeps
reporting progress is no longer killed for being long; a silent hang is.
- config: ';' separates settings on one line, so
plugin lcm { keep = 6; tool_trim = 8192 } parses as two keys.
- tests: lcm widget/status counters, one-line config blocks, session model
restore and /model probe, cli idle timeout with a talkative and a silent
command, run output reset, and the UI status/retry rows.
make check: all tests passed.
This commit is contained in:
1 parent
dc9a1c62ec
commit
af2001bfee
33 files changed
+1035
-184
No files matched your search
+67
-15
@@ -254,9 +254,23 @@ ci_contains(const char *hay, const char *needle)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* the idle window in seconds; 0 or less means no limit */
|
||||
static long
|
||||
cli_timeout_s(const struct cli_cfg *c)
|
||||
{
|
||||
char *end = NULL;
|
||||
long n;
|
||||
|
||||
if (c == NULL || c->timeout[0] == '\0')
|
||||
return 0;
|
||||
n = strtol(c->timeout, &end, 10);
|
||||
return n > 0 ? n : 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Build the shell line: timeout, the command with placeholders expanded, the
|
||||
* session arguments, stdin and stderr redirection.
|
||||
* Build the shell line: the command with placeholders expanded, the session
|
||||
* arguments, stdin and stderr redirection. The timeout is not a `timeout`
|
||||
* wrapper here: the read loop owns it so output can move the deadline.
|
||||
*/
|
||||
static int
|
||||
build_cmd(const struct cli_cfg *c, const char *path, const char *prompt,
|
||||
@@ -273,8 +287,6 @@ build_cmd(const struct cli_cfg *c, const char *path, const char *prompt,
|
||||
(sp_buf_puts(cmd, ". ") != 0 || sh_word(cmd, envfile) != 0 ||
|
||||
sp_buf_puts(cmd, " && ") != 0))
|
||||
return -1;
|
||||
if (sp_buf_printf(cmd, "timeout %s ", c->timeout) != 0)
|
||||
return -1;
|
||||
while (*p != '\0') {
|
||||
if (strncmp(p, "{file}", 6) == 0) {
|
||||
if (sh_word(cmd, path) != 0)
|
||||
@@ -315,22 +327,30 @@ build_cmd(const struct cli_cfg *c, const char *path, const char *prompt,
|
||||
* turn could only end when the program decided to. `claude -p` under its
|
||||
* 30-minute timeout therefore held Ctrl-C hostage: the UI set the flag, joined
|
||||
* the worker, and the worker was still blocked reading a pipe. The child gets
|
||||
* its own process group (the shell, `timeout`, and the program under it), and
|
||||
* the read loop polls it, so a cancellation kills the whole tree.
|
||||
* its own process group (the shell and the program under it), and the read
|
||||
* loop polls it, so a cancellation kills the whole tree.
|
||||
*
|
||||
* The timeout is an idle window, not a wall clock: every byte on stdout or
|
||||
* stderr moves it forward, and the process itself is asked whether it is still
|
||||
* there. A long answer that keeps typing is work, not a hang.
|
||||
*/
|
||||
static int
|
||||
run_cmd(const char *line, const char *errpath, struct sp_buf *raw,
|
||||
char *errtext, size_t errcap, int *status, struct sp_buf *err)
|
||||
run_cmd(const char *line, const char *errpath, long timeout_s,
|
||||
struct sp_buf *raw, char *errtext, size_t errcap, int *status,
|
||||
struct sp_buf *err)
|
||||
{
|
||||
const volatile int *cancel = sp_cancel_flag();
|
||||
char chunk[4096];
|
||||
FILE *ef;
|
||||
int fds[2], st = 0, rc = 0;
|
||||
int fds[2], st = 0, rc = 0, timed_out = 0, reaped = 0;
|
||||
pid_t child;
|
||||
size_t en = 0;
|
||||
time_t last_out;
|
||||
long errseen = 0;
|
||||
|
||||
sp_buf_clear(raw);
|
||||
*status = 0;
|
||||
last_out = time(NULL);
|
||||
if (pipe(fds) != 0) {
|
||||
sp_buf_printf(err, "cli: pipe: %s", strerror(errno));
|
||||
return -1;
|
||||
@@ -359,7 +379,9 @@ run_cmd(const char *line, const char *errpath, struct sp_buf *raw,
|
||||
close(fds[1]);
|
||||
for (;;) {
|
||||
struct pollfd pfd;
|
||||
struct stat es;
|
||||
ssize_t got;
|
||||
time_t now;
|
||||
int pr;
|
||||
|
||||
if (cancel != NULL && *cancel) {
|
||||
@@ -368,6 +390,18 @@ run_cmd(const char *line, const char *errpath, struct sp_buf *raw,
|
||||
rc = -1;
|
||||
break;
|
||||
}
|
||||
now = time(NULL);
|
||||
/* stderr goes to a file: its growth is output too */
|
||||
if (errpath[0] != '\0' && stat(errpath, &es) == 0 &&
|
||||
(long)es.st_size > errseen) {
|
||||
errseen = (long)es.st_size;
|
||||
last_out = now;
|
||||
}
|
||||
if (timeout_s > 0 && now - last_out >= timeout_s) {
|
||||
(void)kill(-child, SIGKILL);
|
||||
timed_out = 1;
|
||||
break;
|
||||
}
|
||||
pfd.fd = fds[0];
|
||||
pfd.events = POLLIN;
|
||||
pfd.revents = 0;
|
||||
@@ -402,10 +436,28 @@ run_cmd(const char *line, const char *errpath, struct sp_buf *raw,
|
||||
rc = -1;
|
||||
break;
|
||||
}
|
||||
/*
|
||||
* Output keeps the program alive only if the program is still
|
||||
* there: a closed child can leave bytes in the pipe.
|
||||
*/
|
||||
if (!reaped) {
|
||||
pid_t r;
|
||||
|
||||
do {
|
||||
r = waitpid(child, &st, WNOHANG);
|
||||
} while (r < 0 && errno == EINTR);
|
||||
if (r == child)
|
||||
reaped = 1;
|
||||
}
|
||||
if (!reaped)
|
||||
last_out = time(NULL);
|
||||
}
|
||||
close(fds[0]);
|
||||
(void)waitpid(child, &st, 0);
|
||||
*status = st;
|
||||
if (!reaped)
|
||||
while (waitpid(child, &st, 0) < 0 && errno == EINTR)
|
||||
;
|
||||
/* the caller reports 124 as the cli's own timeout */
|
||||
*status = timed_out ? (124 << 8) : st;
|
||||
ef = fopen(errpath, "r");
|
||||
if (ef != NULL) {
|
||||
en = fread(errtext, 1, errcap - 1, ef);
|
||||
@@ -532,8 +584,8 @@ cli_send_one(struct cli_cfg *c, const struct sp_conv *conv,
|
||||
}
|
||||
if (build_cmd(c, path, body.p != NULL ? body.p : "", key, uuid, extra,
|
||||
errpath, envfile, &cmd) != 0 ||
|
||||
run_cmd(cmd.p, errpath, &raw, errtext, sizeof(errtext), &status,
|
||||
err) != 0) {
|
||||
run_cmd(cmd.p, errpath, cli_timeout_s(c), &raw, errtext,
|
||||
sizeof(errtext), &status, err) != 0) {
|
||||
unlink(path);
|
||||
goto fail;
|
||||
}
|
||||
@@ -550,8 +602,8 @@ cli_send_one(struct cli_cfg *c, const struct sp_conv *conv,
|
||||
resume ? "--resume" : "--session-id", uuid);
|
||||
if (build_cmd(c, path, body.p != NULL ? body.p : "", key, uuid,
|
||||
extra, errpath, envfile, &cmd) != 0 ||
|
||||
run_cmd(cmd.p, errpath, &raw, errtext, sizeof(errtext),
|
||||
&status, err) != 0) {
|
||||
run_cmd(cmd.p, errpath, cli_timeout_s(c), &raw,
|
||||
errtext, sizeof(errtext), &status, err) != 0) {
|
||||
unlink(path);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user