Feature 13 integration fix 2: report a failed batch on deck load (#112)
CI / ci (push) Successful in 2m43s
CI / ci (pull_request) Successful in 2m43s

Co-authored-by: orchestrator-agent <20+orchestrator-agent@code.cubecraftcreations.com>
This commit was merged in pull request #112.
This commit is contained in:
2026-10-07 05:47:21 -04:00
committed by approver_agent
parent a05d57cb2e
commit b087f3a427
11 changed files with 259 additions and 47 deletions
+20 -14
View File
@@ -95,25 +95,31 @@ export function DiscoverPage() {
const questLog = useQuestLog()
const decision = useDecide()
const startBatch = useStartBatch()
// The job of the batch last known to be finding Side quests: the one Get
// more now started or joined, the replenish a decision started or joined,
// or the deck's active batch, which may have been started elsewhere or
// before the page opened.
// The job of the batch last known to be finding Side quests, or to have
// failed to: the one Get more now started or joined, the replenish a
// decision started or joined, or the deck's active or failed batch, which
// may have been started elsewhere or before the page opened.
const [batchJobId, setBatchJobId] = useState<string | null>(null)
// A read of the deck reporting a new active batch follows its job from
// that render on; one reporting none leaves the last job followed, so its
// end and any failure stay shown.
const activeJobId = deck.data?.activeBatch?.job_id ?? null
const [seenActiveJobId, setSeenActiveJobId] = useState<string | null>(null)
if (activeJobId !== seenActiveJobId) {
setSeenActiveJobId(activeJobId)
if (activeJobId !== null) setBatchJobId(activeJobId)
}
const job = useJob<unknown>(BATCH_JOB_KIND, batchJobId)
// A read of the deck reporting a new active or failed batch follows its
// job from that render on. One reporting neither leaves the last job
// followed, so its end stays shown — unless that job is known to have
// failed, by its poll or the deck's last read: the deck reports the newest
// batch's failure, so a later batch has superseded it, and it goes.
const failedJobId = deck.data?.failedBatch?.job_id ?? null
const deckJobId = deck.data?.activeBatch?.job_id ?? failedJobId
const [seenRead, setSeenRead] = useState({ at: 0, jobId: null as string | null, failedJobId: null as string | null })
if (deck.dataUpdatedAt !== seenRead.at) {
setSeenRead({ at: deck.dataUpdatedAt, jobId: deckJobId, failedJobId })
if (deckJobId !== null && deckJobId !== seenRead.jobId) setBatchJobId(deckJobId)
else if (deckJobId === null && batchJobId !== null && (job.status === 'failed' || batchJobId === seenRead.failedJobId)) setBatchJobId(null)
}
const top = cards?.[0]
const [busy, setBusy] = useState(false)
const jobRunning = batchJobId !== null && job.status !== 'succeeded' && job.status !== 'failed'
// The deck's failed batch is not finding anything, even before its job's
// first poll says why it failed.
const jobRunning = batchJobId !== null && batchJobId !== failedJobId && job.status !== 'succeeded' && job.status !== 'failed'
const finding = startBatch.isPending || jobRunning
const { mutate: mutateStartBatch } = startBatch
const getMore = useCallback(() => mutateStartBatch(undefined, { onSuccess: (b) => setBatchJobId(b.job_id) }), [mutateStartBatch])