fix(submit): adopt legacy rows for first device submit - #609
Merged
junhoyeo merged 2 commits intoMay 27, 2026
Conversation
Validation * Validation tier: Tier 3 - submit data-integrity change; the diff changes how legacy daily_breakdown rows are attributed during the device-aware submit transition. * git diff --check: PASS * git diff --cached --check: PASS * bun x vitest run __tests__/api/submitAuth.test.ts: PASS (7 tests) * bun x vitest run __tests__/api/submitAuth.test.ts __tests__/api/usersProfile.test.ts: PASS (13 tests) * bun x vitest run __tests__/api/submitAuth.test.ts __tests__/api/usersProfile.test.ts __tests__/lib/getLeaderboard.test.ts __tests__/lib/getGroupLeaderboard.test.ts: PASS (22 tests) * bun x vitest run __tests__/lib/getLeaderboardAllTime.test.ts: PASS (4 tests) * bun run lint -- src/app/api/submit/route.ts __tests__/api/submitAuth.test.ts __tests__/api/usersProfile.test.ts: PASS * bash scripts/check-version-coherence.sh: PASS (Version coherence OK: 2.1.3) * Ledger: not applicable - not required for selected validation tier/change family. * Version: PASS, bash scripts/check-version-coherence.sh * Not run: full frontend suite and Rust suite - not required for selected validation tier; targeted submit/profile/leaderboard coverage exercises the changed write path and public totals. Rollback * git revert HEAD
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Add a regression test for the device-aware submit cutover path where legacy daily rows remain separate after another modern device has already submitted. Constraint: Preserve legacy daily rows when modern-device attribution is ambiguous Confidence: medium Scope-risk: narrow Not-tested: DB-backed legacy adoption with real Postgres rows
junhoyeo
pushed a commit
to IvGolovach/tokscale
that referenced
this pull request
May 27, 2026
The regression guard replaces the old client-breakdown merge helper on existing-day submits, so the legacy cutover route tests need to assert the guarded merge path and the provenance now attached to inserted day breakdowns. Constraint: junhoyeo#609 legacy-device adoption is already on main and shares submitAuth route coverage with this PR Rejected: Skip the legacy cutover tests on this branch | would hide the integration contract between the guard and legacy adoption Confidence: high Scope-risk: narrow Tested: bun --cwd packages/frontend vitest run __tests__/api/submit.test.ts __tests__/api/submitAuth.test.ts Tested: bun run --cwd packages/frontend test Tested: bun --cwd packages/frontend eslint __tests__/api/submitAuth.test.ts src/app/api/submit/route.ts src/lib/db/helpers.ts src/lib/db/schema.ts src/lib/validation/submission.ts
Owner
|
@IvGolovach this has been merged to v3.0.0: https://github.com/junhoyeo/tokscale/releases/tag/v3.0.0 thanks for the contribution! |
leecoder
pushed a commit
to leecoder/tokscale
that referenced
this pull request
May 29, 2026
* fix(submit): adopt legacy rows for first device submit Validation * Validation tier: Tier 3 - submit data-integrity change; the diff changes how legacy daily_breakdown rows are attributed during the device-aware submit transition. * git diff --check: PASS * git diff --cached --check: PASS * bun x vitest run __tests__/api/submitAuth.test.ts: PASS (7 tests) * bun x vitest run __tests__/api/submitAuth.test.ts __tests__/api/usersProfile.test.ts: PASS (13 tests) * bun x vitest run __tests__/api/submitAuth.test.ts __tests__/api/usersProfile.test.ts __tests__/lib/getLeaderboard.test.ts __tests__/lib/getGroupLeaderboard.test.ts: PASS (22 tests) * bun x vitest run __tests__/lib/getLeaderboardAllTime.test.ts: PASS (4 tests) * bun run lint -- src/app/api/submit/route.ts __tests__/api/submitAuth.test.ts __tests__/api/usersProfile.test.ts: PASS * bash scripts/check-version-coherence.sh: PASS (Version coherence OK: 2.1.3) * Ledger: not applicable - not required for selected validation tier/change family. * Version: PASS, bash scripts/check-version-coherence.sh * Not run: full frontend suite and Rust suite - not required for selected validation tier; targeted submit/profile/leaderboard coverage exercises the changed write path and public totals. Rollback * git revert HEAD * test(submit): cover legacy rows after modern device submit Add a regression test for the device-aware submit cutover path where legacy daily rows remain separate after another modern device has already submitted. Constraint: Preserve legacy daily rows when modern-device attribution is ambiguous Confidence: medium Scope-risk: narrow Not-tested: DB-backed legacy adoption with real Postgres rows --------- Co-authored-by: Junho Yeo <i@junho.io>
This was referenced Jun 9, 2026
junhoyeo
added a commit
to blpeng2/tokscale
that referenced
this pull request
Jun 9, 2026
Resolution policy: take main wholesale for everything superseded by the relational device model that landed via junhoyeo#517/junhoyeo#593/junhoyeo#609 — device.rs, main.rs, schema.ts, helpers.ts, submit route + tests, and the whole TUI (app.rs, tui/mod.rs, footer.rs). Keep only the PR's remote-stats half (tui/remote.rs, /api/me/stats route, meStats tests) to be rebuilt on top of main in follow-up commits. Drop the next-server.d.ts shim that the PR added as a workaround for the PR-era Next version. Refs junhoyeo#699
This was referenced Jul 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Why
#517 fixed the normal modern case where multiple computers submit with stable device IDs, but migrated historical rows still live in the
legacy-defaultdevice bucket. On currentmain, the first modern device-aware submit only looks for rows attached to the new device ID, so it can insert a new same-date row while the legacy row remains counted. That can double-count the same historical usage during the upgrade path and leave #248 reproducible for users with pre-device data.Diff scope
packages/frontend/src/app/api/submit/route.ts: before writing incoming daily rows, the submit transaction now adopts a user's legacy daily rows into the first real device bucket when no modern device rows exist yet for that submission.packages/frontend/__tests__/api/submitAuth.test.ts: adds a regression test that fails on currentmainbecause the route inserts a duplicate daily row instead of adopting the legacy row.packages/frontend/__tests__/api/usersProfile.test.ts: adds read-path coverage proving same-date rows from multiple submitted devices render as one profile contribution with summed totals.Branch integrity
main64e278cdc4f55544576f3b42010644cd8ba6aa9d49a01dd44d89dc88ce55cd209f33569e53b1f10a0 behind / 1 ahead64e278cdc4f55544576f3b42010644cd8ba6aa9dCommit integrity
49a01dd44d89dc88ce55cd209f33569e53b1f10a fix(submit): adopt legacy rows for first device submitDiff hygiene
git diff --name-status origin/main...HEAD: PASS, only the submit route and two targeted frontend test files changed.git diff --check origin/main...HEAD: PASS, no output.git diff --cached --check: PASS, no output before commit.Validation mode and proof
daily_breakdownrows are attributed during the device-aware submit transition, so targeted submit/profile/leaderboard coverage is required.bun x vitest run __tests__/api/submitAuth.test.ts: PASS, 7 tests.bun x vitest run __tests__/api/submitAuth.test.ts __tests__/api/usersProfile.test.ts: PASS, 13 tests.bun x vitest run __tests__/api/submitAuth.test.ts __tests__/api/usersProfile.test.ts __tests__/lib/getLeaderboard.test.ts __tests__/lib/getGroupLeaderboard.test.ts: PASS, 22 tests.bun x vitest run __tests__/lib/getLeaderboardAllTime.test.ts: PASS, 4 tests.bun run lint -- src/app/api/submit/route.ts __tests__/api/submitAuth.test.ts __tests__/api/usersProfile.test.ts: PASS.bash scripts/check-version-coherence.sh: PASS,Version coherence OK: 2.1.3.Ledger and version proof
bash scripts/check-version-coherence.sh.Migration notes
submitted_devicestable and existingdaily_breakdown.submitted_device_iduniqueness model.Runtime safety
/api/submittransaction after the user submission row is selected withFOR UPDATE.CI context confirmation
Rollback plan
Known residual risks
Summary by cubic
Fixes #248 by adopting legacy
daily_breakdownrows into the first modern submitted device on the first device-aware submit, preventing duplicate same-date rows and double-counted totals. Keeps #517 behavior: modern devices still have separate daily buckets and totals are recalculated from all rows.packages/frontend/src/app/api/submit/route.ts, inside the/api/submittransaction, when no modern-device rows exist for the submission and the incoming device is modern, reassign that submission’s legacy rows to the device; otherwise keep legacy rows separate.packages/frontend/__tests__/api/submitAuth.test.tsandpackages/frontend/__tests__/api/usersProfile.test.tscovering adoption (no duplicate insert), preserving legacy rows when another modern device already submitted, and profile aggregation into a single per-date contribution with summed totals.Written for commit 1c8a217. Summary will update on new commits. Review in cubic