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

address review (round 10): ship limits on response, explicit 400 in tests

Adam Eivyb46ffda51cff
diff --git a/client/src/components/dashboard/LayoutEditor.jsx b/client/src/components/dashboard/LayoutEditor.jsx
index 0d65798ba4..8ee46b715e 100644
--- a/client/src/components/dashboard/LayoutEditor.jsx
+++ b/client/src/components/dashboard/LayoutEditor.jsx
@@ -8,7 +8,13 @@ import toast from '../ui/Toast';
// Keyboard-first editor. No drag-and-drop dep — reorder uses up/down buttons
// (keyboard + touch friendly). Delete and "save as new" use inline state
// instead of window.confirm/prompt per project convention.
-export default function LayoutEditor({ layouts, activeLayoutId, onClose, onSave, onDelete, onDuplicate }) {
+// Fallback if the server didn't return limits (shouldn't happen, but keeps
+// the editor functional in degraded states). Kept in sync with the server's
+// ID_MAX_LENGTH by convention — the server value is authoritative.
+const FALLBACK_ID_MAX = 60;
+
+export default function LayoutEditor({ layouts, activeLayoutId, limits, onClose, onSave, onDelete, onDuplicate }) {
+ const idMax = limits?.idMaxLength || FALLBACK_ID_MAX;
const [editingId, setEditingId] = useState(activeLayoutId);
const editing = layouts.find((l) => l.id === editingId);
const [widgets, setWidgets] = useState(editing?.widgets ?? []);
@@ -81,16 +87,14 @@ export default function LayoutEditor({ layouts, activeLayoutId, onClose, onSave,
const commitDuplicate = async () => {
const trimmed = dupName.trim();
if (!trimmed) { toast.error('Name required'); return; }
- // Server idSchema caps ids at 60 chars. Compute the final id in a way
- // that always fits regardless of how many collisions we walk through —
- // the suffix grows (-2, -10, -100) so we trim the base per-iteration.
- const ID_MAX = 60;
+ // Final id must fit the server's idMax. Suffix grows with collisions
+ // (-2, -10, -100) so the base is trimmed per iteration.
const baseSlug = trimmed.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '');
if (!baseSlug) { toast.error('Use letters/numbers in the name'); return; }
const fitId = (n) => {
- if (n <= 1) return baseSlug.slice(0, ID_MAX);
+ if (n <= 1) return baseSlug.slice(0, idMax);
const suffix = `-${n}`;
- return `${baseSlug.slice(0, ID_MAX - suffix.length)}${suffix}`;
+ return `${baseSlug.slice(0, idMax - suffix.length)}${suffix}`;
};
const existingIds = new Set(layouts.map((l) => l.id));
let n = 1;
diff --git a/client/src/pages/Dashboard.jsx b/client/src/pages/Dashboard.jsx
index e4a2cfc2f5..74f2e181bb 100644
--- a/client/src/pages/Dashboard.jsx
+++ b/client/src/pages/Dashboard.jsx
@@ -20,6 +20,7 @@ export default function Dashboard() {
const [layouts, setLayouts] = useState([]);
const [layoutsLoading, setLayoutsLoading] = useState(true);
+ const [layoutLimits, setLayoutLimits] = useState(null);
const [activeLayoutId, setActiveLayoutId] = useState(null);
const [editorOpen, setEditorOpen] = useState(false);
@@ -48,6 +49,7 @@ export default function Dashboard() {
.then((data) => {
setLayouts(data.layouts);
setActiveLayoutId(data.activeLayoutId);
+ if (data.limits) setLayoutLimits(data.limits);
setLayoutsError(null);
})
.catch((err) => setLayoutsError(err.message))
@@ -206,6 +208,7 @@ export default function Dashboard() {
<LayoutEditor
layouts={layouts}
activeLayoutId={activeLayoutId}
+ limits={layoutLimits}
onClose={() => setEditorOpen(false)}
onSave={saveLayout}
onDelete={deleteLayoutById}
diff --git a/server/routes/dashboardLayouts.test.js b/server/routes/dashboardLayouts.test.js
index 22cd32485a..f15164d2d1 100644
--- a/server/routes/dashboardLayouts.test.js
+++ b/server/routes/dashboardLayouts.test.js
@@ -90,7 +90,7 @@ describe('PUT /api/dashboard/layouts/:id', () => {
const res = await request(makeApp())
.put('/api/dashboard/layouts/NotKebab')
.send({ name: 'x', widgets: [] });
- expect(res.status).toBeGreaterThanOrEqual(400);
+ expect(res.status).toBe(400);
expect(svc.saveLayout).not.toHaveBeenCalled();
});
@@ -98,7 +98,7 @@ describe('PUT /api/dashboard/layouts/:id', () => {
const res = await request(makeApp())
.put('/api/dashboard/layouts/my-custom')
.send({ name: 'Custom', widgets: ['apps', 'cos', 'apps'] });
- expect(res.status).toBeGreaterThanOrEqual(400);
+ expect(res.status).toBe(400);
expect(svc.saveLayout).not.toHaveBeenCalled();
});
});
@@ -108,8 +108,7 @@ describe('PUT /api/dashboard/layouts/active — id validation', () => {
const res = await request(makeApp())
.put('/api/dashboard/layouts/active')
.send({ id: 'Not_Kebab' });
- expect(res.status).toBeGreaterThanOrEqual(400);
- expect(res.status).toBeLessThan(500);
+ expect(res.status).toBe(400);
expect(svc.setActiveLayout).not.toHaveBeenCalled();
});
});
diff --git a/server/services/dashboardLayouts.js b/server/services/dashboardLayouts.js
index ea16651c88..f6d73853ff 100644
--- a/server/services/dashboardLayouts.js
+++ b/server/services/dashboardLayouts.js
@@ -98,6 +98,15 @@ const sanitizeLayout = (l) => {
return { id: l.id, name, builtIn: BUILTIN_IDS.has(l.id), widgets };
};
+// Bundled so clients can enforce the same limits without duplicating magic
+// numbers. Lives on every /api/dashboard/layouts response.
+export const LIMITS = Object.freeze({
+ idMaxLength: ID_MAX_LENGTH,
+ nameMaxLength: NAME_MAX_LENGTH,
+ widgetsMax: WIDGETS_MAX,
+ widgetIdMaxLength: WIDGET_ID_MAX_LENGTH,
+});
+
export async function getState() {
await ensureDir(PATHS.data);
const raw = await readJSONFile(STATE_PATH, DEFAULT_STATE, { logError: false });
@@ -115,7 +124,7 @@ export async function getState() {
const activeLayoutId = layouts.find((l) => l.id === raw.activeLayoutId)
? raw.activeLayoutId
: layouts[0].id;
- return { activeLayoutId, layouts };
+ return { activeLayoutId, layouts, limits: LIMITS };
}
export async function setActiveLayout(id) {
@@ -123,9 +132,9 @@ export async function setActiveLayout(id) {
if (!state.layouts.find((l) => l.id === id)) {
throw makeErr(`Unknown layout id: ${id}`, ERR_NOT_FOUND);
}
- const next = { ...state, activeLayoutId: id };
+ const next = { activeLayoutId: id, layouts: state.layouts };
await atomicWrite(STATE_PATH, next);
- return next;
+ return { ...next, limits: LIMITS };
}
export async function saveLayout(layout) {
@@ -134,9 +143,9 @@ export async function saveLayout(layout) {
const merged = idx >= 0
? state.layouts.map((l, i) => i === idx ? { ...l, ...layout, builtIn: l.builtIn } : l)
: [...state.layouts, { ...layout, builtIn: false }];
- const next = { ...state, layouts: merged };
+ const next = { activeLayoutId: state.activeLayoutId, layouts: merged };
await atomicWrite(STATE_PATH, next);
- return next;
+ return { ...next, limits: LIMITS };
}
export async function deleteLayout(id) {
@@ -152,5 +161,5 @@ export async function deleteLayout(id) {
const activeLayoutId = state.activeLayoutId === id ? nextLayouts[0].id : state.activeLayoutId;
const next = { activeLayoutId, layouts: nextLayouts };
await atomicWrite(STATE_PATH, next);
- return next;
+ return { ...next, limits: LIMITS };
}