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

feat: derive privacy broker manual actions from server allowedTransitions (#2417)

Adam Eivy2963d82e3d21
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index c8ad75087d..6afb2cc712 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -6,6 +6,8 @@
## Fixes
+- **Privacy broker case actions are now rendered from the server's state machine, so the UI can't offer an illegal transition.** The drawer and the human-task digest strip used to decide which manual buttons to show from a hand-mirrored client map (`MANUAL_DONE_ACTION`) of the server's `STATE_TRANSITIONS` — a copy that could silently drift (the original bug: a "Mark submitted" button on blocked cases, where `blocked → submitted` is not a legal transition, so it always failed). Case payloads and digest items now carry a server-derived `allowedTransitions` list (computed from the same rules `assertTransition` enforces, folding in the any-state `human_task_queued` special case and excluding the rescan-only `confirmed_removed`/`reappeared` targets a human can't initiate). Both action strips render from a shared `state → { target, label, tone }` presentation table (`CASE_ACTIONS`, labels/tones stay UI concerns) filtered by that list, so an action whose target the server doesn't consider legal structurally cannot render.
+
- **HuggingFace model downloads (Flux and every other image/video/music pull) now log to the server console.** Triggering a base-model download showed a progress bar in the UI but left no trace in the server log — the entire download path emitted progress *only* over the SSE stream to the browser, and PortOS has no HTTP access logger, so a headless/PM2 log had no record the multi-GB fetch ever ran. The shared SSE driver (`server/lib/sseDownload.js#startHfDownloadStream`, the single chokepoint behind the image, video, and music download endpoints) now writes single-line, emoji-prefixed log lines for the start of each repo pull (`⬇️`, with a forced-re-fetch marker), each file as it streams, a cache hit that skips the download (`📦`), the outcome (`✅` complete with byte count / `❌` failed with the error message), and client-disconnect cancellation (`🛑`) — while cancelled results are deliberately not logged as failures.
- **Audio → MIDI transcription now prompts for HuggingFace access instead of dead-ending on a gated-repo traceback.** MuScriptor's model weights turned out to live in a *gated* HuggingFace repo (`MuScriptor/muscriptor-*`), so the first transcription on a fresh install — even right after the runtime auto-installs — 403'd with a raw `GatedRepoError: Access to model … is restricted` traceback the user couldn't act on. The MuScriptor sidecar now runs under the shared `install_hf_error_handler` (the same cause-chain walker the image/video runners use), so a gated download emits a structured `USER_ERROR:gated_repo:<repo>` marker; the server classifies that into a typed `gated_repo` SSE frame (carrying the repo id), and the client opens the same license-accept + token-paste prompt the gated image models use (reusing `HfTokenBanner`): accept the model's license, paste a HuggingFace read token, and the transcription you originally asked for re-runs automatically. Gated-error detection is now shared via `isGatedRepoError`/`extractGatedRepo` in `server/lib/hfErrors.js` (also adopted by the image runner's prose fallback).
diff --git a/client/src/components/privacy/BrokerCaseDrawer.jsx b/client/src/components/privacy/BrokerCaseDrawer.jsx
index 17ec4c21a5..fb60d093f0 100644
--- a/client/src/components/privacy/BrokerCaseDrawer.jsx
+++ b/client/src/components/privacy/BrokerCaseDrawer.jsx
@@ -1,7 +1,10 @@
import { RotateCw, ExternalLink, CheckCircle2, XCircle, ListChecks } from 'lucide-react';
import Drawer from '../Drawer';
import { timeAgo, formatDateShort } from '../../utils/formatters';
-import { CASE_STATE_TONE, MANUAL_DONE_ACTION, labelFor, CASE_STATES } from './constants';
+import { CASE_STATE_TONE, ACTION_TONES, manualCaseActions, labelFor, CASE_STATES } from './constants';
+
+// Action icon by descriptor `icon` token (positive resolution vs dismiss).
+const ACTION_ICONS = { check: CheckCircle2, x: XCircle };
// Read-only case inspector + manual controls (issue #2146). Deep-linked open
// state is owned by the parent (a `?case=<id>` search param), so this component
@@ -20,13 +23,13 @@ export default function BrokerCaseDrawer({
const optoutUrl = broker?.optout?.url || evidence.optout_url || null;
const searchUrl = evidence.search_url || null;
- // Which manual transitions make sense from the current state. The positive
- // resolution per state (and its legality) lives in MANUAL_DONE_ACTION —
- // shared with the digest strip so the two can't drift.
+ // Which manual transitions make sense from the current state. The action
+ // descriptors (label/tone/icon) live in the shared CASE_ACTIONS presentation
+ // table; legality is gated by the server-supplied `allowedTransitions`, so the
+ // drawer and digest strip can't drift from the server's state machine.
const state = caseData?.state;
const isBlocked = state === 'blocked';
- const doneAction = MANUAL_DONE_ACTION[state];
- const canDismiss = state === 'human_task_queued' || state === 'blocked' || state === 'found' || state === 'indirect_exposure';
+ const actions = manualCaseActions(state, caseData?.allowedTransitions);
const Row = ({ label, children }) => (
<div className="flex flex-col gap-0.5">
@@ -143,24 +146,19 @@ export default function BrokerCaseDrawer({
>
<RotateCw size={14} /> Force re-check
</button>
- {doneAction && (
- <button
- onClick={() => onTransition?.(caseData, doneAction.target)}
- disabled={busy}
- className={`inline-flex items-center gap-1.5 px-3 py-2 text-sm rounded border ${doneAction.buttonTone} disabled:opacity-50`}
- >
- <CheckCircle2 size={14} /> {doneAction.label}
- </button>
- )}
- {canDismiss && (
- <button
- onClick={() => onTransition?.(caseData, 'not_found')}
- disabled={busy}
- className="inline-flex items-center gap-1.5 px-3 py-2 text-sm rounded border border-port-border text-gray-400 hover:text-white hover:bg-port-card disabled:opacity-50"
- >
- <XCircle size={14} /> Dismiss (not found)
- </button>
- )}
+ {actions.map((action) => {
+ const Icon = ACTION_ICONS[action.icon] || CheckCircle2;
+ return (
+ <button
+ key={action.target}
+ onClick={() => onTransition?.(caseData, action.target)}
+ disabled={busy}
+ className={`inline-flex items-center gap-1.5 px-3 py-2 text-sm rounded border ${ACTION_TONES[action.tone]?.button || ''} disabled:opacity-50`}
+ >
+ <Icon size={14} /> {action.label}
+ </button>
+ );
+ })}
{optoutUrl && (
<a
href={optoutUrl}
diff --git a/client/src/components/privacy/BrokerCaseDrawer.test.jsx b/client/src/components/privacy/BrokerCaseDrawer.test.jsx
index 7f9ba4f996..c88be73c46 100644
--- a/client/src/components/privacy/BrokerCaseDrawer.test.jsx
+++ b/client/src/components/privacy/BrokerCaseDrawer.test.jsx
@@ -52,3 +52,28 @@ describe('BrokerCaseDrawer — human task case', () => {
expect(onTransition).toHaveBeenCalledWith(kase, 'submitted');
});
});
+
+describe('BrokerCaseDrawer — server allowedTransitions gating (issue #2417)', () => {
+ it('renders only actions whose target is in the server-supplied allowedTransitions', () => {
+ // A blocked case whose server list omits `found` must NOT render "I'm listed"
+ // even though the curated presentation table lists it — the UI can only offer
+ // what the server says is legal.
+ renderDrawer({
+ id: 'b1', brokerId: 'rad', brokerName: 'Radaris', state: 'blocked',
+ allowedTransitions: ['not_found', 'human_task_queued'],
+ evidence: { match_basis: 'antibot_wall' },
+ });
+ expect(screen.queryByRole('button', { name: /i'm listed/i })).toBeNull();
+ expect(screen.getByRole('button', { name: /dismiss/i })).toBeTruthy();
+ });
+
+ it('renders both curated actions when the server list allows them', () => {
+ renderDrawer({
+ id: 'b1', brokerId: 'rad', brokerName: 'Radaris', state: 'blocked',
+ allowedTransitions: ['found', 'not_found', 'human_task_queued'],
+ evidence: { match_basis: 'antibot_wall' },
+ });
+ expect(screen.getByRole('button', { name: /i'm listed/i })).toBeTruthy();
+ expect(screen.getByRole('button', { name: /dismiss/i })).toBeTruthy();
+ });
+});
diff --git a/client/src/components/privacy/PrivacyBrokersTab.jsx b/client/src/components/privacy/PrivacyBrokersTab.jsx
index 816f0eec21..3ff3a83c73 100644
--- a/client/src/components/privacy/PrivacyBrokersTab.jsx
+++ b/client/src/components/privacy/PrivacyBrokersTab.jsx
@@ -15,9 +15,12 @@ import { timeAgo, formatDateShort } from '../../utils/formatters';
import BrokerCaseDrawer from './BrokerCaseDrawer';
import {
CASE_STATES, CASE_STATE_TONE, EXPOSURE_MAP_STATES, BROKER_SOURCES, BROKER_CONFIDENCE,
- MANUAL_DONE_ACTION, labelFor,
+ ACTION_TONES, manualCaseActions, labelFor,
} from './constants';
+// Digest action icon by descriptor `icon` token (positive resolution vs dismiss).
+const ACTION_ICONS = { check: CheckCircle2, x: XCircle };
+
// Stat chip for the exposure-map header.
function StatChip({ label, count, tone }) {
return (
@@ -280,17 +283,14 @@ export default function PrivacyBrokersTab() {
<ExternalLink size={15} />
</a>
)}
- {(() => {
- const done = MANUAL_DONE_ACTION[item.state] || MANUAL_DONE_ACTION.human_task_queued;
+ {manualCaseActions(item.state, item.allowedTransitions).map((action) => {
+ const Icon = ACTION_ICONS[action.icon] || CheckCircle2;
return (
- <button onClick={() => doTransition({ id: item.caseId }, done.target)} disabled={caseBusy} title={done.label} aria-label={done.label} className={`p-1.5 rounded ${done.chipTone} disabled:opacity-50`}>
- <CheckCircle2 size={15} />
+ <button key={action.target} onClick={() => doTransition({ id: item.caseId }, action.target)} disabled={caseBusy} title={action.label} aria-label={action.label} className={`p-1.5 rounded ${ACTION_TONES[action.tone]?.chip || ''} disabled:opacity-50`}>
+ <Icon size={15} />
</button>
);
- })()}
- <button onClick={() => doTransition({ id: item.caseId }, 'not_found')} disabled={caseBusy} title="Dismiss" aria-label="Dismiss" className="p-1.5 rounded text-gray-400 hover:text-white hover:bg-port-border/50 disabled:opacity-50">
- <XCircle size={15} />
- </button>
+ })}
</div>
</div>
))}
diff --git a/client/src/components/privacy/PrivacyBrokersTab.test.jsx b/client/src/components/privacy/PrivacyBrokersTab.test.jsx
index 0797bb5080..801f7cdc99 100644
--- a/client/src/components/privacy/PrivacyBrokersTab.test.jsx
+++ b/client/src/components/privacy/PrivacyBrokersTab.test.jsx
@@ -25,8 +25,8 @@ const api = vi.hoisted(() => ({
humanTasks: 1,
blocked: 1,
items: [
- { caseId: 'h1', brokerId: 'bv', brokerName: 'BeenVerified', state: 'human_task_queued', reason: 'human_only_channel' },
- { caseId: 'b1', brokerId: 'rad', brokerName: 'Radaris', state: 'blocked', reason: 'antibot_wall', searchUrl: 'https://rad/p/Jane/Doe/' },
+ { caseId: 'h1', brokerId: 'bv', brokerName: 'BeenVerified', state: 'human_task_queued', allowedTransitions: ['submitted', 'not_found', 'human_task_queued'], reason: 'human_only_channel' },
+ { caseId: 'b1', brokerId: 'rad', brokerName: 'Radaris', state: 'blocked', allowedTransitions: ['found', 'not_found', 'human_task_queued'], reason: 'antibot_wall', searchUrl: 'https://rad/p/Jane/Doe/' },
],
},
schedule: { enabled: false, cronExpression: '0 4 * * 0', autoApproveOptOutEmails: false, autoSubmitWebForms: false, nextRun: null },
diff --git a/client/src/components/privacy/constants.js b/client/src/components/privacy/constants.js
index 1fdc688412..855ddf812b 100644
--- a/client/src/components/privacy/constants.js
+++ b/client/src/components/privacy/constants.js
@@ -131,27 +131,60 @@ export const EXPOSURE_MAP_STATES = [
'blocked', 'human_task_queued', 'not_found',
];
-// Positive-resolution action for the case states a human resolves by hand
-// (drawer + digest action strips both render from this map, so the rule lives
-// in ONE place). Mirrors the server's STATE_TRANSITIONS legality
-// (privacyBrokers.js): blocked → submitted is NOT a legal transition — a
-// blocked case's positive outcome is a manual "I'm listed" (found), while a
-// queued human task's is "Mark done" (submitted).
-export const MANUAL_DONE_ACTION = {
- blocked: {
- target: 'found',
- label: "I'm listed",
- chipTone: 'text-port-error hover:bg-port-error/10',
- buttonTone: 'border-port-error/40 text-port-error hover:bg-port-error/10',
+// Manual case actions a human can take per state, as a PRESENTATION table
+// (labels/tones/icons are UI concerns). The drawer + digest action strips both
+// render from this table, so the rule lives in ONE place. Legality is NOT
+// hardcoded here: `manualCaseActions()` filters each entry against the case's
+// server-supplied `allowedTransitions` (derived from STATE_TRANSITIONS in
+// server/services/privacyBrokers.js), so the UI structurally cannot offer an
+// illegal transition or drift from the server. e.g. a blocked case's positive
+// outcome is "I'm listed" (→ found); blocked → submitted is not legal and the
+// server list simply never contains `submitted`, so it can never render.
+export const CASE_ACTIONS = {
+ blocked: [
+ { target: 'found', label: "I'm listed", tone: 'error', icon: 'check' },
+ { target: 'not_found', label: 'Dismiss (not found)', tone: 'muted', icon: 'x' },
+ ],
+ found: [
+ { target: 'not_found', label: 'Dismiss (not found)', tone: 'muted', icon: 'x' },
+ ],
+ indirect_exposure: [
+ { target: 'not_found', label: 'Dismiss (not found)', tone: 'muted', icon: 'x' },
+ ],
+ human_task_queued: [
+ { target: 'submitted', label: 'Mark done', tone: 'success', icon: 'check' },
+ { target: 'not_found', label: 'Dismiss (not found)', tone: 'muted', icon: 'x' },
+ ],
+};
+
+// Pre-composed Tailwind tone tokens per action tone (JIT needs whole classes).
+// `chip` = digest icon button, `button` = drawer labeled button.
+export const ACTION_TONES = {
+ error: {
+ chip: 'text-port-error hover:bg-port-error/10',
+ button: 'border-port-error/40 text-port-error hover:bg-port-error/10',
},
- human_task_queued: {
- target: 'submitted',
- label: 'Mark done',
- chipTone: 'text-port-success hover:bg-port-success/10',
- buttonTone: 'border-port-success/40 text-port-success hover:bg-port-success/10',
+ success: {
+ chip: 'text-port-success hover:bg-port-success/10',
+ button: 'border-port-success/40 text-port-success hover:bg-port-success/10',
+ },
+ muted: {
+ chip: 'text-gray-400 hover:text-white hover:bg-port-border/50',
+ button: 'border-port-border text-gray-400 hover:text-white hover:bg-port-card',
},
};
+// The manual action descriptors the UI may render for a case, gated by the
+// server-supplied `allowedTransitions` so an illegal/absent transition is never
+// offered. If `allowedTransitions` is absent (older payload / stale cached
+// client), fall back to the curated table as-is — every curated entry is legal
+// by construction, so this is a safe best-effort, not a legality bypass.
+export function manualCaseActions(state, allowedTransitions) {
+ const actions = CASE_ACTIONS[state] || [];
+ if (!Array.isArray(allowedTransitions)) return actions;
+ return actions.filter((a) => allowedTransitions.includes(a.target));
+}
+
export const BROKER_SOURCES = [
{ id: 'curated', label: 'Curated' },
{ id: 'badbool', label: 'BADBOOL' },
diff --git a/server/services/privacyBrokers.js b/server/services/privacyBrokers.js
index 0902948989..e0866e49ab 100644
--- a/server/services/privacyBrokers.js
+++ b/server/services/privacyBrokers.js
@@ -125,6 +125,28 @@ export function assertTransition(from, to, { viaRescan = false } = {}) {
}
}
+/**
+ * The manual (non-rescan, human-initiable) target states legally reachable from
+ * `state`, derived from the SAME rules `assertTransition` enforces so the two
+ * can't drift. Folds in the special cases: `human_task_queued` is reachable from
+ * ANY state (queue-a-human), while `confirmed_removed` and `reappeared` are
+ * rescan-only and therefore intentionally EXCLUDED — a person can't initiate
+ * them from the UI (only a verifying re-scan can). Drops the idempotent
+ * self-transition. Returned in canonical `CASE_STATES` order.
+ *
+ * This is the authoritative list the client action strips filter against, so the
+ * UI structurally cannot offer an illegal transition (the original blocked →
+ * submitted bug) and cannot drift from the server's state machine.
+ */
+export function allowedTransitionsFor(state) {
+ const reachable = new Set(STATE_TRANSITIONS[state] || []);
+ reachable.add('human_task_queued'); // any state → human-task digest
+ reachable.delete(state); // no idempotent self-transition
+ reachable.delete('confirmed_removed'); // rescan-only, not human-initiable
+ reachable.delete('reappeared'); // rescan-only, not human-initiable
+ return CASE_STATES.filter((s) => reachable.has(s));
+}
+
/** ISO timestamp for the next recheck given the state (state-dependent backoff). */
export function computeNextRecheckAt(state, now = new Date()) {
const days = RECHECK_BACKOFF_DAYS[state] ?? 14;
@@ -380,6 +402,9 @@ function rowToCase(row) {
id: row.id,
brokerId: row.broker_id,
state: row.state,
+ // Server-derived legal manual moves for this state — the client action
+ // strips render only actions whose target is in this list (issue #2417).
+ allowedTransitions: allowedTransitionsFor(row.state),
found: row.found ?? null,
evidence: row.evidence ?? {},
disclosedFields: row.disclosed_fields ?? [],
diff --git a/server/services/privacyBrokers.test.js b/server/services/privacyBrokers.test.js
index 0ebe8d6132..3a96a3c8a4 100644
--- a/server/services/privacyBrokers.test.js
+++ b/server/services/privacyBrokers.test.js
@@ -9,6 +9,7 @@ import {
CASE_STATES,
SCAN_VERDICTS,
assertTransition,
+ allowedTransitionsFor,
computeNextRecheckAt,
parseCaRegistryCsv,
parseBadboolList,
@@ -93,6 +94,51 @@ describe('assertTransition — invalid transitions rejected', () => {
});
});
+describe('allowedTransitionsFor — client action gating (issue #2417)', () => {
+ it('never returns a target assertTransition would reject as a manual move', () => {
+ // The list is the authority the UI filters against, so every entry MUST be a
+ // legal non-rescan transition from that state.
+ for (const from of CASE_STATES) {
+ for (const to of allowedTransitionsFor(from)) {
+ expect(() => assertTransition(from, to)).not.toThrow();
+ }
+ }
+ });
+
+ it('excludes the rescan-only targets (confirmed_removed, reappeared)', () => {
+ for (const from of CASE_STATES) {
+ const allowed = allowedTransitionsFor(from);
+ expect(allowed).not.toContain('confirmed_removed');
+ expect(allowed).not.toContain('reappeared');
+ }
+ });
+
+ it('offers human_task_queued from every OTHER state, never itself', () => {
+ for (const from of CASE_STATES) {
+ const allowed = allowedTransitionsFor(from);
+ expect(allowed).not.toContain(from); // no idempotent self
+ if (from !== 'human_task_queued') expect(allowed).toContain('human_task_queued');
+ }
+ });
+
+ it('gives blocked its legal positive move (found) but NOT submitted (the classic hole)', () => {
+ const allowed = allowedTransitionsFor('blocked');
+ expect(allowed).toContain('found');
+ expect(allowed).toContain('not_found');
+ expect(allowed).not.toContain('submitted');
+ });
+
+ it('lets a queued human task be marked submitted or dismissed to not_found', () => {
+ const allowed = allowedTransitionsFor('human_task_queued');
+ expect(allowed).toContain('submitted');
+ expect(allowed).toContain('not_found');
+ });
+
+ it('returns only the any-state target for an unknown state', () => {
+ expect(allowedTransitionsFor('bogus')).toEqual(['human_task_queued']);
+ });
+});
+
describe('computeNextRecheckAt — state-dependent backoff', () => {
const now = new Date('2026-07-08T00:00:00.000Z');
const days = (state) => (new Date(computeNextRecheckAt(state, now)) - now) / (24 * 60 * 60 * 1000);
diff --git a/server/services/privacyOptOut.js b/server/services/privacyOptOut.js
index b07da5b5d5..aba66e4c29 100644
--- a/server/services/privacyOptOut.js
+++ b/server/services/privacyOptOut.js
@@ -524,6 +524,9 @@ export async function getOptOutDigest() {
brokerId: c.brokerId,
brokerName: c.brokerName,
state: c.state,
+ // Passed through from listBrokerCases' rowToCase (server-derived legal
+ // manual moves) so the digest action strip filters the same as the drawer.
+ allowedTransitions: c.allowedTransitions,
reason: c.reason || null,
channel: c.channel || null,
disclosedFields: c.disclosedFields || [],
diff --git a/server/services/privacyOptOut.test.js b/server/services/privacyOptOut.test.js
index 4a3352fd4b..3b93e8d57d 100644
--- a/server/services/privacyOptOut.test.js
+++ b/server/services/privacyOptOut.test.js
@@ -306,8 +306,8 @@ describe('runVerificationPass', () => {
describe('getOptOutDigest', () => {
it('aggregates human-task + blocked cases with playbook + reason', async () => {
listBrokerCases.mockImplementation(async ({ state } = {}) => {
- if (state === 'human_task_queued') return [{ id: 'h1', brokerId: 'wp', brokerName: 'Whitepages', state, reason: 'auto_submit_disabled', evidence: { optout_url: 'https://wp/o', playbook: ['call back'] } }];
- if (state === 'blocked') return [{ id: 'b1', brokerId: 'rad', brokerName: 'Radaris', state, reason: 'antibot_wall', evidence: { search_url: 'https://rad/p/Jane/Doe/' } }];
+ if (state === 'human_task_queued') return [{ id: 'h1', brokerId: 'wp', brokerName: 'Whitepages', state, allowedTransitions: ['submitted', 'not_found', 'human_task_queued'], reason: 'auto_submit_disabled', evidence: { optout_url: 'https://wp/o', playbook: ['call back'] } }];
+ if (state === 'blocked') return [{ id: 'b1', brokerId: 'rad', brokerName: 'Radaris', state, allowedTransitions: ['found', 'not_found', 'human_task_queued'], reason: 'antibot_wall', evidence: { search_url: 'https://rad/p/Jane/Doe/' } }];
return [];
});
const digest = await getOptOutDigest();
@@ -315,6 +315,10 @@ describe('getOptOutDigest', () => {
expect(digest.humanTasks).toBe(1);
expect(digest.blocked).toBe(1);
expect(digest.items[0].playbook).toEqual(['call back']);
+ // Server-derived legal moves pass through so the digest strip filters the
+ // same as the drawer (issue #2417).
+ expect(digest.items[0].allowedTransitions).toEqual(['submitted', 'not_found', 'human_task_queued']);
+ expect(digest.items[1].allowedTransitions).toEqual(['found', 'not_found', 'human_task_queued']);
// Blocked items surface the filled search URL for a manual browser check.
expect(digest.items[1].searchUrl).toBe('https://rad/p/Jane/Doe/');
});