fix(submit): make usage merges device-aware - #517
Merged
junhoyeo merged 1 commit intoMay 24, 2026
Conversation
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
IvGolovach
force-pushed
the
codex/device-aware-submit-merge
branch
from
May 12, 2026 17:21
29bc4d8 to
74b5308
Compare
Contributor
|
So when can I use this feature? |
Collaborator
Author
Thanks for asking! This is not available in |
junhoyeo
approved these changes
May 24, 2026
junhoyeo
left a comment
Owner
There was a problem hiding this comment.
LGTM — migration is well-designed, COUNT(DISTINCT) fix is correct. Follow-up: add a one-line comment on schemaVersion: 2 semantics.
Validation: - cargo fmt --all -- --check - cargo test -p tokscale-cli - /opt/homebrew/bin/cargo-clippy --package=tokscale-cli --all-features -- -D warnings - bunx vitest run packages/frontend/__tests__ - bun run lint (0 errors; existing warnings only) - git diff --check && git diff --cached --check - git diff --check origin/main...HEAD Rollback: - Revert this commit.
junhoyeo
force-pushed
the
codex/device-aware-submit-merge
branch
from
May 24, 2026 14:59
74b5308 to
e4f6098
Compare
This was referenced May 25, 2026
junhoyeo
added a commit
that referenced
this pull request
May 25, 2026
…rift (#593) Schema: - Add 0010_submit_count_safety.sql to ALTER TABLE submissions ADD COLUMN IF NOT EXISTS submit_count. The column is referenced by schema.ts and written on every /api/submit call, but no earlier .sql migration adds it; prod has it because somebody once ran drizzle-kit push directly, so a fresh drizzle-kit migrate on CI/staging/dev currently breaks /api/submit. Verified locally against postgres:16. API: - GET /api/users/[username]/devices: aggregated per-device totals (tokens, cost, input/output, active days) for a user's submission devices, sourced from submitted_devices LEFT JOIN daily_breakdown. - GET /api/users/[username]/devices/[deviceId]: per-device detail with day-by-day contributions. Cross-user device ids silently 404. - PATCH /api/settings/devices/[deviceId]: session-authenticated rename (or clear, via name: null). Validates length and rejects control characters; ownership enforced in the same WHERE. Helpers: - src/lib/devices/shared.ts: deviceDisplayLabel() and toIsoString() shared across the three routes so the public label format cannot drift. Local dev: - scripts/seed-dev.ts: idempotent synthetic seed (3 users × 2 devices × 14 days + 1 group). Refuses any non-localhost DATABASE_URL. Ported from #389 onto main's submitted_devices model (#517) rather than that PR's submissions.source_id schema rewrite. #389's CLI source-id lockfile and profile Devices tab UI are deliberately not in this PR; they want separate decisions (CLI lock vs main's existing device.id payload; UI as a styled-components review pass). Constraint: do not regress main's submitted_devices schema or rehash the migrated multi-machine model Rejected: include #389's index-cleanup migration (drop idx_submissions_user_id et al.) | needs a fresh pg_stat_user_indexes audit on current prod before dropping anything in a single transaction Rejected: bundle #389's CLI source-id lockfile | main already sends device.id via #517/#545; the lockfile is a behavior change, not a port Confidence: high Scope-risk: narrow Directive: /api/users/[username]/devices is public — match it to /api/users/[username]'s visibility model when extending; the rename endpoint is the only auth-gated piece Not-tested: interaction with the existing rank cache (rankTotal in embed routes is unaffected)
Owner
|
@IvGolovach @BenLampson this has been merged to v3.0.0: https://github.com/junhoyeo/tokscale/releases/tag/v3.0.0 thanks for the contribution! |
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
3 tasks
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
tokscale submitpayloads.(submission, device, date)instead of only(submission, date).Why
Submitting from multiple machines currently shares one daily row per user submission. A later submit for the same date can replace another device's client breakdown because the merge cannot distinguish which local dataset is being refreshed.
Diff scope
crates/tokscale-cli/src/device.rs: resolves stable submit device identity from env/config, withTOKSCALE_DEVICE_IDandTOKSCALE_DEVICE_NAMEoverrides.crates/tokscale-cli/src/main.rs: includes the device only in submit payloads, not graph JSON output.packages/frontend/src/lib/validation/submission.ts: validates optional device metadata and folds the device id into the submission hash.packages/frontend/src/lib/db/schema.tsandpackages/frontend/src/lib/db/migrations/0006_add_submitted_devices.sql: addsubmitted_devices, backfill legacy rows, and change the daily uniqueness boundary.packages/frontend/src/app/api/submit/route.ts: upserts submit devices, locks/merges rows for the current device, and recalculates aggregate totals across all devices.packages/frontend/src/app/api/settings/submitted-data/route.ts: deletes submit device metadata together with submitted usage data.Migration notes
submitted_deviceswith a per-user uniquedevice_key.legacy-defaultdevice before makingdaily_breakdown.submitted_device_idrequired.(submission_id, date)uniqueness constraint with(submission_id, submitted_device_id, date).Safety
deviceremain valid and use thelegacy-defaultbucket.activeDayscounts distinct active dates so it does not inflate across devices.Validation
cargo fmt --all -- --check— PASS.cargo test -p tokscale-cli— PASS:473 passed,1 ignored;cli_tests:88 passed./opt/homebrew/bin/cargo-clippy --package=tokscale-cli --all-features -- -D warnings— PASS.bunx vitest run packages/frontend/__tests__— PASS:21 files,182 tests.bun run lintinpackages/frontend— PASS, 0 errors; 7 existing warnings in untouched files.git diff --check origin/main...HEAD— PASS, no output.Rollback
Revert the merge commit. If the database migration has already been applied, rollback also needs to remove
daily_breakdown.submitted_device_id, dropsubmitted_devices, and restore the previous(submission_id, date)uniqueness constraint.