Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
### Fixes
- Raise Windows timer resolution during ACC and AC Evo capture so shared-memory polling no longer collapses to the default ~64 Hz tick
- Make stale-session reprocessing recoverable with retry and dismissal actions, accessible progress states, and clear failure feedback
- Skip recordings from games unavailable in the current RaceIQ build during stale-session checks and bulk reprocessing
- Open RaceIQ faster by skipping unnecessary historical race-result work during startup
- Show actionable, neutral guidance when AI provider, credentials, or model configuration is incomplete
- Keep iRacing lap replay within saved frame boundaries so telemetry from the following lap is not included
Expand Down
12 changes: 10 additions & 2 deletions server/db/session-queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,18 @@ export async function updateSessionRawFile(
* cards and per-game pages now both report the full picture.
*/

export async function countStaleSessions(currentIds: string | string[]): Promise<number> {
export async function countStaleSessions(
currentIds: string | string[],
reprocessableGameIds: GameId[],
): Promise<number> {
const ids = Array.isArray(currentIds) ? currentIds : [currentIds];
const rows = await db
.select({ id: sessions.id })
.from(sessions)
.where(
and(
sql`${sessions.rawFile} IS NOT NULL`,
inArray(sessions.gameId, reprocessableGameIds),
or(isNull(sessions.lapDetectorVersion), notInArray(sessions.lapDetectorVersion, ids))
)
)
Expand All @@ -82,14 +86,18 @@ export async function countStaleSessions(currentIds: string | string[]): Promise
* Get IDs of sessions with stale lap detector version that have a raw file.
*/

export async function getStaleSessions(currentIds: string | string[]): Promise<number[]> {
export async function getStaleSessions(
currentIds: string | string[],
reprocessableGameIds: GameId[],
): Promise<number[]> {
const ids = Array.isArray(currentIds) ? currentIds : [currentIds];
const rows = await db
.select({ id: sessions.id })
.from(sessions)
.where(
and(
sql`${sessions.rawFile} IS NOT NULL`,
inArray(sessions.gameId, reprocessableGameIds),
or(isNull(sessions.lapDetectorVersion), notInArray(sessions.lapDetectorVersion, ids))
)
)
Expand Down
11 changes: 9 additions & 2 deletions server/routes/session-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { LAP_DETECTOR_ID } from "../lap-detection/detector";
import { LAP_DETECTOR_ACC_ID } from "../games/acc/lap-detector";
import { LAP_DETECTOR_AC_EVO_ID } from "../games/ac-evo/lap-detector";
import { LAP_DETECTOR_IRACING_ID } from "../games/iracing/lap-detector";
import { getAllServerGames } from "../games/registry";
import { wsManager } from "../runtime/websocket-manager";
import { computeRecap } from "../lap-analysis/recap";
import { tryGetGame } from "../../shared/games/registry";
Expand Down Expand Up @@ -79,12 +80,18 @@ export const sessionRoutes = new Hono()
const { id } = c.req.valid("param");
const result = await reprocessSession(id);
wsManager.broadcastNotification({ type: "lap-reprocessed", ...result });
const remaining = await countStaleSessions(ALL_DETECTOR_IDS);
const remaining = await countStaleSessions(
ALL_DETECTOR_IDS,
getAllServerGames().map((adapter) => adapter.id),
);
if (remaining === 0) wsManager.setStaleSessionsNotification(null);
return c.json(result);
})
.post("/api/sessions/reprocess-stale", async (c) => {
const staleIds = await getStaleSessions(ALL_DETECTOR_IDS);
const staleIds = await getStaleSessions(
ALL_DETECTOR_IDS,
getAllServerGames().map((adapter) => adapter.id),
);
const results = [];
for (const id of staleIds) {
const result = await reprocessSession(id);
Expand Down
6 changes: 5 additions & 1 deletion server/runtime/startup-jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { LAP_DETECTOR_ID } from "../lap-detection/detector";
import { LAP_DETECTOR_ACC_ID } from "../games/acc/lap-detector";
import { LAP_DETECTOR_AC_EVO_ID } from "../games/ac-evo/lap-detector";
import { LAP_DETECTOR_IRACING_ID } from "../games/iracing/lap-detector";
import { getAllServerGames } from "../games/registry";
import { wsManager } from "./websocket-manager";
import { startSessionCompressor } from "../session-capture/compressor";
import { startUpdateCheckSchedule } from "./update/check";
Expand All @@ -31,7 +32,10 @@ export function startSyncAndStaleSessionJobs(dependencies: StartupJobDependencie
(dependencies.startCommunityTunesSync ?? startCommunityTunesSync)();
(dependencies.startLaptimesSync ?? startLaptimesSync)();

(dependencies.countStaleSessions ?? countStaleSessions)(ALL_DETECTOR_IDS).then((count) => {
(dependencies.countStaleSessions ?? countStaleSessions)(
ALL_DETECTOR_IDS,
getAllServerGames().map((adapter) => adapter.id),
).then((count) => {
if (count > 0) {
console.log(`[Server] ${count} session(s) recorded with stale lap detector — will prompt user to reprocess`);
wsManager.setStaleSessionsNotification({
Expand Down
19 changes: 13 additions & 6 deletions test/session-capture/raw-binary-storage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,14 @@ describe("countStaleSessions", () => {
insertedIds.length = 0;
});

async function insertSession(rawFile: string | null, lapDetectorVersion: string | null): Promise<number> {
async function insertSession(
rawFile: string | null,
lapDetectorVersion: string | null,
gameId = "fm-2023",
): Promise<number> {
const row = await db
.insert(sessions)
.values({ carOrdinal: 1, trackOrdinal: 1, gameId: "fm-2023", rawFile, lapDetectorVersion })
.values({ carOrdinal: 1, trackOrdinal: 1, gameId, rawFile, lapDetectorVersion })
.returning({ id: sessions.id })
.get();
const id = row!.id;
Expand All @@ -292,34 +296,37 @@ describe("countStaleSessions", () => {
}

test("counts only raw sessions with stale detector versions", async () => {
const beforeCount = await countStaleSessions(detectorId);
const beforeCount = await countStaleSessions(detectorId, ["fm-2023"]);

await insertSession("/some/path-old.bin", "lapdetector_v0");
await insertSession("/some/path-null.bin", null);
await insertSession("/some/path-current.bin", detectorId);
await insertSession(null, null);
await insertSession("/some/path-unsupported.bin", "lapdetector_v0", "lmu");

const afterCount = await countStaleSessions(detectorId);
const afterCount = await countStaleSessions(detectorId, ["fm-2023"]);

expect(afterCount - beforeCount).toBe(2);
});

test("getStaleSessions returns only raw sessions with stale detector versions", async () => {
const baselineIds = await getStaleSessions(detectorId);
const baselineIds = await getStaleSessions(detectorId, ["fm-2023"]);
const baselineSet = new Set(baselineIds);

const staleRawOldVersion = await insertSession("/some/path-old.bin", "lapdetector_v0");
const staleRawNullVersion = await insertSession("/some/path-null.bin", null);
const currentVersion = await insertSession("/some/path-current.bin", detectorId);
const noRaw = await insertSession(null, null);
const unsupportedGame = await insertSession("/some/path-unsupported.bin", "lapdetector_v0", "lmu");

const allIds = await getStaleSessions(detectorId);
const allIds = await getStaleSessions(detectorId, ["fm-2023"]);
const insertedIdsOnly = allIds.filter((id) => !baselineSet.has(id));

expect(insertedIdsOnly).toHaveLength(2);
expect(insertedIdsOnly).toContain(staleRawOldVersion);
expect(insertedIdsOnly).toContain(staleRawNullVersion);
expect(insertedIdsOnly).not.toContain(currentVersion);
expect(insertedIdsOnly).not.toContain(noRaw);
expect(insertedIdsOnly).not.toContain(unsupportedGame);
});
});
Loading