← Back to Pull requests

People access patterns on tee-admin: typeahead, offices, ecclesia directory, CARD #278

Open
unknown opened this pull request with 635 lines diff across 7 files
View on GitHub
unknown unknown commented on Oct 18, 2026 02:06 UTC
Author

Closes #275. Phase 2 step 0 of epic #270 (ADR-0006 §8, plan §7).

What


New derived projection items on tee-admin. They are sparse entries on the existing GSIs; no GSI is added. Code lives in packages/app/provider/dynamodb/people-index/: keys.ts derives (pure), projections.ts writes, reader.ts reads.

| Pattern | Item / index entry | Only writer |
|---|---|---|
| 3 typeahead | PERSON#<id> / NAMETOK#<token>, gsi3 NAMEPFX#ALL#<2 letters> | personRepository |
| 4 everyone / by ecclesia, 10 BatchGet | PERSON#<id> / CARD, gsi4 PEOPLE#ALL, gsi2 ECCPEOPLE#<ecclesiaId> | personRepository |
| 7 stable id, 9 all ecclesias | ECCLESIA_ID#<id> / ECCLESIA (points at the ECCLESIA key), gsi2 ECCLESIAS; RB-email sign-in entry on gsi1 RBEMAIL# | locations.ts |
| 8/11 RB office | ECCLESIA_ID#<id> / OFFICE#RB#<pid> + PERSON#<pid> / OFFICE#<id>#RB | locations.ts |
| 8/11/12 REP office | … OFFICE#REP#<pid> + … OFFICE#<id>#REP | personRepository |

  • Offices are references only: they hold no copied name or email.

  • The stable ecclesia id is the slug of the name at creation. It is stored as ecclesiaId and carried across renames, where the alias is re-pointed.
  • One writer, always in sync


  • PersonRepository re-derives a person's projections after every write to a PROFILE, EMAIL# or PHONE# item. That covers the named methods and the base put/update/delete, so the direct personRepository.update(...) callers (the SES cron, contact.ts, scripts) are covered too.

  • locations.ts does the same on ecclesia create, update, rename and delete.

  • Each refresh reads the source with a consistent read, applies only the diff, and refuses any non-projection key.

  • A refresh never fails the source write. A refresh that does fail is repaired by the next write or by the rebuild script.

  • Kill switch: PEOPLE_INDEX_WRITES=off.
  • Scans removed from request paths


    Each of these switches to Query/BatchGet once the backfill marker PEOPLE_INDEX#META/BUILD exists. Before that, the legacy read stays in charge, so a deploy cannot show a short list.

    | Was | Now |
    |---|---|
    | app/api/people/route.ts:94 listAll and :104 getAllPhonesByPerson (two full Scans) | one gsi4 Query of CARDs |
    | app/api/people/guests/route.ts:70 listAll | the same |
    | utils/dynamodb/locations.ts:346 (picker/search), :403 (by country), :465 getAllEcclesia | directory Query plus BatchGet |
    | locations.ts:680 RB Scan in sign-in (auth.ts:134,256,341) | gsi1 RBEMAIL# Query, behind the people_index_signin flag (default off) |
    | person-repository.ts count() and getByGoogleId() | deleted (no callers) |

    Bug found on the way: getAllEcclesia and the RB lookup were single-page Scans. Today getAllEcclesia returns 35 of the 39 ecclesias, and the RB lookup can miss in the same way. The index fixes both.

    Not changed (reported on #270)


  • Sends and crons: sync-ses-contacts, the exhorter heads-up, listInterEcclesiaReps.

  • rb-service.findCurrentRB and the set-role Scans.

  • credentials-users.ts (auth cutover is Phase 2 step 3).

  • The legacy import routes.
  • Backfill


    scripts/rebuild-people-projections.ts:
  • Dry run by default.

  • --apply requires --after-deploy.

  • Backs up PERSON#, ECCLESIA and ECCLESIA_ID# items to s3://tee-admin-backups/backups/<date>-people-index-backfill/ before writing.

  • Writes only projection items, through the same writer the app uses.

  • Re-verifies that 0 differences remain, then writes the marker.
  • Dry run against prod, read-only:

    | | count |
    |---|---|
    | Source: PERSON# partitions | 185 |
    | Source: PROFILEs | 180 |
    | Source: ECCLESIA items | 39 |
    | Existing projection items | 0 |
    | Planned: CARD | 180 put |
    | Planned: NAMETOK | 300 put |
    | Planned: REP office refs | 70 put |
    | Planned: RB office refs | 10 put |
    | Planned: ecclesia directory | 39 put |
    | Deletes | 0 |
    | Ecclesia id collisions | 0 |

    The run happens only after this merges and deploys (see EXTERNAL_CHANGES.md).

    Tests


  • tests/people-index-keys.test.ts: derivation, the key guard, and diff idempotency.

  • tests/people-index-sync.test.ts: uses an in-memory DynamoDB and the real PersonRepository and locations.ts write paths.

  • - Create, rename, phone/email change, bounce, base update/delete, REP move/clear, RB assign/clear and ecclesia rename/delete keep the projections in sync.
    - A re-run is a no-op and writes no source item.
    - The indexed reads make no Scan.
    - The directory loader returns the same people from the index as from the Scan.
  • Full suite: 78 failures before and 78 after. All 78 are pre-existing, in 11 files of legacy auth tests that also fail on main. The PR adds 20 new passing tests.

  • root yarn lint: no new errors. typecheck: pass. next build: pass.
  • Known limitation


    Two concurrent writes to the same person can race their refreshes. The next write or a rebuild repairs this. People change rarely.

    🤖 Generated with Claude Code

    https://claude.ai/code/session_013tgTQCXN3wSxnLue5J49Bs

    Diff: 635 lines (+476 / -159) across 7 files Reviewer: claude[bot] Review duration: 17m
    All Vouch review confidence checks passed
    Residual risk 0.29 = Change Risk (0.50) × (1 − Review Confidence (0.43)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.50 · 635 lines diff across 7 files
    0.50
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    42%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.386
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #278"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 43.0% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 50.4% (MEDIUM) · Higher = larger blast radius
    50.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 43.0% · Lower = rushed or shallow review
    43.0%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 28.8% · Safe to merge
    28.8%