Repository navigation
test(agent): cancel the ask once its kimi is up, not on a 0.3s clock - #943
Conversation
The 0.3s cap ran from the spawn, so wherever the stand-in `kimi` starts slower than that, as on macOS, the ask was killed while it was still starting and had noted no worker to take. Readiness now comes from `ask.pid`, which the stand-in writes only after the worker is noted, and the cancel path proves the group goes rather than the leader alone.
gloryfromca
left a comment
There was a problem hiding this comment.
No blockers; this can merge as far as I am concerned.
The readiness marker is written only after the worker PID, so cancelling after ask.pid appears reliably reaches the behavior under test without weakening the assertion that the child process dies with the ask's process group. The 5-second readiness bound and 2-second reap allowance are consistent with the neighboring subprocess tests.
I covered the repository rules, the complete diff, the production ask cancellation/timeout implementation and its callers' expectations, the test's introducing history, backward compatibility, test-strength/regression concerns, and architecture constraints. This is test-only and changes no runtime behavior or public contract.
Verification:
uv run --extra dev pytest tests/test_subagent_kimi_code.py -q: 59 passed.- Changed test repeated 10 times with
-n0: 10 passed. - The initial default-extra invocation did not reach the test because
raven_everoswas absent; an all-extras retry also did not reach it because this host lacksgccfordatrie.
Summary
A follow-up to #927, which merged before this was pushed. Its test
test_an_ask_that_runs_out_takes_what_its_kimi_startedcut the Kimi Code ask's timeout to 0.3s and then read theworker.pidits stand-inkimiwrites. The timeout runs from the spawn, so wherever the stand-in starts slower than that, the ask'sfinallyended the process group before the stand-in had noted its worker, and readingworker.pidraisedFileNotFoundError. The review on #927 reproduced it deterministically on macOS; on Linux the stand-in's start crossed 0.3s here only at low priority beside busy loops.The test now cancels the ask once the stand-in is up rather than waiting on the clock: it waits for
ask.pid, which the stand-in writes only after noting its worker, checks the worker is alive, cancels, and asserts the worker went with the group. Cancel and timeout end the ask through the samefinally, and the timeout path keeps its own tests in the file, the 1.0s POSIX one and the Windows-branch one. Test-only: no production file changes.Type
Verification
Linux, Python 3.12, on main d106a5c:
uv run --frozen --python 3.12 --all-extras pytest tests/test_subagent_kimi_code.py tests/test_subagent_third_party.py -q: 348 passed.The race, forced: with the stand-in made to wait 0.5s before starting its worker (a scratch edit to
_through_kimi, not part of this change), main's test fails withFileNotFoundErroronworker.pid, the failure reported on fix(*): stop cli sub-agents on windows and hand new ones a rotated web key #927, and the new test passes.Against the fix: making the POSIX branch of
kimi_code._end_treekill the leader alone (proc.kill()in place ofos.killpg) turns the new test red, and only it (1 failed, 347 passed over the two files).ruff checkandruff format --checkon the changed file: clean.make lint-typesleavestests/out, so no type check covers this change.Relevant tests pass locally
Relevant lint / type checks pass locally
User-facing docs or screenshots are updated when needed
Risk
Test-only. One test is rewritten under a new name; no production file changes, so reverting the commit is the whole rollback.
Related Issues
#927