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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
address review (claude): close the disconnect window the token await opened, and keep the paste form reachable
[._.]/ Adam Eivy472dc0fb707e
diff --git a/client/src/pages/Media3D.jsx b/client/src/pages/Media3D.jsxindex 4405fbbd93..cbb24c4fdf 100644--- a/client/src/pages/Media3D.jsx+++ b/client/src/pages/Media3D.jsx@@ -34,13 +34,22 @@ const HF_GATED_MODELS = {// instead of instructions. Either way the gated repos stay listed: a token doesn't// grant access until their terms are accepted on the user's HF account.function HfAccessNotice({ models, tokenPresent, tokenSource, onSaved }) {+ // Escape hatch for the stale/invalid-token case: `isHfAuthError` in the runner+ // also matches `401` / `Invalid user token`, and its guidance now says to add a+ // token *on this page* — so the paste form has to stay reachable even when one is+ // already configured, or that instruction is impossible to follow here. Mirrors+ // MidiGatedModal's "Use a different token".+ const [replacing, setReplacing] = useState(false);+if (!models?.length) return null;// Status still loading (null) — don't flash a "needs setup" banner at a user who// already has a token.if (tokenPresent === null) return null;- if (!tokenPresent) {- return <HfTokenBanner models={models} onSaved={onSaved} />;+ const handleSaved = () => { setReplacing(false); onSaved?.(); };++ if (!tokenPresent || replacing) {+ return <HfTokenBanner models={models} onSaved={handleSaved} />;}return (@@ -55,6 +64,13 @@ function HfAccessNotice({ models, tokenPresent, tokenSource, onSaved }) {doesn’t grant access:</p><GatedModelList models={models} linkClassName="text-port-accent hover:underline" />+ <button+ type="button"+ onClick={() => setReplacing(true)}+ className="mt-2 text-xs underline text-gray-400 hover:text-white"+ >+ Use a different token+ </button></div>);}diff --git a/client/src/pages/Media3D.test.jsx b/client/src/pages/Media3D.test.jsxindex fbe5d5d3f0..5b17327826 100644--- a/client/src/pages/Media3D.test.jsx+++ b/client/src/pages/Media3D.test.jsx@@ -175,6 +175,16 @@ describe('Media3D — generation workspace', () => {expect(screen.getByRole('link', { name: /dinov3-vitl16-pretrain-lvd1689m/i })).toBeInTheDocument();});+ it('lets a user with a configured token reach the paste form to replace a stale one', async () => {+ // The runner's HF-auth guidance also fires on `401` / `Invalid user token` and+ // tells the user to add a token on THIS page — so the form must stay reachable+ // when one is already configured, or that instruction can't be followed here.+ getHfTokenStatus.mockResolvedValue({ hfTokenPresent: true, source: 'stored' });+ renderAt('/media/3d?image=example-robot.png');+ fireEvent.click(await screen.findByRole('button', { name: /use a different token/i }));+ expect(screen.getByPlaceholderText('hf_…')).toBeInTheDocument();+ });+it('shows neither the banner nor the confirmation while token status is still unknown', async () => {// Absent-vs-failed: a pending/failed status must not flash "add a token" at a user// who has one (nor claim one is configured).diff --git a/server/routes/imageTo3d.js b/server/routes/imageTo3d.jsindex 52418d99c3..6784e3efd7 100644--- a/server/routes/imageTo3d.js+++ b/server/routes/imageTo3d.js@@ -101,6 +101,23 @@ router.get('/trellis2/install', asyncHandler(async (req, res) => {const emit = (event) => { installLog.onEvent(event); send(event); };installLog.start();+ // Disconnect bookkeeping wired BEFORE the token-resolution await below (the+ // same hazard `lib/sseDownload.js` documents): that await does a settings read+ // plus a token-file read, and a client closing during it would otherwise land+ // with no listener — the handler would go on to spawn a ~15 GB clone with no+ // kill path, leaving `trellis2InstallInFlight` pinned until it finished on its+ // own and blocking every later Install click.+ let currentKill = null;+ let aborted = false;+ req.on('close', () => {+ aborted = true;+ installLog.cancel();+ // `close` also fires on normal completion; only a live handle means an+ // install was actually mid-flight.+ if (currentKill) currentKill();+ safeEnd();+ });+// Carry the stored HF token into the install too: setup.sh doesn't pull gated// weights today, but a future prefetch step would, and one env source beats two.// Guarded because the SSE headers are already flushed by this point — a throw@@ -115,11 +132,15 @@ router.get('/trellis2/install', asyncHandler(async (req, res) => {emit({ type: 'error', message: `Could not read settings to resolve the Hugging Face token: ${err.message}` });return safeEnd();}+ // The client hung up during the await — don't start a multi-GB install nobody+ // is listening to.+ if (aborted) return safeEnd();const { promise, kill } = installTrellis2({onEvent: emit,env: installEnv,});+ currentKill = kill;trellis2InstallInFlight = promise;promise.then(() => installLog.success())@@ -133,12 +154,10 @@ router.get('/trellis2/install', asyncHandler(async (req, res) => {emit({ type: 'error', message: `${err?.message || 'Install failed'}${hint}`, stage: err?.stage });}).finally(() => {+ currentKill = null;trellis2InstallInFlight = null;safeEnd();});-- // Cancel the (multi-GB) install if the client navigates away mid-bootstrap.- req.on('close', () => { installLog.cancel(); kill(); safeEnd(); });}));// ── Image-to-3D model records ─────────────────────────────────────────────diff --git a/server/routes/imageTo3d.test.js b/server/routes/imageTo3d.test.jsindex 6310fb1598..f7c872aeb7 100644--- a/server/routes/imageTo3d.test.js+++ b/server/routes/imageTo3d.test.js@@ -35,6 +35,13 @@ vi.mock('../services/imageTo3d/trellis2.js', () => ({}),}));+// The install route resolves the central HF token into the child env (#3032).+// Mock it so the suite never reads the host's real settings.json or+// ~/.cache/huggingface/token, and so the resolution-failure branch is drivable.+vi.mock('../lib/hfToken.js', () => ({+ hfTokenEnv: vi.fn(async () => ({ HF_TOKEN: 'hf_test', HUGGINGFACE_HUB_TOKEN: 'hf_test' })),+}));+vi.mock('../services/imageTo3d/models.js', () => ({listModels: vi.fn(),getModel: vi.fn(),@@ -47,6 +54,7 @@ vi.mock('../services/imageTo3d/models.js', () => ({import * as targets from '../services/imageTo3d/targets.js';import * as trellis2 from '../services/imageTo3d/trellis2.js';import * as models from '../services/imageTo3d/models.js';+import { hfTokenEnv } from '../lib/hfToken.js';import routes from './imageTo3d.js';const makeApp = () => {@@ -84,6 +92,35 @@ describe('GET /trellis2/install (SSE)', () => {expect(trellis2.installTrellis2).toHaveBeenCalled();});+ it('hands the resolved HF token env to the install child', async () => {+ // #3032: the install must carry the CENTRAL token (settings-stored included),+ // not just whatever the server process happened to be launched with.+ trellis2.installTrellis2.mockClear();+ trellis2.isTrellis2Installed.mockReturnValueOnce(false);+ targets.isTargetAvailable.mockReturnValueOnce(true);+ await request(makeApp()).get('/api/image-to-3d/trellis2/install');+ expect(trellis2.installTrellis2).toHaveBeenCalledWith(expect.objectContaining({+ env: expect.objectContaining({ HF_TOKEN: 'hf_test', HUGGINGFACE_HUB_TOKEN: 'hf_test' }),+ }));+ });++ it('emits a terminal error frame — not a half-open stream — when the token env cannot be resolved', async () => {+ // The SSE headers are already flushed by this point, so a throw here can't+ // reach the error middleware as JSON; it has to surface as an error frame.+ trellis2.installTrellis2.mockClear();+ trellis2.isTrellis2Installed.mockReturnValueOnce(false);+ targets.isTargetAvailable.mockReturnValueOnce(true);+ hfTokenEnv.mockRejectedValueOnce(new Error('settings.json is not valid JSON'));+ const res = await request(makeApp()).get('/api/image-to-3d/trellis2/install');+ const frames = sseFrames(res.text);+ expect(frames.at(-1)).toMatchObject({+ type: 'error',+ message: expect.stringMatching(/Hugging Face token/i),+ });+ // And no multi-GB install is started on a failed resolve.+ expect(trellis2.installTrellis2).not.toHaveBeenCalled();+ });+it('short-circuits with complete when already installed (no install spawned)', async () => {trellis2.installTrellis2.mockClear();trellis2.isTrellis2Installed.mockReturnValueOnce(true);