From d142317b182a4b3bc2f4450e4b4ec37ff45d28a0 Mon Sep 17 00:00:00 2001 From: unimatrixgit <95320811+unimatrixgit@users.noreply.github.com> Date: Sun, 29 Nov 2026 09:06:59 +0100 Subject: [PATCH 1/2] Rotate deferred quest successor retries without starving later players --- .../docs/QUEST-CHAIN-AUTO-START-20261129.md | 4 +++- website/node/progression-quests.mjs | 12 ++++++---- website/tests/progression-quests.test.mjs | 24 +++++++++++++++++++ 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/website/docs/QUEST-CHAIN-AUTO-START-20261129.md b/website/docs/QUEST-CHAIN-AUTO-START-20261129.md index c3b143dd..8a5ca64f 100644 --- a/website/docs/QUEST-CHAIN-AUTO-START-20261129.md +++ b/website/docs/QUEST-CHAIN-AUTO-START-20261129.md @@ -6,6 +6,8 @@ Bounded scope: reuse createQuestProgression for Personal and the existing namesp Website refresh selects the authoritative returned nextQuestId. Existing authenticated game journal responses forward the same server-owned successor result; clients cannot supply a nextQuestId. Native optional focus support can consume this field in the separate quest UI work without changing reward authority. -Validation so far:59 local progression/game/POL tests passed, including four new chain cases (unique next/no extra reward, forks/unrelated branches, all-predecessor gating/retry, failed issuance retaining committed reward) and native response/forged-input coverage. Existing uncapped POL test now checks the absence of mandatory-completion jobs and exactly one real claim, rather than incorrectly treating a successor-start job as an automatic reward. No production quest/XP/account records modified by tests. +Retries drain bounded waves of queued jobs before recycling deferred predecessors. Blocked or failed starts move to deferred without changing their creation timestamp; completed jobs never requeue. This prevents twenty old blocked jobs from starving later players without adding a schema or claiming a retry timestamp is a creation time. + +Validation so far:60 local progression/game/POL tests passed, including unique next/no extra reward, forks/unrelated branches, all-predecessor gating/retry, failed issuance retaining committed reward, a twenty-blocked/one-eligible fairness regression and native response/forged-input coverage. Existing uncapped POL test now checks the absence of mandatory-completion jobs and exactly one real claim, rather than incorrectly treating a successor-start job as an automatic reward. No production quest/XP/account records modified by tests. Remaining acceptance: canonical Linux CI/build, focused source review, publication, live serving revision and ordinary user confirmation. This work is separate from the current pack incident; no draft code has been deployed. Existing pending gameplay producers are separate work and are not fabricated by automatic starting. diff --git a/website/node/progression-quests.mjs b/website/node/progression-quests.mjs index 6faec408..67051b0c 100644 --- a/website/node/progression-quests.mjs +++ b/website/node/progression-quests.mjs @@ -20,9 +20,13 @@ export function createQuestProgression(db,keys,{definitions=QUEST_DEFINITIONS,au // This runs after reward commit: issuing another key must never nest a key transaction. async function processNextQuests({accountId=null,parentId=null,actor=null}={}){ if(accountId!==null&&!uuid(accountId))throw TypeError('Invalid completion account'); - const args=[],where=["state='queued'",parentId?'purpose=?':"purpose LIKE 'quest-next:%'"]; + const args=[],where=[parentId?'purpose=?':"purpose LIKE 'quest-next:%'"]; if(parentId)args.push(nextPurpose(parentId));if(accountId){where.push('account_id=?');args.push(accountId);} - const jobs=await db.query('SELECT * FROM jarvis_progression_outbox WHERE '+where.join(' AND ')+' ORDER BY created_at,id LIMIT 20',args); + const scope=where.join(' AND '),select="SELECT * FROM jarvis_progression_outbox WHERE state='queued' AND "+scope+' ORDER BY created_at,id LIMIT 20'; + let jobs=await db.query(select,args); + // Drain each bounded wave before retrying blocked predecessors, so an old + // batch cannot starve later players. Keep the original creation timestamps. + if(!jobs.length){await db.query("UPDATE jarvis_progression_outbox SET state='queued' WHERE state='deferred' AND "+scope,args);jobs=await db.query(select,args);} const result={started:0,failed:0,pending:false,nextQuestId:null,choices:[]}; for(const job of jobs)try{ const current=actor?.id===job.account_id?actor:await resolvePlayer(job.account_id);if(!current)throw Error('Player unavailable'); @@ -39,8 +43,8 @@ export function createQuestProgression(db,keys,{definitions=QUEST_DEFINITIONS,au else if(!children.length)finish=true; else result.pending=true; } - if(finish)await db.query("UPDATE jarvis_progression_outbox SET state='completed' WHERE id=? AND state='queued'",[job.id]); - }catch{result.failed++;result.pending=true;} + await db.query("UPDATE jarvis_progression_outbox SET state=? WHERE id=? AND state='queued'",[finish?'completed':'deferred',job.id]); + }catch{result.failed++;result.pending=true;await db.query("UPDATE jarvis_progression_outbox SET state='deferred' WHERE id=? AND state='queued'",[job.id]);} return result; } async function player(actor,store=db){if(!uuid(actor?.id)||!await authorizePlayer(actor,store))throw Error('Current player identity required');} diff --git a/website/tests/progression-quests.test.mjs b/website/tests/progression-quests.test.mjs index 6dfce7bb..c2535769 100644 --- a/website/tests/progression-quests.test.mjs +++ b/website/tests/progression-quests.test.mjs @@ -86,3 +86,27 @@ test('next-key issuance failure preserves a successful reward and retries from d assert.equal((await f.db.query('SELECT * FROM jarvis_quest_states')).length,2);assert.equal((await f.db.query('SELECT * FROM jarvis_quest_claims')).length,1); }finally{f.db.close();} }); + +test('twenty blocked predecessor jobs cannot starve a later eligible retry',async()=>{ + const blocked=Array.from({length:20},(_,i)=>[ + {...definitions[0],id:`S1-BLOCK-${i}`,branch:`blocked-${i}`,metric:`blocked-${i}`,optional:true}, + {...definitions[1],id:`S1-CHILD-${i}`,branch:`blocked-${i}`,metric:`child-${i}`,requires:[`S1-BLOCK-${i}`,'S1-TEST-03'],optional:true} + ]).flat(); + const f=await fixture({questDefinitions:[...definitions,...blocked]});try{ + await f.db.query('UPDATE jarvis_progression_seasons SET level_cap=0'); + for(let i=0;i<20;i++){ + await f.observe(`blocked-${i}`,1); + await f.service.claim(f.people.Member,{definitionId:`S1-BLOCK-${i}`,revision:1,requestId:randomUUID()}); + } + f.failNextStarts(true);await f.observe('first',1); + await f.service.claim(f.people.Member,{definitionId:'S1-TEST-01',revision:1,requestId:randomUUID()});f.failNextStarts(false); + const jobs=await f.db.query("SELECT * FROM jarvis_progression_outbox WHERE purpose LIKE 'quest-next:%'");assert.equal(jobs.length,21); + for(const job of jobs)await f.db.query("UPDATE jarvis_progression_outbox SET state='queued',created_at=? WHERE id=?",[JSON.parse(job.payload_json).definitionId==='S1-TEST-01'?2:1,job.id]); + await f.service.processCompletions(); + assert.equal((await f.service.list(f.people.Member)).quests.find(q=>q.id==='S1-TEST-02').keyId,null); + assert.equal((await f.db.query("SELECT * FROM jarvis_progression_outbox WHERE state='deferred'")).length,20); + await f.service.processCompletions(); + assert.equal((await f.service.list(f.people.Member)).quests.find(q=>q.id==='S1-TEST-02').state,'active'); + assert.equal((await f.db.query('SELECT * FROM jarvis_quest_claims')).length,21); + }finally{f.db.close();} +}); -- 2.53.0 From 47fc12d44949a6e1773c3d6eb675869052e57d96 Mon Sep 17 00:00:00 2001 From: unimatrixgit <95320811+unimatrixgit@users.noreply.github.com> Date: Sun, 29 Nov 2026 09:09:32 +0100 Subject: [PATCH 2/2] Verify existing quest journeys after automatic successor starts --- website/tests/fremen-husbandry.test.mjs | 7 ++++--- website/tests/house-prologue.test.mjs | 2 +- website/tests/pol-system-issuer.test.mjs | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/website/tests/fremen-husbandry.test.mjs b/website/tests/fremen-husbandry.test.mjs index eda4998d..53cfd58d 100644 --- a/website/tests/fremen-husbandry.test.mjs +++ b/website/tests/fremen-husbandry.test.mjs @@ -130,9 +130,10 @@ test('cargo requires a sealed mission-bound parcel, distinct confirmed Guild arr await f.db.query(POL_CARGO_SCHEMA);await f.db.query(POL_COOP_CARGO_SCHEMA);f.db.polSupplyEnabled=true;const bankRows=[];const bank={query:async(sql,args)=>{assert.match(sql,/state='arrived'/);assert.equal(args[0],f.actor.id);assert.equal(args[2],'arrakis');return bankRows.filter(r=>r.arrived_at>=args[3]);}}; const clock=()=>f.base().occurredAt,cargo=createPOLCargoMissions(f.db,bank,f.keys,{clock}),api=createGameQuestsAPI(f.db,{GAME_LINK_SECRET:secret},{pol:f.runtime,cargo});const events=createGameQuestEventsAPI(f.db,f.keys,{GAME_LINK_SECRET:secret},{clock,cargo}); const post=(fn,path,body)=>fn(new Request('https://cp.dunerealms.com/internal/game/'+path,{method:'POST',headers:{authorization:'Bearer '+secret,'content-type':'application/json'},body:JSON.stringify(body)}));const send=body=>post(api,'quests',body),observe=body=>post(events,'quest-events',body); - const permit=await(await send({action:'prepare_pol_supply',uuid:f.uuid,kind:'pol',definitionId:'POL-FREMEN-01',requestId:randomUUID(),confirmed:true,server:'arrakis',npcUuid:randomUUID()})).json();assert.equal((await f.request({...f.base(),kind:'supply_water',eventId:supplyEvent('supply_water',permit.requestId)})).status,200);await f.runtime.quests.claim(f.actor,{definitionId:'POL-FREMEN-01',revision:1,requestId:randomUUID()}); + const permit=await(await send({action:'prepare_pol_supply',uuid:f.uuid,kind:'pol',definitionId:'POL-FREMEN-01',requestId:randomUUID(),confirmed:true,server:'arrakis',npcUuid:randomUUID()})).json();assert.equal((await f.request({...f.base(),kind:'supply_water',eventId:supplyEvent('supply_water',permit.requestId)})).status,200); const base={action:'prepare_pol_cargo',kind:'pol',uuid:f.uuid,definitionId:'POL-FREMEN-02',requestId:randomUUID(),confirmed:true,npcUuid:randomUUID()},seal={...base,phase:'seal',server:'lobby',npcRole:'edric'},deliver={...base,phase:'deliver',server:'arrakis',npcRole:'stilgar'}; - assert.equal((await send(seal)).status,409);await f.runtime.quests.start(f.actor,{definitionId:'POL-FREMEN-02'});assert.equal((await send({...seal,npcRole:'stilgar'})).status,409);const s=await send(seal);assert.equal(s.status,200,await s.clone().text());const sealed=await s.json();assert.equal(sealed.quantity,12);assert.equal((await(await send(seal)).json()).requestId,sealed.requestId); + assert.equal((await send(seal)).status,409);await f.runtime.quests.claim(f.actor,{definitionId:'POL-FREMEN-01',revision:1,requestId:randomUUID()}); + assert.equal((await f.runtime.quests.list(f.actor)).quests.find(q=>q.id==='POL-FREMEN-02').state,'active');assert.equal((await send({...seal,npcRole:'stilgar'})).status,409);const s=await send(seal);assert.equal(s.status,200,await s.clone().text());const sealed=await s.json();assert.equal(sealed.quantity,12);assert.equal((await(await send(seal)).json()).requestId,sealed.requestId); const sealReceipt={...f.base(),eventId:sealed.requestId,kind:'cargo_seal',server:'lobby'};assert.equal((await observe({...sealReceipt,server:'arrakis'})).status,409);assert.equal((await observe(sealReceipt)).status,200);assert.equal((await send(deliver)).status,409); f.advance(100);bankRows.push({id:randomUUID(),arrived_at:clock()});const d=await send(deliver);assert.equal(d.status,200,await d.clone().text());const delivered=await d.json();assert.equal(delivered.manifestId,sealed.manifestId);assert.notEqual(delivered.requestId,sealed.requestId); const finish={...f.base(),eventId:delivered.requestId,kind:'cargo_deliver',server:'arrakis'};assert.equal((await observe({...finish,uuid:f.otherUuid})).status,409);const r=await observe(finish);assert.equal(r.status,200,await r.clone().text());assert.equal((await observe(finish)).status,200);assert.equal((await f.runtime.quests.list(f.actor)).quests.find(q=>q.id==='POL-FREMEN-02').canClaim,true); @@ -257,4 +258,4 @@ test('Esmar introduction in the Guild grants a personal hour without refreshing f.advance(3595000);assert.equal(await permit(),null);await f.request({...f.base(),kind:'smuggler_introduction',server:'lobby'});assert.equal((await permit()).expiresAt,clock()+3600000); assert.equal(await activeSmugglerPermit(f.db,f.keys,f.other,f.otherUuid,clock()),null); }finally{f.db.close();} -}); \ No newline at end of file +}); diff --git a/website/tests/house-prologue.test.mjs b/website/tests/house-prologue.test.mjs index 9f1d6809..ad7213ec 100644 --- a/website/tests/house-prologue.test.mjs +++ b/website/tests/house-prologue.test.mjs @@ -22,7 +22,7 @@ test('new linked player must meet the matching lobby Mentat and obtain the origi assert.equal((await state()).ready,false);assert.equal((await old()).ready,true); assert.equal((await intro('piter_de_vries')).status,409);const response=await intro('thufir_hawat');assert.equal(response.status,200,await response.clone().text()); assert.equal((await state()).introduced,true);assert.equal((await state()).ready,false); - await runtime.collect(actor);let view=await runtime.quests.list(actor);assert.equal(view.quests.find(q=>q.id===HOUSE_PROLOGUE_IDS[0]).state,'claimed');assert.equal(view.quests.find(q=>q.id===HOUSE_PROLOGUE_IDS[1]).state,'not-started'); + await runtime.collect(actor);let view=await runtime.quests.list(actor);assert.equal(view.quests.find(q=>q.id===HOUSE_PROLOGUE_IDS[0]).state,'claimed');assert.equal(view.quests.find(q=>q.id===HOUSE_PROLOGUE_IDS[1]).state,'active');assert.equal(view.quests.find(q=>q.id===HOUSE_PROLOGUE_IDS[1]).canClaim,false); const producer={},events=createStarterKitEvents(f.db,f.keys,{clock,authorizeProducer:async who=>who===producer}); await events.record(producer,{eventId:randomUUID(),uuid,seasonId:'S01',kind:'acquired',occurredAt:now,kitInstanceId:randomUUID(),blueprintId:randomUUID(),blueprintVersion:1,faction:'atreides',snapshot:{name:'House starter',quality:'common',commerceKind:'faction_sale',color:'#336633',lore:['Original kit.'],equipment:defaultKitEquipment()},remainingDurabilityBps:5000}); assert.equal((await state()).ready,true);await runtime.collect(actor);await runtime.collect(actor);view=await runtime.quests.list(actor); diff --git a/website/tests/pol-system-issuer.test.mjs b/website/tests/pol-system-issuer.test.mjs index 4a305090..3acd4729 100644 --- a/website/tests/pol-system-issuer.test.mjs +++ b/website/tests/pol-system-issuer.test.mjs @@ -16,7 +16,7 @@ test('POL issuance binds a current SYS-ID; only trusted observations permit clai await runtime.quests.observe(trusted,observation);await runtime.quests.claim(f.people.Member,{definitionId:d.id,revision:1,requestId:randomUUID()}); assert.equal((await runtime.quests.list(f.people.Member)).profile.totalXP,d.xp); await f.db.query('UPDATE organisation_keys SET revoked_at=1 WHERE id=?',[issuer.keyId]);await assert.rejects(runtime.quests.start(f.people.Member,{definitionId:POL_QUEST_DEFINITIONS[1].id}),/review/); - assert.equal((await f.db.query('SELECT * FROM jarvis_pol_quest_issuers')).length,1); + const bindings=await f.db.query('SELECT * FROM jarvis_pol_quest_issuers');assert.equal(bindings.length,2);assert.ok(bindings.every(row=>row.issuer_key_id===issuer.keyId)); }finally{f.db.close();} }); -- 2.53.0