Skip to content

Fix duplicate migration version 039 and add CI check - #382

Merged
bokelley merged 2 commits into
mainfrom
bokelley/fix-worktree-setup
Dec 29, 2025
Merged

bokelley merged 2 commits into
mainfrom
bokelley/fix-worktree-setup

Conversation

@bokelley

Copy link
Copy Markdown
Contributor

Summary

  • Fix duplicate migration version 039 that was causing fresh database setup to fail
  • Add CI test to prevent duplicate migration versions in the future

Problem

Two migrations had the same version number (039):

This caused migration failures with "duplicate key value violates unique constraint" on fresh databases.

Production State

Checked prod via fly ssh:

  • Has versions 37/38 recorded as email_tracking/preferences (from old numbering before renaming)
  • Has version 39 recorded as member_engagement
  • Never got working_group_leaders (would have failed with duplicate key)
  • Missing working_group_leaders table, still has old chair_user_id/vice_chair_user_id columns

Fix

  1. Rename duplicate migration: 039_working_group_leaders.sql → 047_working_group_leaders.sql
  2. Add CI test: New tests/migration-validation.test.js checks for:
    • Valid migration filename pattern (NNN_description.sql)
    • No duplicate version numbers
    • Valid positive integer versions

The working_group_leaders migration is idempotent (uses IF NOT EXISTS, IF EXISTS, ON CONFLICT DO NOTHING), so it will safely apply to prod as version 47.

Test plan

  • Fresh database migrations pass locally
  • Migration validation test passes
  • All existing tests pass

🤖 Generated with Claude Code

bokelley and others added 2 commits December 29, 2025 08:32
Two migrations had the same version number (039):
- 039_member_engagement.sql (PR #376)
- 039_working_group_leaders.sql (PR #377)

This caused migration failures on fresh databases (including new worktrees).

Production state:
- Has versions 37/38 as email_tracking/preferences (from old numbering)
- Has version 39 as member_engagement
- Never got working_group_leaders (would have failed with duplicate key)

Fix:
- Rename 039_working_group_leaders.sql → 047_working_group_leaders.sql
- Add CI test to prevent duplicate migration versions in the future

The working_group_leaders migration is idempotent (uses IF NOT EXISTS,
IF EXISTS, ON CONFLICT DO NOTHING), so it will safely apply to prod
as version 47.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Internal fix that doesn't affect the protocol specification.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@bokelley
bokelley merged commit 283d415 into main Dec 29, 2025
bokelley added a commit that referenced this pull request May 19, 2026
… undefined" (#4768)

* fix(certification): credential recipient name no longer becomes "undefined undefined"

When a learner earns a credential before WorkOS has populated their
first_name/last_name, naive `${first} ${last}` interpolation sent the
literal string "undefined undefined" to Certifier (escalation #382,
Tom Hespos). The existing `.trim() || email` fallback in the backfill
path didn't catch it either, because "undefined undefined".trim() is
still truthy.

- Introduce `buildRecipientName({first_name?, last_name?, email})` that
  trims each field independently and falls back to email when both are
  missing/empty.
- Use it in both issuance call sites: Addie's `issueCertifierBadge`
  and the admin backfill route.
- Add `updateCredential(id, {recipient,...})` wrapping Certifier
  PATCH /credentials/{id} for after-the-fact corrections.
- Add `server/src/scripts/repair-credential-recipient-names.ts` —
  dry-run audit + repair script that finds credentials with
  "undefined"/"null" in the remote name (and email-only fallbacks
  that now have real name data to substitute) and PATCHes Certifier.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* chore: add empty changeset for credential recipient name fix

Server-only bugfix, no published package version change needed.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* ci(broken-links): skip placeholder URLs and bump owned-links budget to 10m

The 5-minute step timeout on `check:owned-links` is too tight when
agenticadvertising.org is slow — multiple unrelated branches started
hitting the 5m wall this morning while main passes in <10s when the
site is healthy. Two surgical fixes:

- Filter URLs containing `{` or `}` in `check-owned-links.js`. These
  are documentation placeholders like `/agents/{url-encoded-agent-url}/badge`
  that never resolve to a real route; the script was burning the full
  per-URL retry budget (3 retries × 10s × HEAD+GET) on guaranteed
  timeouts.
- Bump the workflow step timeout from 5 to 10 minutes so a slow-but-
  healthy upstream doesn't tip the job over.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
bokelley added a commit that referenced this pull request May 19, 2026
…ause) (#4781)

* fix(signup): capture first/last name reliably so credentials never read "undefined undefined"

Closes the gap behind escalation #382 (Tom Hespos plus 12 other learners
with empty names on prod credentials):

1. Auth callback now applies the same Slack-name fallback the WorkOS
   webhook already had. 8 of the 11 nameless users on prod have a
   slack_user_mappings.slack_real_name we can split into first/last —
   next sign-in silently backfills them.

2. Onboarding gates on a name. When callback fallbacks still produce
   nothing (no Slack mapping, no WorkOS profile), /onboarding.html
   shows a "What should we call you?" step before the rest of the
   flow. Submits to the existing PUT /api/me/name.

3. PUT /api/me/name pushes back to WorkOS. Previously we wrote only
   to users + organization_memberships; WorkOS itself stayed NULL,
   which meant the next webhook could overwrite us with empty values.

The Slack-fallback cascade is extracted into a shared util so the
auth callback and the user.updated webhook can't drift.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* fix(signup): backfill users.first_name/last_name at Slack-link time

Closes the residual gap from the OAuth-callback Slack fallback: admin
links and email-based auto-links happen out-of-band from the OAuth
callback, so a learner can be Slack-linked, earn a credential via Sage,
and never sign in via OAuth in between. mapUser now runs the same
cascade inline on every successful link.

- Pure DB operation; no cross-layer dependency on the WorkOS client
- COALESCE preserves user-set names (won't overwrite anything they
  set via /api/me/name)
- 6 integration tests cover: real_name fill, display_name fallback,
  single-word names, existing-name preservation, partial fills,
  no-op when Slack has nothing

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* test: use correct SlackMappingSource enum in name-backfill integration test

'admin' isn't a valid mapping_source — the type is 'email_auto' |
'manual_admin' | 'user_claimed'. Check constraint rejected all 6 inserts
in CI. No production code affected.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* review: address code+security review findings on PR #4781

Code review (must-fix):
- Extract splitFullName helper used by both resolveUserNameWithFallbacks
  and SlackDatabase.mapUser. mapUser previously used indexOf(' ') while
  the helper used split(/\s+/); double-space / tab inputs diverged.
- Onboarding gate now sets currentUser optimistically + a
  nameJustCaptured guard before re-entering init(). Prevents the gate
  from re-firing if /api/me momentarily still returns null first_name
  after the PUT (cache, read-after-write race).
- Drop firstName/lastName PII from the PUT /api/me/name info log line;
  userId is sufficient to correlate.

Security review (defense-in-depth):
- Strip C0/C1 controls + Unicode direction/format characters (RTL-
  override spoofing, ZWSP, BOM) from all name inputs. Centralized in a
  sanitizeName helper used by splitFullName (Slack paths) and the
  PUT /api/me/name handler.
- Cap each name half at 255 chars (matches users table column).
- Reject overlong raw input before sanitizing so the user sees a clear
  422 instead of silent truncation.

13 new unit tests for sanitizeName + splitFullName.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
bokelley added a commit that referenced this pull request May 19, 2026
closes #4782) (#4799)

* fix(certification): block credential issuance when learner has no name (#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]>

* review: address code review findings on PR #4799

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]>

---------

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.

1 participant