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([character-bible-simplify-followups]): copilot pass 4

[._.]/ Adam Eivyc30f0d85fe96
diff --git a/client/src/components/universe/CharacterReferenceSheetPanel.jsx b/client/src/components/universe/CharacterReferenceSheetPanel.jsx
index cde8f411ca..81ed8d0e91 100644
--- a/client/src/components/universe/CharacterReferenceSheetPanel.jsx
+++ b/client/src/components/universe/CharacterReferenceSheetPanel.jsx
@@ -110,16 +110,18 @@ export default function CharacterReferenceSheetPanel({
const handleGenerate = async () => {
if (jobId || !universeId || !entry?.id) return;
- // Abort any in-flight HEAD poll from a previous render before kicking
- // off a new one. Without this a superseded render's poll could still
- // resolve and call `onSheetCompleted` with the stale filename — the
- // server-side supersede check skips the pointer stamp but the client
- // would have already swapped the displayed filename.
- pollAbortRef.current?.abort();
- pollAbortRef.current = null;
const queued = await renderCharacterReferenceSheet(universeId, entry.id)
.catch((err) => { toast.error(err.message || 'Sheet render failed to start'); return null; });
if (!queued?.jobId) return;
+ // Abort the previous render's in-flight HEAD poll ONLY after the new
+ // render is successfully queued. Aborting up-front would discard the
+ // previous render's `onSheetCompleted` call if the new render-start
+ // failed; aborting here only sacrifices it when we're about to replace
+ // the displayed filename anyway. This also closes the supersede race —
+ // a poll that fires after we've moved on can't call back with a stale
+ // filename the server-side check refused to stamp.
+ pollAbortRef.current?.abort();
+ pollAbortRef.current = null;
destFilenameRef.current = queued.destFilename || null;
setJobId(queued.jobId);
toast.success(`Rendering reference sheet for ${entry.name}…`);
diff --git a/server/lib/fileUtils.js b/server/lib/fileUtils.js
index 972b989683..c2610ede5c 100644
--- a/server/lib/fileUtils.js
+++ b/server/lib/fileUtils.js
@@ -662,8 +662,14 @@ export function makePathResolver(getRoot, { extensions, cache = false } = {}) {
if (typeof getRoot !== 'function') {
throw new Error('makePathResolver: getRoot must be a function returning the root dir');
}
+ // Escape regex metacharacters in each extension before interpolating —
+ // current callers pass plain alphanumeric tokens (png/jpg/jpeg/webp), but
+ // the exported factory shouldn't behave incorrectly if a future caller
+ // passes an extension containing `.`/`+`/etc.
const extRegex = Array.isArray(extensions) && extensions.length > 0
- ? new RegExp(`\\.(${extensions.map((e) => String(e).replace(/^\./, '')).join('|')})$`, 'i')
+ ? new RegExp(`\\.(${extensions
+ .map((e) => String(e).replace(/^\./, '').replace(/[.*+?^${}()|[\]\\]/g, '\\$&'))
+ .join('|')})$`, 'i')
: null;
const memo = cache ? new Map() : null;
// Resolved-root cache so the hot path doesn't re-run `resolvePath(root) +
diff --git a/server/services/pipeline/refineHelpers.js b/server/services/pipeline/refineHelpers.js
index c5dd901092..a07ced5b12 100644
--- a/server/services/pipeline/refineHelpers.js
+++ b/server/services/pipeline/refineHelpers.js
@@ -44,13 +44,18 @@ export async function runPromptRefine({
...rest
}) {
const validateContent = (c) => {
- const refined = (c?.[resultField] || '').trim();
+ // Type-gate: an LLM that returned `{ prompt: 42 }` or `{ prompt: { ... } }`
+ // would otherwise blow up on `.trim()` or silently coerce to garbage. Treat
+ // any non-string as missing.
+ const raw = c?.[resultField];
+ const refined = typeof raw === 'string' ? raw.trim() : '';
if (!refined) {
throw new ServerError(emptyError.message, { status: 502, code: emptyError.code });
}
};
const { content, ...meta } = await runPromptRefineRaw({ ...rest, validateContent, emptyError });
- const refined = String(content[resultField]).trim();
+ // `validateContent` already guarantees a non-empty string at this index.
+ const refined = content[resultField].trim();
const changes = Array.isArray(content.changes)
? content.changes.map((c) => String(c).slice(0, 240)).filter(Boolean).slice(0, changesLimit)
: [];