[PR #158] [MERGED] fix: empty-string handle never falls back in ensure() #273

Closed
opened 2026-02-15 17:16:37 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/openclaw/clawhub/pull/158
Author: @adlai88
Created: 2/6/2026
Status: Merged
Merged: 2/6/2026
Merged by: @steipete

Base: mainHead: fix/empty-handle-fallback


📝 Commits (2)

  • 06f116a fix: handle empty-string handle in ensure() fallback
  • 55060eb fix: backfill empty handles in ensure (#158) (thanks @adlai88)

📊 Changes

2 files changed (+2 additions, -1 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 convex/users.ts (+1 -1)

📄 Description

Summary

  • Bug: ensure() in convex/users.ts uses ?? (nullish coalescing) to derive a handle fallback from user.name or user.email. But ?? treats "" as a valid value, so users with handle="" never get a fallback — they're stuck with an empty handle permanently.
  • Fix: Change ?? to || so empty strings fall through to the next candidate.
- const handle = user.handle ?? user.name ?? user.email?.split('@')[0]
+ const handle = user.handle || user.name || user.email?.split('@')[0]

Who's affected

Any user whose handle field is "" (empty string) rather than null/undefined — e.g. accounts created early or affected by migration issues. The downstream check if (!user.handle && handle) correctly detects the empty handle, but handle itself is already "" from the ?? chain, so the update never fires.

Test plan

  • Verify user with handle="" gets a derived handle on next ensure() call
  • Verify user with a valid handle is unaffected (no change)
  • Verify user with handle=null still gets fallback (existing behavior, unchanged)

Greptile Overview

Greptile Summary

  • Fixes ensure() user handle derivation to treat empty string handles as missing by switching from ?? to ||.
  • This allows users with handle="" to fall back to user.name or email local-part and get patched.
  • Change is localized to the Convex users mutation that normalizes/patches missing profile fields on login/ensure.

Confidence Score: 4/5

  • This PR is close to safe to merge, but there is a small correctness risk around patching displayName to an undefined value when no fallback handle can be derived.
  • The change is tiny and addresses a real bug for empty-string handles, but it also slightly changes truthiness behavior; in at least one reachable case (no handle/name/email) handle becomes undefined and the mutation currently patches displayName unconditionally when missing.
  • convex/users.ts

(2/5) Greptile learns from your feedback when you react with thumbs up/down!


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/openclaw/clawhub/pull/158 **Author:** [@adlai88](https://github.com/adlai88) **Created:** 2/6/2026 **Status:** ✅ Merged **Merged:** 2/6/2026 **Merged by:** [@steipete](https://github.com/steipete) **Base:** `main` ← **Head:** `fix/empty-handle-fallback` --- ### 📝 Commits (2) - [`06f116a`](https://github.com/openclaw/clawhub/commit/06f116a990b7a058b75ef4a97e701277d8b2f62b) fix: handle empty-string handle in ensure() fallback - [`55060eb`](https://github.com/openclaw/clawhub/commit/55060eb3a6362b7c7607aa5c84ce70fabc4ed05d) fix: backfill empty handles in ensure (#158) (thanks @adlai88) ### 📊 Changes **2 files changed** (+2 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `convex/users.ts` (+1 -1) </details> ### 📄 Description ## Summary - **Bug**: `ensure()` in `convex/users.ts` uses `??` (nullish coalescing) to derive a handle fallback from `user.name` or `user.email`. But `??` treats `""` as a valid value, so users with `handle=""` never get a fallback — they're stuck with an empty handle permanently. - **Fix**: Change `??` to `||` so empty strings fall through to the next candidate. ```diff - const handle = user.handle ?? user.name ?? user.email?.split('@')[0] + const handle = user.handle || user.name || user.email?.split('@')[0] ``` ## Who's affected Any user whose `handle` field is `""` (empty string) rather than `null`/`undefined` — e.g. accounts created early or affected by migration issues. The downstream check `if (!user.handle && handle)` correctly detects the empty handle, but `handle` itself is already `""` from the `??` chain, so the update never fires. ## Test plan - [ ] Verify user with `handle=""` gets a derived handle on next `ensure()` call - [ ] Verify user with a valid handle is unaffected (no change) - [ ] Verify user with `handle=null` still gets fallback (existing behavior, unchanged) <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> - Fixes `ensure()` user handle derivation to treat empty string handles as missing by switching from `??` to `||`. - This allows users with `handle=""` to fall back to `user.name` or email local-part and get patched. - Change is localized to the Convex `users` mutation that normalizes/patches missing profile fields on login/ensure. <h3>Confidence Score: 4/5</h3> - This PR is close to safe to merge, but there is a small correctness risk around patching `displayName` to an undefined value when no fallback handle can be derived. - The change is tiny and addresses a real bug for empty-string handles, but it also slightly changes truthiness behavior; in at least one reachable case (no handle/name/email) `handle` becomes undefined and the mutation currently patches `displayName` unconditionally when missing. - convex/users.ts <!-- greptile_other_comments_section --> <sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub> <!-- /greptile_comment --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-15 17:16:37 -05:00
yindo closed this issue 2026-02-15 17:16:37 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: openclaw/clawhub#273