mirror of
https://github.com/nestriness/nestri.git
synced 2026-11-18 21:19:50 +02:00
Release: host reports accepted, library drops games no longer owned (#374)
- The API accepts a host's own tier label in a box report. Every report naming a box was rejected with a 400, so stop reasons never reached a run. - A library sync now removes the games the account no longer owns. An empty sync removes nothing, and a game owned again comes back. - Build: a mesa patch keeping the GE rings off the discardable path.
This commit is contained in:
@@ -70,6 +70,7 @@ export namespace LibraryApi {
|
||||
z.object({
|
||||
gamesSynced: z.number(),
|
||||
libraryEntries: z.number(),
|
||||
libraryRemoved: z.number().meta({ description: 'Entries dropped because the account no longer owns them' }),
|
||||
failedEntries: z.array(z.number())
|
||||
})
|
||||
)
|
||||
@@ -200,10 +201,16 @@ export namespace LibraryApi {
|
||||
}
|
||||
}
|
||||
|
||||
// Only after a sync that fully landed: a game that failed to
|
||||
// write would otherwise be pruned as if the account lost it.
|
||||
const libraryRemoved =
|
||||
failedSteamIDs.size === 0 ? await Library.prune({ userId, keep: gameIds }) : 0;
|
||||
|
||||
return c.json({
|
||||
data: {
|
||||
gamesSynced,
|
||||
libraryEntries,
|
||||
libraryRemoved,
|
||||
failedEntries: Array.from(failedSteamIDs)
|
||||
}
|
||||
});
|
||||
|
||||
@@ -75,7 +75,7 @@ describe('POST /machine/report', () => {
|
||||
boxesKnown: 2,
|
||||
boxesRunning: 1,
|
||||
boxes: [
|
||||
{ boxId: running.id, tier: 'sm', state: 'running', pid: 1234, uptimeS: 45 },
|
||||
{ boxId: running.id, tier: '1080p', state: 'running', pid: 1234, uptimeS: 45 },
|
||||
{ boxId: idle.id, tier: 'sm', state: 'created' }
|
||||
]
|
||||
});
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
From 51bd5adfe92aa3010d0b0ddbc417d2be636a369e Mon Sep 17 00:00:00 2001
|
||||
From: DatCaptainHorse <DatCaptainHorse@users.noreply.github.com>
|
||||
Date: Wed, 7 Oct 2026 22:00:43 +0300
|
||||
Subject: [PATCH] radv: don't make the GE rings BO discardable
|
||||
|
||||
amdgpu only adds GTT to a VRAM BO's allowed domains when the BO is not
|
||||
discardable. A discardable BO that gets evicted loses its backing and
|
||||
can only be placed in VRAM again, so under VRAM pressure it may never
|
||||
come back: every submission that references it fails validation with
|
||||
-ENOMEM ("Not enough memory for command submission") until enough VRAM
|
||||
is freed, which on a full card can be never.
|
||||
|
||||
Seen with several processes sharing an RX 9060 XT under dmem cgroup
|
||||
protection: a protected allocation in one process evicted another
|
||||
process's GE rings, and that process then failed every graphics
|
||||
submission (1735 failed validations in 6 seconds, all of this 4 MiB
|
||||
BO) while the card stayed full.
|
||||
|
||||
Without the flag the BO keeps VRAM as its preferred domain with GTT as
|
||||
a fallback: under pressure the ring is moved to GTT and the submission
|
||||
goes through, and it is moved back to VRAM once there is room. The
|
||||
cost is copying the ring's contents on eviction, which is rare.
|
||||
|
||||
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
||||
---
|
||||
src/amd/vulkan/radv_queue.c | 6 +++++-
|
||||
1 file changed, 5 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/src/amd/vulkan/radv_queue.c b/src/amd/vulkan/radv_queue.c
|
||||
index e3321ff9b85..ec7a934c78f 100644
|
||||
--- a/src/amd/vulkan/radv_queue.c
|
||||
+++ b/src/amd/vulkan/radv_queue.c
|
||||
@@ -947,8 +947,12 @@ radv_update_preamble_cs(struct radv_queue_state *queue, struct radv_device *devi
|
||||
|
||||
if (!queue->ring_info.ge_rings && needs->ge_rings) {
|
||||
assert(pdev->info.gfx_level >= GFX11);
|
||||
+ /* Not discardable: amdgpu gives a discardable BO no GTT fallback, so
|
||||
+ * once evicted under VRAM pressure it can only come back to VRAM, and
|
||||
+ * every submission that needs it fails until VRAM frees up.
|
||||
+ */
|
||||
result = radv_bo_create(device, NULL, pdev->info.total_attribute_pos_prim_ring_size, 2 * 1024 * 1024 /* 2MiB */,
|
||||
- RADEON_DOMAIN_VRAM, RADEON_FLAG_32BIT | RADEON_FLAG_DISCARDABLE | ring_bo_flags_tmz,
|
||||
+ RADEON_DOMAIN_VRAM, RADEON_FLAG_32BIT | ring_bo_flags_tmz,
|
||||
RADV_BO_PRIORITY_SCRATCH, 0, true, &ge_rings_bo);
|
||||
if (result != VK_SUCCESS)
|
||||
goto fail;
|
||||
--
|
||||
2.56.0
|
||||
|
||||
@@ -235,22 +235,32 @@ export namespace Box {
|
||||
* kept and already trustworthy. Storing a plausible number instead of a
|
||||
* measured one is how a scheduler learns to trust a field nobody produced.
|
||||
*/
|
||||
/**
|
||||
* The host's own name for a box's shape, such as `1080p`.
|
||||
*
|
||||
* Free text, and never stored: placement already wrote this box's size on
|
||||
* its row. Pinning it to our size enum turned every report from a host
|
||||
* that names shapes by resolution into a 400, and with it every stop
|
||||
* reason the report carries.
|
||||
*/
|
||||
const ReportedTier = z.string();
|
||||
|
||||
export const Reported = z.discriminatedUnion('state', [
|
||||
z.object({
|
||||
boxId: z.string(),
|
||||
tier: z.enum(BoxTier.enumValues),
|
||||
tier: ReportedTier,
|
||||
state: z.literal('created')
|
||||
}),
|
||||
z.object({
|
||||
boxId: z.string(),
|
||||
tier: z.enum(BoxTier.enumValues),
|
||||
tier: ReportedTier,
|
||||
state: z.literal('running'),
|
||||
pid: z.number().int().optional(),
|
||||
uptimeS: z.number().int()
|
||||
}),
|
||||
z.object({
|
||||
boxId: z.string(),
|
||||
tier: z.enum(BoxTier.enumValues),
|
||||
tier: ReportedTier,
|
||||
state: z.literal('stopped'),
|
||||
reason: z.string(),
|
||||
clean: z.boolean()
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
import { afterAll, describe, expect, test } from 'bun:test';
|
||||
|
||||
import { Fixtures } from '../db/fixtures.js';
|
||||
import { testDb } from '../db/test.js';
|
||||
import { Game } from '../game/index.js';
|
||||
import { Identifier } from '../id.js';
|
||||
import { Library } from './library.js';
|
||||
|
||||
const sql = testDb();
|
||||
|
||||
const createdUserIds: string[] = [];
|
||||
const createdGameIds: string[] = [];
|
||||
|
||||
async function newGame(steamAppId: number): Promise<string> {
|
||||
const [row] = await Game.upsert({
|
||||
id: Identifier.ascending('game'),
|
||||
steamAppId,
|
||||
slug: `library-test-${steamAppId}`,
|
||||
name: `Library Test ${steamAppId}`
|
||||
});
|
||||
if (!row) throw new Error('expected a game row');
|
||||
createdGameIds.push(row.id);
|
||||
return row.id;
|
||||
}
|
||||
|
||||
async function own(userId: string, gameId: string) {
|
||||
await Library.upsert({ id: Identifier.ascending('userLibrary'), userId, gameId });
|
||||
}
|
||||
|
||||
afterAll(async () => {
|
||||
if (createdUserIds.length > 0) {
|
||||
await sql`delete from "user_library" where user_id in ${sql(createdUserIds)}`;
|
||||
await sql`delete from "user" where id in ${sql(createdUserIds)}`;
|
||||
}
|
||||
if (createdGameIds.length > 0) {
|
||||
await sql`delete from "game" where id in ${sql(createdGameIds)}`;
|
||||
}
|
||||
});
|
||||
|
||||
describe('Library.prune', () => {
|
||||
test('drops what the account no longer owns, and brings it back when owned again', async () => {
|
||||
const owner = await Fixtures.owner('library-prune');
|
||||
createdUserIds.push(owner.userId);
|
||||
const kept = await newGame(9_100_001);
|
||||
const lost = await newGame(9_100_002);
|
||||
await own(owner.userId, kept);
|
||||
await own(owner.userId, lost);
|
||||
|
||||
expect(await Library.prune({ userId: owner.userId, keep: [kept] })).toBe(1);
|
||||
const after = (await Library.listByUser(owner.userId)).map((e) => e.gameId);
|
||||
expect(after).toEqual([kept]);
|
||||
|
||||
await own(owner.userId, lost);
|
||||
expect((await Library.listByUser(owner.userId)).length).toBe(2);
|
||||
});
|
||||
|
||||
test('an empty sync removes nothing', async () => {
|
||||
const owner = await Fixtures.owner('library-empty');
|
||||
createdUserIds.push(owner.userId);
|
||||
await own(owner.userId, await newGame(9_100_003));
|
||||
|
||||
expect(await Library.prune({ userId: owner.userId, keep: [] })).toBe(0);
|
||||
expect((await Library.listByUser(owner.userId)).length).toBe(1);
|
||||
});
|
||||
});
|
||||
@@ -1,4 +1,4 @@
|
||||
import { eq, and, isNull, sql, inArray } from 'drizzle-orm';
|
||||
import { eq, and, isNull, sql, inArray, notInArray } from 'drizzle-orm';
|
||||
import z from 'zod';
|
||||
|
||||
import { Database } from '../db/index.js';
|
||||
@@ -86,7 +86,9 @@ export namespace Library {
|
||||
set: {
|
||||
playtime2w: input.playtime2w ?? null,
|
||||
playtimeForever: input.playtimeForever ?? null,
|
||||
lastPlayed: input.lastPlayed ? new Date(input.lastPlayed) : null
|
||||
lastPlayed: input.lastPlayed ? new Date(input.lastPlayed) : null,
|
||||
// Owned again after a prune: the entry comes back.
|
||||
timeDeleted: null
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -212,6 +214,36 @@ export namespace Library {
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* Drop the entries a sync no longer lists.
|
||||
*
|
||||
* A sync is the whole of what the account owns, so an entry it leaves out
|
||||
* is a game the account lost: a licence revoked, or a library from a Steam
|
||||
* account this user no longer signs in with. An empty `keep` removes
|
||||
* nothing, because an empty answer from Steam is likelier a blip than an
|
||||
* account that owns no games.
|
||||
*/
|
||||
export const prune = fn(
|
||||
z.object({ userId: z.string(), keep: z.array(z.string()) }),
|
||||
async (input) => {
|
||||
if (input.keep.length === 0) return 0;
|
||||
return Database.use(async (tx) => {
|
||||
const removed = await tx
|
||||
.update(UserLibraryTable)
|
||||
.set({ timeDeleted: sql`now()` })
|
||||
.where(
|
||||
and(
|
||||
eq(UserLibraryTable.userId, input.userId),
|
||||
isNull(UserLibraryTable.timeDeleted),
|
||||
notInArray(UserLibraryTable.gameId, input.keep)
|
||||
)
|
||||
)
|
||||
.returning({ id: UserLibraryTable.id });
|
||||
return removed.length;
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
export const remove = fn(Info.shape.id, async (id) => {
|
||||
await Database.use(async (tx) => {
|
||||
await tx
|
||||
|
||||
Reference in New Issue
Block a user