fix(cf): register crashes on first name collision under set -e#7
Merged
Conversation
… set -e `cf register`'s retry loop used `((attempts++))`. Post-increment evaluates to the *old* value, so on the first iteration it yields 0 — which bash reports as exit status 1. Combined with the script's `set -e`, that aborted `cf register` entirely the moment a generated name collided with an existing one, instead of retrying. Replace it with `attempts=$((attempts + 1))` (an assignment always returns success), and add a guard so exhausting all 100 attempts errors out rather than silently registering a duplicate name. Adds a regression test (`test_register_survives_name_collisions`) that fills a chunk of the name space so collisions are frequent and registers 30×; it fails against the old `((attempts++))` and passes with the fix. Suite: 40/40. Salvaged from the superseded #1 (which can't merge — it predates the global-room rework and would revert main's CI + presentation tests). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Bug
cf register's name-retry loop used((attempts++)):((expr))returns exit status 1 when the arithmetic result is 0, and post-incrementattempts++evaluates to the old value (0) on the first iteration. With the script'sset -e, that abortscf registerthe moment a generated name collides with an existing participant — instead of retrying for a fresh name.Fix
attempts=$((attempts + 1))— an assignment always returns success, so the loop retries correctly.Test
test_register_survives_name_collisionsfills a chunk of the name space so collisions are frequent, then registers 30×; each must succeed with a non-empty name. It fails against the old((attempts++))(39/40) and passes with the fix (40/40).Context
Salvaged from #1, which I'm closing as superseded: it predates the global-room rework (#3 closed issue #2 with a different
$HOME/.cf_sessionapproach) and its diff would revert main's CI workflow and presentation-helper tests. This is the one unambiguous, still-applicable fix from it. (Other candidates in #1 —sendnewline sanitization,tail -forphan cleanup inawait, a LASTLINE read-cursor — are noted on #1 as possible follow-ups.)🤖 Generated with Claude Code