fix(sync): route sessions by server-confirmed directory, unstick queued sends
Session directory resolution had no precedence contract: the selection-time directory short-circuited every lookup, and a persisted runtime value was consulted before the authoritative record. A worktree session selected before its directory store bootstrapped kept the active-directory fallback, and that guess was persisted, so it survived reloads and restarts. Directory resolution now lives in one module and orders sources by whether the server confirmed the path, not by whether the value is local or synced: authoritative (the child store that holds the session) > server-confirmed selection > worktree attachment/metadata (the requested path, pre-canonical) > remembered. A guessed selection is no longer persisted, remembered, or ranked. Chips read the same resolution the composer used, so queue keys cannot diverge. Queued auto-send could strand an item indefinitely: backoff, missing send configuration, and the recent-abort window all returned without scheduling a wake-up, so the queue only retried when an unrelated status or directory change re-ran the effect. A retry scheduler now wakes it at the earliest known time. A rejected send rolls the optimistic message back while the composer stays silent for transport failures, which makes it indistinguishable from nothing happening. Failures are now recorded to a bounded in-memory log surfaced in the About diagnostics report, alongside a directory-resolution breakdown, plus __opencodeDebug.diagnoseSessionDirectory() and getRecentSendFailures(). Prompted by a report of worktree prompting silently failing. That failure was not reproduced locally, so the diagnostics are what will identify it.
This commit is contained in:
@@ -29,12 +29,61 @@ mock.module('@/sync/session-ui-store', () => ({
|
||||
|
||||
import {
|
||||
buildQueuedAutoSendPayload,
|
||||
createQueuedAutoSendRetryScheduler,
|
||||
getQueuedAutoSendRetryDelayMs,
|
||||
isQueuedAutoSendBackedOff,
|
||||
sendQueuedAutoSendPayload,
|
||||
shouldDispatchQueuedAutoSend,
|
||||
} from './useQueuedMessageAutoSend';
|
||||
|
||||
describe('queued auto-send retry scheduler', () => {
|
||||
test('wakes the queue when backoff expires', () => {
|
||||
const callbacks = new Map<number, () => void>();
|
||||
let nextTimer = 0;
|
||||
let wakeups = 0;
|
||||
const scheduler = createQueuedAutoSendRetryScheduler(
|
||||
() => { wakeups += 1; },
|
||||
() => 1_000,
|
||||
(callback, delay) => {
|
||||
callbacks.set(++nextTimer, callback);
|
||||
expect(delay).toBe(500);
|
||||
return nextTimer as unknown as ReturnType<typeof setTimeout>;
|
||||
},
|
||||
(timer) => { callbacks.delete(timer as unknown as number); },
|
||||
);
|
||||
|
||||
scheduler.schedule(1_500);
|
||||
expect(callbacks.size).toBe(1);
|
||||
callbacks.values().next().value?.();
|
||||
expect(wakeups).toBe(1);
|
||||
});
|
||||
|
||||
test('keeps the earliest retry and cancels it on dispose', () => {
|
||||
const callbacks = new Map<number, () => void>();
|
||||
let nextTimer = 0;
|
||||
const delays: number[] = [];
|
||||
const scheduler = createQueuedAutoSendRetryScheduler(
|
||||
() => undefined,
|
||||
() => 1_000,
|
||||
(callback, delay) => {
|
||||
callbacks.set(++nextTimer, callback);
|
||||
delays.push(delay);
|
||||
return nextTimer as unknown as ReturnType<typeof setTimeout>;
|
||||
},
|
||||
(timer) => { callbacks.delete(timer as unknown as number); },
|
||||
);
|
||||
|
||||
scheduler.schedule(3_000);
|
||||
scheduler.schedule(4_000);
|
||||
scheduler.schedule(2_000);
|
||||
|
||||
expect(delays).toEqual([2_000, 1_000]);
|
||||
expect(callbacks.size).toBe(1);
|
||||
scheduler.dispose();
|
||||
expect(callbacks.size).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('shouldDispatchQueuedAutoSend', () => {
|
||||
test('dispatches only after an active session becomes idle', () => {
|
||||
expect(shouldDispatchQueuedAutoSend('busy', 'idle', false)).toBe(true);
|
||||
|
||||
Reference in New Issue
Block a user