fix six defects and add an offline test suite

Four settings read from the environment (endpoint, model, reasoning,
scratch dir) pointed straight at getenv() memory instead of a copy,
and both setstr() and the cleanup at exit called free() on them.
Changing one of them from inside the session therefore freed the
environment block: "/endpoint http://x.example" with SOLO_ENDPOINT
set died inside the handler, and SOLO_TMPDIR killed the process on the
way out without a slash command at all. Reproduced on musl, both are
copies now, and the two post-load env re-reads go through setstr() so
they stop leaking the value create() already stored.

The generic parameter handler typed every number with
json_object_new_double, so "/max_tokens 4096" reached the endpoint as
4096.0 and "/seed 3" as 3.0. A number written without a decimal point
or an exponent now stays an integer, which is what the OpenAI schema
asks for; 0.7, .5 and 1e3 are still floats, and a word is still a
string.

The deadline for a command was time(0) + SOLO_TIMEOUT, and time()
counts whole seconds, so the effective limit was the timeout minus
whatever fraction of the second the command happened to start in.
Measured with SOLO_TIMEOUT=3, commands died after 2.38s, 2.47s, 2.68s
and 3.19s depending on the phase. rp() takes its deadline from
clock_gettime(CLOCK_MONOTONIC) now, which is also immune to the clock
being stepped underneath it.

A SOLO_TIMEOUT below 1 gave rp() a deadline already in the past, so
every command failed at once with "still running after 0s", and
atoi on anything unparseable lands there too. Below 1 now means no
limit. The API read, which passed time(0) + 1e9 to mean "never",
passes no deadline at all.

Only the child called setpgid(0,0), so a kill(-k, ...) issued before
the child reached it found no process group and was dropped, leaving
the command running as an orphan. A standalone harness confirms both
halves: without the parent claim the signal is lost and the child
runs to completion, with it the child dies. The parent claims the
group too, which is the belt to the child's braces.

hc() wrote the response envelope with one uncounted write(), so a
signal arriving mid-write truncated the JSON and the parent reported
"request failed" for a request that had in fact succeeded.

Both link steps write to <name>.new and rename it. Overwriting a
running executable fails with ETXTBSY, which is exactly what happens
when the agent rebuilds the binary it is itself running from, and a
failed link used to take the working binary with it. make clean now
removes the temp names as well.

test.sh holds 13 offline tests: no API key and no network, every line
handed to the agent starting with / or !, each test in its own
directory because the session file lives in the cwd. They cover the
four crash paths, integer/float/string typing, a staggered-start
sweep for the early timeout, SOLO_TIMEOUT=0 and a negative value,
process group cleanup after a timeout, and the tool description
quoting the real timeout. make test runs them. The README documents
the timeout semantics, the integer typing and the new build step.

Verified: 13 passed, 0 failed against the new binary, and 8 of the
13 fail against the previous one, which is what makes them regression
tests rather than decoration. Still silent under -Wall -Wextra and
under -Wshadow -Wformat=2 -Wcast-align -Wwrite-strings
-Wstrict-prototypes -Wmissing-prototypes -Wredundant-decls -Wundef.
Built and tested on Alpine gcc 15.2 (musl) with libcurl 8.22.0,
json-c 0.19 and readline 8.3.
This commit is contained in:
Luxferre
2026-10-04 06:06:06 +00:00
parent c0d0b2633d
commit ecc48cd472
5 changed files with 179 additions and 26 deletions
+17 -5
View File
@@ -43,12 +43,17 @@ make
That produces a stripped dynamic binary named `solo` in the project directory.
The default flags are: `-Wall -Wextra -O2 -std=c99 -march=native`.
Both binaries are linked under a temporary name and then renamed, so `make`
works while an agent is still running from the old one, and a link failure
leaves the previous binary in place.
Other targets:
make clean # remove solo and solo-static
make install # install to $(PREFIX)/bin, default /usr/local/bin
make installdir # print the directory install would use
make uninstall # remove the installed binaries
make test # offline regression tests, no API key or network
make static-deps # build the static curl and c-ares archives, see below
## Static build
@@ -227,7 +232,10 @@ environment set instead.
`/name` is a generic model-parameter editor. The value is typed from its
spelling: `true` and `false` become booleans, a parseable number becomes a
number, and anything else stays a string.
number, and anything else stays a string. A number written without a decimal
point or an exponent stays an integer, so `/max_tokens 4096` is sent as `4096`
and not as `4096.0`, which a strict endpoint rejects; `0.7` and `1e3` are sent
as floats.
> /model deepseek/deepseek-v4.1-flash
> /reasoning_effort high
@@ -321,9 +329,10 @@ Tool execution in detail:
with `-c`, in the current working directory.
- stdout and stderr are merged into one pipe, so the model sees them together in
the order they were produced.
- The child gets its own process group (`setpgid`). On timeout or Ctrl-C the
whole group is signalled, so `make`, a shell pipeline and everything they
spawned all die, not just the direct child.
- The child gets its own process group (`setpgid`), claimed by the parent as
well as the child, so the group signal cannot lose the race against the child
starting up. On timeout or Ctrl-C the whole group is signalled, so `make`, a
shell pipeline and everything they spawned all die, not just the direct child.
- The output is returned verbatim, with an exit marker on the last line. Nothing
is truncated or summarised, which is the point: the model sees exactly what
the terminal saw.
@@ -340,7 +349,10 @@ back into the transcript so that a follow-up turn can reuse them.
## Timeouts, exit codes and interrupts
Every command the agent runs is bounded by `SOLO_TIMEOUT` seconds (120 by
default), and the exit status is reported to the model as a marker line:
default), and the exit status is reported to the model as a marker line. The
deadline comes from a monotonic clock, so a command is not killed early by a
wall clock adjustment. A `SOLO_TIMEOUT` below 1 means no limit, for the rare
command that has to run to completion.
| Status | Meaning |
| ------- | ------------------------------------------------------------------ |