Rotate deferred quest successor retries without starving later players
This commit is contained in:
parent
ca5acc79b2
commit
d142317b18
3 changed files with 35 additions and 5 deletions
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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');}
|
||||
|
|
|
|||
|
|
@ -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();}
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue

Staff