Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/build-mobile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ jobs:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- uses: ./.github/actions/setup-node-pnpm
- name: Verify dependencies match Expo SDK
env:
EXPO_OFFLINE: "1"
run: cd packages/mobile && pnpm expo install --check
- uses: ./.github/actions/load-infisical-secrets
with:
Expand Down
30 changes: 30 additions & 0 deletions docs/production-incident-baseline.md
Original file line number Diff line number Diff line change
Expand Up @@ -15045,3 +15045,33 @@ Drizzle schema and runtime Zod schemas. Findings and remediations:
- **Remaining risk / follow-up:** Confirm the PR's Actionlint and test checks pass,
then verify the next production deployment restores both consumers only after
CDC setup succeeds.

## 2026-07-22 — Kaya Climbing Attempts Matched Sends 1:1

- **Status:** Root cause fixed and validated locally; production deployment and
historical backfill are pending.
- **Symptoms:** Climbing volume by grade displayed 52 attempts and 52 sends, with
identical attempt and send counts for every grade.
- **User impact:** The climbing dashboard understated attempts and made send
rates appear to be 100%.
- **Evidence:** Kaya CSV rows preserve a numeric `attempts` value, but the importer
previously stored that value only in the raw payload while creating one sent
climbing entry per CSV row. The repository then used row count as its attempt
total; see the [Kaya importer](../src/providers/kaya/import.ts) and
[climbing repository](../packages/server/src/repositories/climbing-repository.ts).
- **Root cause:** The canonical climbing model represented a sent ascent row but
had no canonical attempt-count field, so server aggregation treated every sent
row as exactly one attempt.
- **Fix / mitigation:** Migration `0055_climbing_attempt_count` adds a positive
canonical `attempt_count`; Kaya imports populate it, and climbing volume and
session summaries sum it server-side. A dry-run-by-default
[backfill](../scripts/backfill-climbing-attempt-count.ts) copies valid historical
Kaya counts from preserved raw payloads.
- **Validation:** Parser and repository regression tests pass, the router
integration test verifies non-1:1 totals and the positive-count constraint in
Postgres, and the backfill integration test verifies dry-run behavior,
execution, and idempotence. Typecheck, repository lint, and migration policy
checks pass without retries or resilience changes.
- **Remaining risk / follow-up:** Deploy the migration, run
`pnpm backfill:climbing-attempt-count --execute`, and confirm the production
climbing chart no longer reports identical attempt and send totals.
12 changes: 12 additions & 0 deletions drizzle/0055_climbing_attempt_count.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
ALTER TABLE fitness.climbing_entry
-- A per-climb attempt count cannot approach the 32-bit integer limit.
-- squawk-ignore prefer-bigint-over-int
ADD COLUMN attempt_count integer DEFAULT 1 NOT NULL;
--> statement-breakpoint

ALTER TABLE fitness.climbing_entry
ADD CONSTRAINT climbing_entry_attempt_count_positive CHECK (attempt_count > 0) NOT VALID;
--> statement-breakpoint

ALTER TABLE fitness.climbing_entry
VALIDATE CONSTRAINT climbing_entry_attempt_count_positive;
7 changes: 7 additions & 0 deletions drizzle/meta/_journal.json
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,13 @@
"when": 1784656907000,
"tag": "0054_stripe_webhook_idempotency",
"breakpoints": true
},
{
"idx": 65,
"version": "7",
"when": 1784734909000,
"tag": "0055_climbing_attempt_count",
"breakpoints": true
}
]
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
"check:clickhouse-cdc": "./scripts/with-env.sh tsx scripts/check-clickhouse-cdc.ts",
"catch-up:metric-stream": "./scripts/with-env.sh tsx scripts/catch-up-clickhouse-metric-stream.ts",
"backfill:body-measurements": "./scripts/with-env.sh tsx scripts/backfill-body-measurement-sample.ts",
"backfill:climbing-attempt-count": "./scripts/with-env.sh tsx scripts/backfill-climbing-attempt-count.ts",
"test:all": "tsx scripts/run-tests.ts all",
"test:changed": "vitest run --changed origin/main --project unit --project mobile",
"test:changed:all": "tsx scripts/run-tests.ts changed",
Expand Down
2 changes: 2 additions & 0 deletions packages/mobile/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@
}
}
],
"expo-sharing",
"expo-web-browser",
"@bacons/apple-targets",
"./plugins/with-podfile-post-install"
]
Expand Down
28 changes: 14 additions & 14 deletions packages/mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@dofek/scoring": "workspace:*",
"@dofek/training": "workspace:*",
"@dofek/zones": "workspace:*",
"@expo/metro-runtime": "57.0.6",
"@expo/metro-runtime": "57.0.7",
"@expo/vector-icons": "15.1.1",
"@formatjs/intl-getcanonicallocales": "3.2.11",
"@formatjs/intl-locale": "5.3.9",
Expand All @@ -57,31 +57,31 @@
"@trpc/client": "11.18.0",
"@trpc/react-query": "11.18.0",
"dofek-server": "workspace:*",
"expo": "57.0.7",
"expo": "57.0.8",
"expo-apple-authentication": "57.0.1",
"expo-build-properties": "57.0.6",
"expo-build-properties": "57.0.7",
"expo-camera": "~57.0.3",
"expo-dev-client": "~57.0.7",
"expo-dev-client": "~57.0.8",
"expo-document-picker": "~57.0.1",
"expo-file-system": "57.0.1",
"expo-haptics": "57.0.1",
"expo-linking": "57.0.3",
"expo-location": "57.0.5",
"expo-modules-core": "57.0.6",
"expo-router": "57.0.7",
"expo-linking": "57.0.4",
"expo-location": "57.0.6",
"expo-modules-core": "57.0.7",
"expo-router": "57.0.8",
"expo-secure-store": "57.0.1",
"expo-sharing": "57.0.6",
"expo-splash-screen": "57.0.4",
"expo-task-manager": "57.0.5",
"expo-updates": "57.0.8",
"expo-web-browser": "57.0.1",
"expo-sharing": "57.0.7",
"expo-splash-screen": "57.0.5",
"expo-task-manager": "57.0.6",
"expo-updates": "57.0.9",
"expo-web-browser": "57.0.2",
"react": "19.2.3",
"react-native": "0.86.0",
"react-native-body-highlighter": "3.2.0",
"react-native-maps": "1.27.2",
"react-native-reanimated": "4.5.0",
"react-native-safe-area-context": "5.7.0",
"react-native-screens": "4.25.2",
"react-native-screens": "4.26.2",
"react-native-svg": "15.15.4",
"react-native-worklets": "0.10.0",
"zod": "4.4.3"
Expand Down
6 changes: 3 additions & 3 deletions packages/server/src/repositories/climbing-repository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,13 @@ describe("ClimbingRepository", () => {
]);
});

it("queries row counts and sent counts without using raw Kaya attempt counts", async () => {
it("queries canonical attempt totals and sent counts", async () => {
const { repo, execute } = makeRepository([]);

await repo.getVolumeByGrade(30);

const text = queryText(execute.mock.calls[0]?.[0]);
expect(text).toContain("COUNT(ce.id)::int AS attempts");
expect(text).toContain("SUM(ce.attempt_count)::int AS attempts");
expect(text).toContain("COUNT(*) FILTER (WHERE ce.sent)::int AS sends");
expect(text).toContain("GROUP BY ce.climb_type, ce.grade_system, ce.grade, grade_sort_value");
expect(text).toContain("ORDER BY grade_sort_value");
Expand Down Expand Up @@ -317,7 +317,7 @@ describe("ClimbingRepository", () => {
expect(text).toContain("ce.activity_id = ANY(a.member_activity_ids)");
expect(text).toContain("a.activity_type IN ('climbing', 'rock_climbing')");
expect(text).toContain("IS NOT NULL");
expect(text).toContain("COUNT(entry_id)::int AS attempts");
expect(text).toContain("SUM(attempt_count)::int AS attempts");
expect(text).toContain("COUNT(*) FILTER (WHERE sent)::int AS sends");
});
});
Expand Down
6 changes: 3 additions & 3 deletions packages/server/src/repositories/climbing-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export class ClimbingRepository extends BaseRepository {
ce.grade_system,
ce.grade,
${climbingGradeSortSql} AS grade_sort_value,
COUNT(ce.id)::int AS attempts,
SUM(ce.attempt_count)::int AS attempts,
COUNT(*) FILTER (WHERE ce.sent)::int AS sends
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
FROM fitness.v_activity a
JOIN fitness.climbing_entry ce ON ce.activity_id = ANY(a.member_activity_ids)
Expand Down Expand Up @@ -244,7 +244,7 @@ export class ClimbingRepository extends BaseRepository {
(a.started_at AT TIME ZONE ${this.timezone})::date::text AS session_date,
COALESCE(a.name, 'Climbing') AS name,
ce.location_name,
ce.id AS entry_id,
ce.attempt_count,
ce.sent,
ce.climb_type,
ce.grade,
Expand All @@ -259,7 +259,7 @@ export class ClimbingRepository extends BaseRepository {
session_date,
name,
MAX(location_name) FILTER (WHERE location_name IS NOT NULL) AS location_name,
COUNT(entry_id)::int AS attempts,
SUM(attempt_count)::int AS attempts,
COUNT(*) FILTER (WHERE sent)::int AS sends,
(ARRAY_AGG(grade ORDER BY grade_sort_value DESC NULLS LAST)
FILTER (WHERE sent AND climb_type = 'boulder'))[1] AS hardest_boulder_grade,
Expand Down
27 changes: 22 additions & 5 deletions packages/server/src/routers/climbing.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ describe("climbing router integration", () => {
grade_system,
grade,
sent,
attempt_count,
route_name,
location_name,
source_name,
Expand All @@ -89,6 +90,7 @@ describe("climbing router integration", () => {
'v_scale',
'V2',
true,
2,
'Warmup',
'Touchstone Pacific Pipe',
'Kaya',
Expand All @@ -101,6 +103,7 @@ describe("climbing router integration", () => {
'v_scale',
'V4',
true,
3,
'Blue Circuit',
'Touchstone Pacific Pipe',
'Kaya',
Expand All @@ -113,6 +116,7 @@ describe("climbing router integration", () => {
'v_scale',
'V5',
false,
4,
'Project',
'Touchstone Pacific Pipe',
'Kaya',
Expand All @@ -125,6 +129,7 @@ describe("climbing router integration", () => {
'yds',
'5.10a',
true,
2,
'Lead Route',
'Mission Cliffs',
'Kaya',
Expand Down Expand Up @@ -158,23 +163,23 @@ describe("climbing router integration", () => {
);
expect(volumeByGrade).toEqual(
expect.arrayContaining([
expect.objectContaining({ climbType: "boulder", grade: "V4", attempts: 1, sends: 1 }),
expect.objectContaining({ climbType: "boulder", grade: "V5", attempts: 1, sends: 0 }),
expect.objectContaining({ climbType: "route", grade: "5.10a", attempts: 1, sends: 1 }),
expect.objectContaining({ climbType: "boulder", grade: "V4", attempts: 3, sends: 1 }),
expect.objectContaining({ climbType: "boulder", grade: "V5", attempts: 4, sends: 0 }),
expect.objectContaining({ climbType: "route", grade: "5.10a", attempts: 2, sends: 1 }),
]),
);
expect(sessionSummary).toEqual(
expect.arrayContaining([
expect.objectContaining({
activityId: climbingActivityId,
attempts: 3,
attempts: 9,
sends: 2,
hardestBoulderGrade: "V4",
hardestRouteGrade: null,
}),
expect.objectContaining({
activityId: routeActivityId,
attempts: 1,
attempts: 2,
sends: 1,
hardestBoulderGrade: null,
hardestRouteGrade: "5.10a",
Expand All @@ -183,6 +188,18 @@ describe("climbing router integration", () => {
);
});

it("rejects non-positive climbing attempt counts", async () => {
await expect(
testContext.db.execute(sql`
INSERT INTO fitness.climbing_entry (
activity_id, climb_type, grade_system, grade, sent, attempt_count
) VALUES (
${routeActivityId}, 'route', 'yds', '5.9', false, 0
)
`),
).rejects.toThrow("Failed query");
});

it("cascades climbing entries when an activity is deleted", async () => {
await testContext.db.execute(
sql`DELETE FROM fitness.activity WHERE id = ${climbingActivityId}`,
Expand Down
Loading
Loading