Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: preserve slow Three.js poll responses (#5498)

[._.]/ Adam Eivydef8748fdc24
diff --git a/client/src/pages/ThreejsModelDetail.jsx b/client/src/pages/ThreejsModelDetail.jsx
index d277f37115..ae1087daea 100644
--- a/client/src/pages/ThreejsModelDetail.jsx
+++ b/client/src/pages/ThreejsModelDetail.jsx
@@ -286,21 +286,27 @@ export default function ThreejsModelDetail() {
} = useProviderModels({ filter: providerFilter, silent: true, withEffort: true });
const mountedRef = useMounted();
- const loadGenerationRef = useRef(0);
+ const lifecycleGenerationRef = useRef(0);
+ const requestSequenceRef = useRef(0);
+ const lastAppliedRequestRef = useRef(0);
const load = useCallback(async ({ initial = false } = {}) => {
- const generation = ++loadGenerationRef.current;
- const isCurrent = () => mountedRef.current && generation === loadGenerationRef.current;
+ const lifecycleGeneration = lifecycleGenerationRef.current;
+ const requestSequence = ++requestSequenceRef.current;
+ const isCurrent = () => mountedRef.current && lifecycleGeneration === lifecycleGenerationRef.current;
+ const isAuthoritative = () => isCurrent() && requestSequence >= lastAppliedRequestRef.current;
if (initial && isCurrent()) {
setLoading(true);
setNotFound(false);
}
const next = await getThreejsModel(id, { silent: true }).catch((error) => {
- if (!isCurrent()) return null;
+ if (!isAuthoritative()) return null;
+ lastAppliedRequestRef.current = requestSequence;
if (error.status === 404) setNotFound(true);
else if (initial) toast.error(error.message || 'Failed to load model');
return null;
});
- if (!isCurrent()) return null;
+ if (!isAuthoritative()) return null;
+ lastAppliedRequestRef.current = requestSequence;
if (next) {
setRecord(next);
setNotFound(false);
@@ -310,9 +316,9 @@ export default function ThreejsModelDetail() {
}, [id, mountedRef]);
useEffect(() => {
- loadGenerationRef.current += 1;
+ lifecycleGenerationRef.current += 1;
void load({ initial: true });
- return () => { loadGenerationRef.current += 1; };
+ return () => { lifecycleGenerationRef.current += 1; };
}, [id, load]);
useEffect(() => {
@@ -320,7 +326,7 @@ export default function ThreejsModelDetail() {
const handle = setInterval(() => { void load(); }, 2_000);
return () => {
clearInterval(handle);
- loadGenerationRef.current += 1;
+ lifecycleGenerationRef.current += 1;
};
}, [record?.id, record?.status, id, load]);
diff --git a/client/src/pages/ThreejsModelDetail.test.jsx b/client/src/pages/ThreejsModelDetail.test.jsx
index 072dfda9d9..e426306715 100644
--- a/client/src/pages/ThreejsModelDetail.test.jsx
+++ b/client/src/pages/ThreejsModelDetail.test.jsx
@@ -108,6 +108,24 @@ describe('ThreejsModelDetail request lifecycle', () => {
expect(screen.queryByText('Model A')).not.toBeInTheDocument();
});
+ it('does not starve a slow poll when the next interval tick starts', async () => {
+ vi.useFakeTimers();
+ const initial = deferred();
+ const slowPoll = deferred();
+ const laterPoll = deferred();
+ const requests = [initial, slowPoll, laterPoll];
+ getThreejsModel.mockImplementation(() => requests.shift().promise);
+ renderDetail(['/media/threejs/model-a']);
+
+ await act(async () => { initial.resolve({ ...baseRecord, id: 'model-a', name: 'Model A', status: 'generating' }); });
+ await act(async () => { vi.advanceTimersByTime(4_000); });
+ await act(async () => { slowPoll.resolve({ ...baseRecord, id: 'model-a', name: 'Model A', status: 'ready' }); });
+ expect(screen.getByText('ready', { exact: true })).toBeInTheDocument();
+
+ await act(async () => { laterPoll.resolve({ ...baseRecord, id: 'model-a', name: 'Model A', status: 'generating' }); });
+ expect(screen.getByText('ready', { exact: true })).toBeInTheDocument();
+ });
+
it('keeps a newer terminal poll result authoritative over an older generating response', async () => {
vi.useFakeTimers();
const initial = deferred();