Stop the chat client only after the API has stopped (closes #4)
check / check (push) Successful in 1m14s

The chat client's context no longer follows the bot's, so a stop no
longer sends it SIGTERM while the API is still finishing its requests.
The deferred stop in Run, which runs after the API's, stops it instead,
so a request in progress at a stop gets its answer rather than a 500.
The README says so.

The new test runs the whole bot with the test binary itself standing in
for simplex-chat on PATH. The stand-in holds its answer to the contacts
request until the test has told the bot to stop.

Model: opus-5-5
This commit is contained in:
clawbot
2026-09-29 01:36:44 +00:00
parent b965e45454
commit 407eaf847a
3 changed files with 237 additions and 2 deletions
+3 -1
View File
@@ -67,7 +67,9 @@ func Run(ctx context.Context, log *slog.Logger, cfg *config.Config) error {
// Cancelling this stops the chat client; the deferred wait makes
// Run return only once it has exited, whatever path Run takes.
cliCtx, stopCLI := context.WithCancel(ctx)
// Cancelling ctx does not reach it, so that the API, stopped first,
// can finish its requests while the chat client still answers.
cliCtx, stopCLI := context.WithCancel(context.WithoutCancel(ctx))
cli, err := simplex.StartCLI(cliCtx, log, filepath.Join(cfg.DataDir, "simplex"),
DisplayName, chatPort)