Skip to content

fix(certification): block credential issuance when learner has no name (closes #4782) - #4799

Merged
bokelley merged 2 commits into
mainfrom
bokelley/credential-name-required-gate
May 19, 2026
Merged

bokelley merged 2 commits into
mainfrom
bokelley/credential-name-required-gate

Conversation

@bokelley

Copy link
Copy Markdown
Contributor

Summary

Closes #4782 — the credential-issuance safety net behind escalation #382. Even after the auth-callback Slack fallback and onboarding gate in #4781, an exotic auth path could still drop a learner at credential-issuance time without a name. Today that produces an email-on-certificate ([email protected]); now it produces a one-turn conversational recovery.

Pattern

Hard block + Sage conversational prompt — option (1) from the issue. Fits the "Sage tools just work" pattern from feedback memory (Sage handles errors conversationally, doesn't announce tool names).

What's new

Change Where
NAME_REQUIRED_MARKER constant — exported, referenced from all three sites (sentinel, warning line, Sage rule) server/src/addie/mcp/certification-tools.ts
issueCertifierBadge returns the marker (no Certifier call) when users.first_name is empty certification-tools.ts:428
checkAndFormatCredentials retries previously-deferred issuances on every call — that's the post-set_my_name finalize path certification-tools.ts:535
set_my_name learner-self tool — wraps the same write-through-to-WorkOS path as the onboarding form server/src/addie/mcp/member-tools.ts
check_credentials tool — runs an award/issue pass on demand (previously the only triggers were complete_certification_module / exam) certification-tools.ts
Sage prompt rule "Credential name recovery" buildCertificationContext

Flow

  1. Learner finishes a module → complete_certification_module → checkAndFormatCredentials → issueCertifierBadge detects no name → returns NAME_REQUIRED_MARKER
  2. checkAndFormatCredentials emits a warning line containing the marker. Share links + specialist Slack notification are deferred.
  3. Sage sees the marker, asks the learner one short turn for their name
  4. Sage calls set_my_name with what they said
  5. Sage calls check_credentials — checkAndFormatCredentials picks up the deferred issuance via the new "already-awarded-but-unissued" path, calls Certifier with the real name, returns share links + fires specialist notification

Test plan

  • tests/unit/credential-name-required-marker.test.ts — keeps the marker string stable across the sentinel + warning + Sage rule (drift would silently break recovery)
  • npm run typecheck clean
  • Precommit (test:unit + dynamic-imports + callapi-state-change + typecheck) green
  • Manual: clear a test user's name, complete a module, observe NAME_REQUIRED in Sage's reply, set name, re-trigger, certificate finalizes
  • Manual: confirm set_my_name write-through hits users + organization_memberships + WorkOS

Related

🤖 Generated with Claude Code

bokelley and others added 2 commits May 19, 2026 10:06
#4782)

Closes #4782 — the safety net behind escalation #382. Even after the
auth-callback Slack fallback and onboarding gate in #4781, an exotic
auth path could still drop a learner at credential-issuance time without
a name. Today that produced an email-on-certificate; now it produces a
one-turn conversational recovery.

- issueCertifierBadge returns a NAME_REQUIRED sentinel (without calling
  Certifier) when users.first_name is empty. The credential row is still
  awarded in user_credentials; only Certifier-side issuance is deferred.
- checkAndFormatCredentials now also retries previously-deferred issuances
  on every call, so the post-set_my_name retry finalizes the certificate.
- set_my_name (new learner-self tool in member-tools) wraps the same
  write-through-to-WorkOS path as the onboarding form. Sage's prompt rule
  ("Credential name recovery") tells her to ask for first+last on seeing
  the marker, call set_my_name, then check_credentials to finalize.
- check_credentials (new tool) runs an award/issue pass on demand. Used
  by the recovery flow and safe for "did I earn anything new?" prompts.
- NAME_REQUIRED_MARKER constant exported and referenced from all three
  sites (sentinel, warning line, Sage rule) so they can't drift — guarded
  by a unit test.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Code reviewer (must-fix):
- issueCertifierBadge now reads name via resolveUserNameWithFallbacks
  with the live DB pool, not the closure-bound memberContext that goes
  stale after set_my_name writes through. Closes the loop where Sage
  set the name but check_credentials still saw the gate fire.
- Deferred-issuance retry in checkAndFormatCredentials is bounded to a
  24-hour window so we never re-issue a legitimately-issued older
  credential whose certifier_credential_id was nulled out-of-band.

Code reviewer (should-fix):
- Move "Credential earned!" line *after* the gate check so a gated
  attempt no longer announces the credential before deferring.
- Dedupe toProcess via Set (awarded + deferred could overlap on a race
  between checkAndAwardCredentials and getUserCredentials).
- Narrow IssueResult union to literal 'NAME_REQUIRED' instead of
  typeof-the-constant (which collapsed to plain string).
- Marker test now also pins the source-reference count so a refactor
  that drops one of the three load-bearing sites fails loud.

Security reviewer (should-fix):
- Rate-limit set_my_name (per-user default cap: 60/10min) — bounds
  WorkOS updateUser calls.
- Rate-limit check_credentials (same cap) — bounds fan-out to Certifier
  issuance API.

Cache-invalidation scope: invalidateMemberContextCache() with no arg
clears the whole cache. This matches the pre-existing PUT /api/me/name
behavior in http.ts:7400 — narrowing both is a separate fix.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@bokelley
bokelley merged commit 51d9255 into main May 19, 2026
13 checks passed
@bokelley
bokelley deleted the bokelley/credential-name-required-gate branch May 19, 2026 17:21
bokelley added a commit that referenced this pull request May 20, 2026
…repair (#4882)

The repair script in server/src/scripts/repair-credential-recipient-names.ts
now accepts a flag that skips credentials whose backfill value would be the
user's email AND the email domain is a personal-email provider (gmail,
hotmail, yahoo, icloud, etc.).

Avoids surfacing personal-email PII on a publicly-shareable credential
artifact. Corporate-email users still get repaired — their email is already
public on business cards / LinkedIn. Personal-email users wait for the
NAME_REQUIRED gate + set_my_name recovery flow (#4799) to populate their
name in users.first_name; re-running the backfill then picks them up.

Closes the cleanup loop for #4753 and #4760. Tom Hespos's two credentials
in #4760 are unaffected — we have his real name in the users table, so the
script writes "Tom Hespos" not his email.

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
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.

Gate credential issuance when learner has no first/last name

1 participant