fix(orbit): pending counter ignored merged/declined items

The "X / Y pending" counter in the queue head and the guest-side
gate-check both used `state.queue.filter(non-host).length`, which is the
*history* count — items the host has already approved or declined still
sit in `state.queue` for attribution lookup, so the counter never
decreased. Reported as "3 / 4 pending" with no actual rows in the
approval list.

The merged / declined sets only exist in the host's local store, so the
guest can't filter them out itself. Solution: the host writes an
authoritative `pendingApprovalCount` into the state blob each tick;
guests (and the host's own UI) read it directly, with a fallback to the
old over-counting behaviour for any older client that doesn't write the
field.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Psychotoxical
2026-04-25 01:30:57 +02:00
parent cfb7e7f6c1
commit 7c379c2111
4 changed files with 35 additions and 9 deletions
+8 -3
View File
@@ -480,9 +480,14 @@ export function evaluateOrbitSuggestGate(): { allowed: boolean; reason: OrbitSug
}
const cap = state.settings?.maxPending ?? 0;
if (cap > 0) {
const inState = state.queue.filter(q => q.addedBy !== state.host).length;
const total = inState + pendingSuggestions.length;
if (total >= cap) return { allowed: false, reason: 'cap-reached' };
// Prefer the host-pushed authoritative count when present; fall back to a
// raw queue scan for older hosts. Add the local guest's pending list on
// top — those are tracks the host hasn't swept in yet.
const knownPending = state.pendingApprovalCount
?? state.queue.filter(q => q.addedBy !== state.host).length;
if (knownPending + pendingSuggestions.length >= cap) {
return { allowed: false, reason: 'cap-reached' };
}
}
return { allowed: true, reason: null };
}