Skip to content

Fix two test_wait flakes: a stop that waited on background commands, and a test lock that held the service loop - #342

Merged
lydakis merged 1 commit into
mainfrom
claude/project-thread-etkmky
Oct 29, 2026
Merged

lydakis merged 1 commit into
mainfrom
claude/project-thread-etkmky

Conversation

@lydakis

@lydakis lydakis commented Oct 29, 2026

Copy link
Copy Markdown
Owner

Requested by George · project thread

Both flakes come from tests/test_wait.py failing the runtime job on PRs that never touched the daemon.

1. A stop waited on background commands (test_waiters_share_output_before_and_after_process_completion timed out in Client.close, runs 40673434375 and 40792167581)

When the daemon stopped with a background command still running, it waited up to 5 s for the publication stream, because the command's result task held a store handle until the command ended. The test fixture times commands out at 5 s, so a stop took about 4.9 s, right at close's 5 s limit, and it recorded the command as timed_out even though the daemon had killed it. The registry now ends background commands when the daemon stops, the same way it ends terminals. Each one's group is killed and its handle records process_lost straight away, which is what the next start would have said. Locally the stop went from 4.93 s to 0.02 s. A new test checks the resulting state: after a clean stop the row reads finished / process_lost, and a restarted daemon reports process_lost. On main the row read timed_out.

2. The storage-failure test's lock held the service loop (test_a_fatal_storage_failure_still_answers_admissions_queued_before_it, failed on #334 and #333)

The test holds SQLite's write lock while it sends its admissions. When a turn ends, the service looks for ready turns (next_ready, which takes BEGIN IMMEDIATE on the writer) and awaits that look on its own loop. If the look came after the test took the lock, the loop stayed blocked until the lock was released. It then read the admissions only after the failure, so some got no reply. Before taking the lock, the test now waits until the service's store counters show it has finished that look. To check this, I ran the daemon alone on a CPU shared with six busy loops: replies went missing in 2 of 8 runs before the change and in none of 12 after.

The other intermittent failures in recent runs fall outside this PR:

Local runs: cargo fmt and clippy pass; test_wait passes. In the full runtime suite only test_acp fails locally, and that's because this machine has no bubblewrap.


Generated by Claude Code

…d a test lock that held the service loop

A daemon that stopped with a background command still running waited
up to 5 s for the publication stream: the command's result task kept a
store handle open until the command ended or the stream timed out. The
tests' fixture times commands out at 5 s, so the stop took about as long
as `Client.close` allows, failed it now and then, and recorded the
command as timed out. The registry now ends background commands as the
daemon stops, as it ends terminals: each group is killed and its handle
records process_lost at once, which the next start would have said.

The fatal-storage test holds SQLite's write lock while it sends its
admissions. The service looks for ready turns as each turn ends, on its
own loop and through the store; a look still to come when the lock was
taken held that loop, so the admissions were read only after the
failure. The test now waits until the service has looked, by its store
counters, before taking the lock. Starving the daemon of CPU reproduced
the missing replies in 2 of 8 runs before and none of 12 after.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013jkdGEgwvrmgA2w4Bq4gqN
@lydakis lydakis self-assigned this Oct 29, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-10-29T03:48:43.340378Z 160b0bd PR opened
🔒 Security Review ✅ Completed 2026-10-29T03:50:44.602469Z 160b0bd PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@lydakis
lydakis merged commit 4b20a9a into main Oct 29, 2026
4 checks passed
@lydakis lydakis mentioned this pull request Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants