Repository navigation
fix: atomic config save, stdin-free prompter tests, credential env lock - #162
Merged
Merged
Conversation
1. config: write_atomic removed the destination before the rename. Two parallel saves raced on that remove (NotFound, flaky in Coverage on #161), and a crash between remove and rename left no config.toml. rename replaces atomically on Unix and Windows (MOVEFILE_REPLACE_ EXISTING), so it is now rename-only with the one retry. Parallel-save test: 30/30 on Linux, 15/15 on Windows. 2. agent: StdinPrompter / StdinQuestionPrompter read the process stdin inside the async ask. The read blocks the runtime thread, so the tests' 2 s timeout could not cancel it; with stdin left open (a terminal or a pipe) the tests never ended and other tests queued on the stdin lock — `cargo test -p whycodes-agent` hung. The prompters take an AnswerInput (default: locked process stdin); tests pass an empty reader and still go through `ask`. With stdin held open: 3/3 runs in 32 s, was hung on the first. 3. agent: rate_limit_retries_same_model_on_next_credential and failover_api_key_walks_named_credentials both set and restore the credential env vars; run in parallel, one restored the other's vars mid-turn and the 429 failover found no second key (flaky in Coverage on #154 and #161). Both now hold CREDENTIAL_ENV_LOCK. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Rename-only saves no longer lose a remove race, so tests never took the 'first rename failed, retry succeeded' arm and config fell to 2406/2407. The same logic as two always-run lines: let-else on the first rename, map_err on the retry. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Three tests that failed or hung intermittently. Two of them were product bugs.
1.
config::write_atomicwas not atomic (and raced). It removedconfig.tomland then renamed the temp over it. Two parallel saves raced on the remove (NotFound; flakywrite_atomic_parallel_saves_do_not_collidein Coverage on #161), and a crash between the two steps left no config at all.std::fs::renamealready replaces atomically on Unix and Windows (MoveFileExW+MOVEFILE_REPLACE_EXISTING), so the save is now rename-only with the existing single retry. The parallel-save test passed 30/30 under a Linux stress run and 15/15 on Windows.2. Stdin prompter tests hung the agent suite.
StdinPrompter::ask/StdinQuestionPrompter::askread the process stdin synchronously inside the async block. The tests' 2 stimeoutcannot cancel a blocking read, and theiris_terminalskip does not catch an open pipe. So with stdin left open the read never returned, the runtime never shut down, and other stdin readers queued behind the lock:cargo test -p whycodes-agenthung, both in a background loop and in a harness. The prompters now take anAnswerInput(fn() -> Box<dyn BufRead>, default: the locked process stdin). Tests still callask, withstd::io::empty(). Production behavior is unchanged. With stdin held open the suite passed 3/3 in 32 s; before, it hung on the first run.3. Credential env-var race.
rate_limit_retries_same_model_on_next_credentialandfailover_api_key_walks_named_credentialsboth set and restoreWHYCODES_CREDENTIAL_LANEand the named-credential vars. Run in parallel, one restored the other's vars mid-turn, and the 429 failover found no second key (flaky in Coverage on #154 and #161). Both now hold a test-onlyCREDENTIAL_ENV_LOCK.Test plan
🤖 Generated with Claude Code