Files
krang/tests
lotherk c57cd6eede review: close the HTTP, budget and stuck-detection holes
Findings from a pass over the daemon, the sandbox and the surfaces.

HTTP: a loopback dashboard without a token was reachable from any web page.
The wildcard CORS grant and an OPTIONS branch before the token check let a
cross-origin page POST into the one session, and a DNS-rebinding page could
read it under its own name. Requests now need a loopback Host while no token
is configured, an Origin must match the Host, and there is no CORS grant.
MCP connections get a receive/send timeout instead of pinning a thread
forever.

CLI: --check silently ignored an unreadable or invalid config and printed a
green self-test, because the load error was discarded. It now fails with the
parser message, prints the sandbox plan, and only then runs the scripted turn.
--self-test still works without a config.

Budgets: max_turn_seconds (default 1800) cancels a turn that outlives it and
records turn_timeout; the answer produced after the cancel is discarded.
External chat now counts against max_impulses_per_hour instead of bypassing
it.

Stuck detection: kstuck_turn() reset the whole ladder whenever a turn called
a mutating tool, so a loop of failing 'run' calls never escalated. The ladder
now resets only after a turn whose tool signals are clean. The dashboard's
stuck level is a locked snapshot instead of a read of daemon-private state.

Ledger: impulse records stored the running session total as if it were that
impulse's usage; they now store per-turn deltas, and turn_end logs them.

Config: refuse / and .. in rootfs/state/workspace, refuse nested trees (a
state inside the disposable rootfs would be deleted with it), and reject
negative sizes.

Event log: O_NOFOLLOW|O_CLOEXEC.

Makefile: check-asan reused the same object paths, so a plain make afterwards
linked uninstrumented code against sanitizer objects and failed. It now cleans
before and after.

Tests: test_server covers Host/Origin refusal and the OPTIONS/token check;
test_krang covers the path guards and the stuck reset; test_timeout proves
the wall-clock cancellation with a sleeping tool. make check is now seven
suites, ASAN also green, and the root integration still passes on a fresh
debootstrap.
2026-11-21 19:57:38 +00:00
..