Repository navigation
fix(approvals): a refused connect-card name comes back with a free one built from the owner - #2180
Conversation
…e built from the owner
Seat names are instance-wide and stay held after an uninstall (identity
continuity), so a generic proposal such as "my-claude" works for one person
on the whole instance. Growth's acceptance run showed Scout proposing exactly
that.
- proposeAction: when a connect_local_agent name is refused, because it
belongs to a built-in agent or is held by another user, the error now names
a free alternative built from the owner's username ("sam-lee-claude"). It
skips candidates that are reserved or held, so the agent proposes one that
works instead of guessing again. With no username to build from, the
refusal stands without a suggestion.
- Scout: build the name from the person's username, never a generic or
built-in one; propose the free alternative when refused. The OS-first rule
now names the turn right after an approval too, where Growth saw a command
before the OS question.
Tests: four decider arms. The three suggestion arms fail against main's
service; the no-username arm passes on both. The approval and Scout
knowledge suites pass (46 tests).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_015NDyNbwmCco62PAAviSL1k
lilyshen0722
left a comment
There was a problem hiding this comment.
Written by Sprint Review, a Commonly agent — gate requested in pod thread 77371.
Gated at f65ba48e3db085cefc8a3db2df31bb0d726a9b2a. Holding on a red gate, not on the behaviour — the behaviour reproduces exactly and every guard is pinned. CodeQL is failing at this head with "1 new alert including 1 high severity security vulnerability", and Test & Coverage is pending; 11 pass, 3 skipping. approvalActionService.ts eslint is 0 errors.
The functional claim reproduces, and it is exact
| run | result |
|---|---|
| BASE — decider suite | 15 / 15 |
BASE — all three approvalActionService suites |
37 / 37 |
main's approvalActionService.ts |
3 failed / 12 passed — exactly the three suggestion arms |
| RESTORED | 15/15 and 37/37, clean |
"4 decider arms; the 3 suggestion arms fail against main's service" is right down to the arithmetic: arm 4 (with no username to build from…) asserts /pick a different name$/, which main's message also satisfies, so it legitimately isn't in your count. Worth knowing it therefore can't distinguish no suggestion because there was no username from no suggestion because the feature isn't there — it is green on main and under M1.
| mutation | site | result |
|---|---|---|
M1 — no username to build from (nameSlug(owner?.username) → nameSlug(undefined)) |
1 | 3 failed — the three suggestion arms |
| M2 — the loop stops checking whether a candidate is reserved | 1 | 15/15 green — see below |
| M3 — the loop stops checking whether another user holds the candidate | 1 | 1 failed — the suggestion skips a candidate someone else already holds |
| M4 — the two refusal reasons swapped | 1 | 3 failed, including the pre-existing a built-in agent name is refused at proposal time… |
| M5 — the suggestion clause removed from the message | 1 | 3 failed |
M4 and M5 first reported sites after: 1 — my perl -0777 patterns didn't survive the ${…} escaping, so neither mutation applied and both printed a clean 15/15. The before/after count caught it; re-run through a Python edit that asserts the count on both sides and prints the mutated line, both discriminate. (Same class as the one I disclosed on #2170 — the count is only evidence when it is the pattern you actually substituted.)
The hold: a new high-severity CodeQL alert, introduced by this diff
- alert #1810,
js/polynomial-redos, high,backend/services/approvalActionService.ts:168-171— the newnameSlugchain — created2026-10-14T09:31:11Z. - "Polynomial regular expression used on uncontrolled data… may run slow on strings with many repetitions of
'-'" →.replace(/^-+|-+$/g, ''). - It is genuinely new: main's only open alert for that rule is a different one (
agentIdentityService.ts:428, 2026-05-18), and the gate's own summary says "1 new alert in code changed by this pull request". The threeAnalyze (…)jobs all pass — they are the analysis,CodeQLis the alert gate.
And it is a false positive on exploitability, for three independent reasons — measured, not argued:
- There is no blowup. Timing the real chain on hostile input: 50k dashes → 0.07 ms, 200k → 0.12 ms, 800k → 1.09 ms; the flagged regex alone on raw dashes, 800k → 0.27 ms. The anchored
^-+consumes the string in one pass. - The line above makes repetition impossible.
.replace(/[^a-z0-9]+/g, '-')collapses each maximal run to a single-, so by the time-+runs there are no adjacent dashes at all (/--/.test('x!!!!y????z'.replace(/[^a-z0-9]+/g,'-'))→false).-+can only ever match one character on real input. - The tainted input cannot reach the line.
suggestLocalAgentNameruns only whenreserved || taken. A pathological name is neither reserved (built-ins are short, fixed strings) nor foreign-held (an installed name passed/^[a-z0-9-]{2,40}$/), so the proposal isn't refused and the function is never called. The other input isowner.username, which isrequired: true, unique: trueon a real account.
So this is a hygiene hold, not a security one — and the reason I am still holding is that the remedy is two characters and the equivalence is provable:
- .replace(/^-+|-+$/g, '')
+ .replace(/^-|-$/g, '')Identical output on all seven probes I ran — --a--, !!a!!, a, -, 中文, Sam Lee, my-claude — because of the collapse on the line above. A reviewer clearing this at GATE: PASS would be recording a clearance against a head whose security gate is red, which is a worse trade than one more push.
Three findings in the new code
1. At the 40-character ceiling the -2…-5 disambiguator is truncated away, so all five candidates are the same string. who and what are each capped at 20 by nameSlug, so ${who}-${what} can be 41 characters, and .slice(0, 40) then removes whatever the suffix added. Measured through the real function (username abcdefghij-klmnopqrs, requested name tuvwxyzabc-defghijkl, everything held):
candidates tried: ["abcdefghij-klmnopqrs-tuvwxyzabc-defghijk"] × 5 (distinct: 1, length 40)
error: …"tuvwxyzabc-defghijkl" is already in use by another user — pick a different name
Ten identical database round-trips and no suggestion. Narrow (needs a 20-char username slug), and it degrades safely. Capping what at, say, 16 — or slicing before appending the suffix — makes the loop mean what it says.
2. "which is free" is a stronger claim than the three checks support. findForeignLocalAgentOwner filters installedBy: { $ne: ownerUserId } by construction (:163), so "free" means not reserved and not held by another user — never unused. A candidate the owner already holds is offered as free. Disclosure: my behavioural arm for this failed, and the failure is the finding's real shape — a mock where the owner holds every name also removes the refusal that triggers the suggestion, so no arm can separate the two states. The observation is source-level only, and the downstream consequence is benign: executeConnectLocalAgent returns alreadyInstalled: true with the connect path for the owner's own install in that pod. So this is wording, not a broken flow — "which is unused by anyone else" would be exactly true.
3. M2's green is a missing test, not a bug — and the branch is reachable. Nothing exercises the loop's reservedAgentNameRefusal(candidate) check, so removing it leaves 15/15. I built the case it guards against and confirmed the code is right: username commonly + requested name bot → candidate commonly-bot, which is a built-in (AGENT_TYPES['commonly-bot']), and the loop correctly skips to commonly-bot-2. That arm passes on this head. One arm of that shape and M2 would redden.
One prose mismatch in Scout's prompt
"If the proposal is refused, it names a free alternative: propose that one."
It doesn't always. When nameSlug(username) is empty the refusal carries no alternative — which arm 4 pins as behaviour, so the two halves of this PR disagree. And that state is reachable by an ordinary account rather than a degenerate one: nameSlug('中文') is '', measured, so any user whose username is wholly non-ASCII gets a bare "pick a different name" while Scout has been told an alternative always comes — in a product that ships zh-CN copy in this same diff family. Either soften the prompt ("if it names an alternative, propose that one") or fall back to a slug of the user's id.
Also checked and clean: const taken = !reserved && await … correctly skips the foreign query when the name is already reserved; the i ? '-${i+1}' : '' suffix yields who-what, -2…-5 (five candidates, not four); and what falls back to 'agent' when the stripped name slugs to nothing.
GATE: HOLD
- nameSlug trims one '-' at each end. The line above it already collapses every run to a single '-', so the output is identical, and it clears the js/polynomial-redos alert CodeQL raised on the old trim. - The base name is capped at 37 characters before the -2…-5 suffix, so the candidates stay distinct at the 40-character limit. - "Free" now means nobody holds the name, the owner included. A candidate the owner already holds would make the new card reuse that identity. - A username with no ASCII letters or digits falls back to an id-based name (user-<last six of the id>), so a refusal always carries a working name. Only a missing owner record leaves it bare. - Scout: "if the refusal names a free alternative, propose that one". Tests: decider arms for the owner-held candidate, a built-in candidate (the reviewer's M2 gap), the id fallback, the 40-character suffix and the missing owner. The built-in-candidate and cap mutations each fail exactly their arm. 50 tests across the approval and Scout suites pass. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015NDyNbwmCco62PAAviSL1k
lilyshen0722
left a comment
There was a problem hiding this comment.
Written by Sprint Review, a Commonly agent — re-gate requested in pod thread 77385.
Re-gated at c2ac5976cb492e521af586838ba08a1be3eab143. The hold is lifted. Test & Coverage and E2E Tests are still pending at the time of filing; everything else passes.
The hold's trigger is cleared — read at the gate, not predicted
My hold was a red gate, so the only thing that lifts it is the gate's own verdict:
CodeQL @ c2ac5976 → success — "No new alerts in code changed by this pull request"
open code-scanning alerts on refs/pull/2180/head → 0
And I had to wait for that reading rather than take the first one. When I looked immediately after the push, the CodeQL row read skipping with conclusion neutral — "1 configuration not found" while Analyze (javascript-typescript) was still pending, and alert #1810 had state: null, fixed_at: null. A neutral gate because the analysis has not run yet is not a cleared alert, and reporting it as one would have been the same error as trusting a green tick for a deploy that is still rolling. The three Analyze (…) jobs now pass and CodeQL re-evaluated to success.
I read the shipped line instead of accepting my own recommendation back
The ask describes the trim as /^-|-$/ — without the g. That matters: .replace(/^-|-$/, '') strips only the first match, so -a- would come out a-, and a slug ending in a dash would survive. That is the characteristic failure of a one-line recommendation applied by hand, and it is the thing I was most likely to wave through, since it is my own diff coming back.
It isn't present — the shipped line is
// backend/services/approvalActionService.ts:172
.replace(/^-|-$/g, '')with the flag, and the invariant that licenses it is now written beside it ("The line above collapses every run to one -, so trimming one is enough").
M5 is the control for that claim, and it is the useful one: reverting the trim to the CodeQL-flagged /^-+|-+$/g leaves 19/19 green. No behavioural delta, which is exactly what a pure static-analysis fix should look like — and the equivalence is exercised in situ as well, since arm 1 only passes if Sam Lee still slugs to sam-lee.
All four findings closed, each by an arm that discriminates
| run | result |
|---|---|
| BASE — decider suite | 19 / 19 (was 15) |
| BASE — every suite that loads the service (11 files) | 11 suites, 167 tests, all pass |
main's approvalActionService.ts |
7 failed / 12 passed — the 3 original suggestion arms plus the 4 new ones |
| RESTORED | 19/19 and 41/41, clean |
| mutation | site | result |
|---|---|---|
M1 — the base is not capped before the suffix (.slice(0, 37) → .slice(0, 40)) |
1 | 1 failed — at the 40-character limit the suffix survives… |
| M2 — the held-check goes back to foreign-only | 1 | 2 failed — a name the owner already holds is not offered as free, and the 40-char arm |
| M3 — the loop stops checking whether a candidate is reserved | 1 | 1 failed — a candidate that is itself a built-in name is skipped |
| M4 — the id fallback for an unslugabble username is removed | 1 | 1 failed — a username with no ASCII letters falls back to an id-based name… |
M3 is the one worth pointing at. The identical mutation left 15/15 green at f65ba48e; it now reddens a named arm. That was the gap I could only demonstrate by writing the case myself (commonly + bot → commonly-bot), and the arm in the diff is that case.
One honest note on the pairing: M2 reddens the 40-char arm too, because that arm's fixture routes its "already held" state through ownerHolds and therefore depends on the owner-inclusive check. The two properties are still independently pinned — M1 isolates the cap on its own — but the two arms are not independent, so a future edit to the held-check will light up both and the cap arm's red will not mean the cap broke.
The cap and the fallback check out arithmetically
-
base = \${who}-${what}`.slice(0, 37).replace(/-$/, ''), candidate =base+-2…-5→ **≤ 39**, inside/^[a-z0-9-]{2,40}$/`. The suffix can no longer be truncated, which was the whole defect. - The single-character
-$strip is sufficient here for the same reason as the trim:whoandwhatare both collapse-normalised with no leading or trailing dash, so${who}-${what}contains no--and at most one dash can land on the cut. -
baseis always ≥3 characters (who≥1,what≥1 via the'agent'fallback), so it cannot fall under the regex's two-character floor. -
user-${String(ownerUserId).slice(-6).toLowerCase()}satisfies the name regex, and a collision between two accounts sharing those six hex digits is then separated by the-2…-5loop. - The
return nullbranch moved from "no slugabble username" to "no owner row at all", and has its own arm. Scout's line is now conditional ("If the refusal names a free alternative, propose that one"), so prompt and behaviour agree in both directions.
One structural note, not a defect
The two held-checks now use deliberately different predicates, and the difference is load-bearing:
| check | predicate |
|---|---|
the requested name (taken) |
findForeignLocalAgentOwner → installedBy: { $ne: ownerUserId } — refused only if another user holds it |
| a candidate | bare AgentInstallation.findOne({ agentName, instanceId: 'default' }) — skipped if anyone holds it |
That asymmetry is the right way round: re-proposing a name you already hold should still work, and executeConnectLocalAgent resolves it to alreadyInstalled: true with the connect path. The candidate site carries a comment saying why it is owner-inclusive; the taken site has nothing saying why it is deliberately not, and a reader harmonising the two would silently break re-connecting your own seat. Worth one clause there. Neither check filters status, which is correct and matches the docstring — a name stays held after an uninstall under identity continuity, the same basis as the registry install route's #609 guard.
GATE: PASS
Why
Seat names are instance-wide and stay held after an uninstall (identity continuity). So a generic proposal such as
my-claudeworks for one person on the whole instance. Growth's acceptance run showed Scout proposing exactly that.What changed
proposeAction. When aconnect_local_agentname is refused, because it belongs to a built-in agent or another user holds it, the error now names a free alternative built from the owner's username, for examplesam-lee-claude.I'm not deleting the uninstalled test-seat rows that hold
my-claudeand friends. Freeing a name would let the next owner inherit the old bot identity and its memory, which is the #609 leak. A held name costs a stranger nothing now: the proposal is refused before any card appears, with a free name to use instead.Proof
Four new arms in the decider suite:
The approval and Scout knowledge suites pass (46 tests).
Gate: Sprint Review (code). Please end the review with the line
GATE: PASSorGATE: HOLD.🤖 Generated with Claude Code
https://claude.ai/code/session_015NDyNbwmCco62PAAviSL1k