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 (codex): validate the stored per-reviewer model scalars too, so a saved pin can't display but never apply

[._.]/ Adam Eivydefc52e21a5f
diff --git a/client/src/lib/reviewerModels.js b/client/src/lib/reviewerModels.js
index 46cadc679a..0586145037 100644
--- a/client/src/lib/reviewerModels.js
+++ b/client/src/lib/reviewerModels.js
@@ -1,4 +1,4 @@
-import { MODEL_SELECTABLE_REVIEWERS } from '../components/cos/constants';
+import { MODEL_SELECTABLE_REVIEWERS, MAX_REVIEWER_MODEL_LENGTH, sanitizeReviewerModelInput } from '../components/cos/constants';
/**
* Adapters between the two shapes a per-reviewer model pin takes.
@@ -14,12 +14,20 @@ import { MODEL_SELECTABLE_REVIEWERS } from '../components/cos/constants';
* Server mirror: `reviewerModelsFromDefaults` in `server/lib/cosValidation.js`.
*/
-/** Scalars → `{ codex: 'gpt-…', ollama: 'qwen…' }`. Blank/absent scalars are omitted. */
+/**
+ * Scalars → `{ codex: 'gpt-…', ollama: 'qwen…' }`. Blank/absent scalars are omitted,
+ * as is a value the server's token builders would drop — an over-long id or one
+ * carrying a structural delimiter. settings.json is hand-editable, so a stored
+ * value that predates the schema's validation must not surface as a pin the picker
+ * DISPLAYS but no reviewer ever receives.
+ */
export function reviewerModelsFromDefaults(defaults) {
const out = {};
for (const reviewer of MODEL_SELECTABLE_REVIEWERS) {
- const model = defaults?.[`${reviewer}Model`];
- if (typeof model === 'string' && model.trim()) out[reviewer] = model.trim();
+ const raw = defaults?.[`${reviewer}Model`];
+ if (typeof raw !== 'string') continue;
+ const model = sanitizeReviewerModelInput(raw).trim();
+ if (model && model.length <= MAX_REVIEWER_MODEL_LENGTH && model === raw.trim()) out[reviewer] = model;
}
return out;
}
diff --git a/server/lib/cosValidation.js b/server/lib/cosValidation.js
index e168f89256..e815870f5f 100644
--- a/server/lib/cosValidation.js
+++ b/server/lib/cosValidation.js
@@ -241,6 +241,26 @@ export const MAX_REVIEWER_MODEL_LENGTH = 200;
// not.
const REVIEWER_MODEL_FORBIDDEN_RE = /[[\],\r\n\t]/;
+/**
+ * Validate ONE reviewer model id — the single definition shared by the
+ * token-keyed map normalizer, the `<reviewer>Model` settings scalars, and the
+ * defaults→map adapter, so a pin can't be accepted by one path and dropped by
+ * another (which would show the user a stored pin that never reaches a reviewer).
+ *
+ * Returns the trimmed id, or `undefined` when it isn't usable: a non-string, a
+ * blank/whitespace-only value (absent ≠ `''` — a `--model ` with no id would break
+ * the invocation), an over-long one, one carrying a structural delimiter, or one
+ * naming a reviewer that takes no model. Pass `reviewer` to apply that last check.
+ */
+function normalizeReviewerModel(raw, reviewer = null) {
+ if (reviewer !== null && !MODEL_SELECTABLE_REVIEWERS.includes(reviewer)) return undefined;
+ if (typeof raw !== 'string') return undefined;
+ const model = raw.trim();
+ if (!model || model.length > MAX_REVIEWER_MODEL_LENGTH) return undefined;
+ if (REVIEWER_MODEL_FORBIDDEN_RE.test(model)) return undefined;
+ return model;
+}
+
// Reviewers whose slashdo `--review-with` entry accepts a `[<model>]` bracket
// (`lib/multi-reviewer-loop.md`: codex/claude/agy/grok/ollama). PortOS's
// `lmstudio` reviewer has NO slashdo counterpart — it's served by
@@ -279,11 +299,9 @@ export function normalizeReviewerModels(map) {
const out = Object.create(null);
for (const [rawKey, rawValue] of Object.entries(map)) {
const token = normalizeReviewerToken(rawKey);
- if (!token || !MODEL_SELECTABLE_REVIEWERS.includes(token)) continue;
- if (typeof rawValue !== 'string') continue;
- const model = rawValue.trim();
- if (!model || model.length > MAX_REVIEWER_MODEL_LENGTH) continue;
- if (REVIEWER_MODEL_FORBIDDEN_RE.test(model)) continue;
+ if (!token) continue;
+ const model = normalizeReviewerModel(rawValue, token);
+ if (!model) continue;
// First occurrence wins for two spellings of one reviewer — mirrors the
// sibling normalizers' dedupe.
if (Object.prototype.hasOwnProperty.call(out, token)) continue;
@@ -318,8 +336,11 @@ export function resolveReviewerModels(metadataMap, defaultMap) {
export function reviewerModelsFromDefaults(defaults) {
const out = {};
for (const r of MODEL_SELECTABLE_REVIEWERS) {
- const model = defaults?.[`${r}Model`];
- if (typeof model === 'string' && model.trim()) out[r] = model.trim();
+ // Re-checked here, not trusted: settings.json is hand-editable, and a value
+ // stored before the scalars were validated must not surface as a pin the token
+ // builders would then drop.
+ const model = normalizeReviewerModel(defaults?.[`${r}Model`], r);
+ if (model) out[r] = model;
}
return out;
}
@@ -850,10 +871,15 @@ export const codeReviewSettingsSchema = z.object({
),
stopMode: z.enum(REVIEW_STOP_MODES).optional(),
reviewerApplies: z.boolean().optional(),
- lmstudioModel: z.preprocess(emptyToUndefined, z.string().optional()),
- ollamaModel: z.preprocess(emptyToUndefined, z.string().optional()),
- codexModel: z.preprocess(emptyToUndefined, z.string().optional()),
- claudeModel: z.preprocess(emptyToUndefined, z.string().optional()),
+ // Each scalar runs through the same shape check as a task-level pin
+ // (`normalizeReviewerModel`), so a stored default can't carry an id the token
+ // builders would silently drop — the picker would otherwise DISPLAY a pin that
+ // never reaches a reviewer. An unusable value clears the field (undefined)
+ // rather than persisting: same "absent = that reviewer's own default" contract.
+ lmstudioModel: z.preprocess(v => normalizeReviewerModel(v, 'lmstudio'), z.string().optional()),
+ ollamaModel: z.preprocess(v => normalizeReviewerModel(v, 'ollama'), z.string().optional()),
+ codexModel: z.preprocess(v => normalizeReviewerModel(v, 'codex'), z.string().optional()),
+ claudeModel: z.preprocess(v => normalizeReviewerModel(v, 'claude'), z.string().optional()),
}).strict();
// =============================================================================
diff --git a/server/lib/validation.test.js b/server/lib/validation.test.js
index dc837cc292..d1187f64e2 100644
--- a/server/lib/validation.test.js
+++ b/server/lib/validation.test.js
@@ -217,6 +217,25 @@ describe('validation.js', () => {
// A token-keyed map is NOT part of this slice — the scalars are.
expect(codeReviewSettingsSchema.safeParse({ reviewerModels: { codex: 'a' } }).success).toBe(false)
})
+
+ it('clears a scalar carrying a character the emitted token cannot escape', () => {
+ // Otherwise the picker would DISPLAY a stored pin that the token builders
+ // silently drop — the user sets a model and no reviewer ever gets it.
+ const r = codeReviewSettingsSchema.safeParse({ codexModel: 'foo]~opt', claudeModel: 'a,b' })
+ expect(r.success).toBe(true)
+ expect(r.data.codexModel).toBeUndefined()
+ expect(r.data.claudeModel).toBeUndefined()
+ })
+
+ it('trims a scalar and clears an over-long one', () => {
+ const r = codeReviewSettingsSchema.safeParse({
+ codexModel: ' gpt-tier-a ',
+ claudeModel: 'm'.repeat(MAX_REVIEWER_MODEL_LENGTH + 1),
+ })
+ expect(r.success).toBe(true)
+ expect(r.data.codexModel).toBe('gpt-tier-a')
+ expect(r.data.claudeModel).toBeUndefined()
+ })
})
describe('processSchema', () => {
@@ -1294,6 +1313,16 @@ describe('validation.js', () => {
it('tolerates absent defaults', () => {
expect(reviewerModelsFromDefaults(null)).toEqual({});
});
+
+ it('re-checks the stored scalars rather than trusting them', () => {
+ // settings.json is hand-editable, and a value stored before the schema
+ // validated these scalars must not surface as a pin the builders then drop.
+ expect(reviewerModelsFromDefaults({
+ codexModel: 'foo]~opt',
+ claudeModel: 'm'.repeat(MAX_REVIEWER_MODEL_LENGTH + 1),
+ ollamaModel: 'ok',
+ })).toEqual({ ollama: 'ok' });
+ });
});
describe('buildReviewWithArgs — per-reviewer [model] selector', () => {
diff --git a/server/services/codeReview.js b/server/services/codeReview.js
index 25e3bc4bda..f561da9f4c 100644
--- a/server/services/codeReview.js
+++ b/server/services/codeReview.js
@@ -78,6 +78,12 @@ export function pickCodeReviewDefaults(settings) {
reviewerMaxRounds: normalizeReviewerMaxRounds(raw?.reviewerMaxRounds) || {},
stopMode: REVIEW_STOP_MODES.includes(raw?.stopMode) ? raw.stopMode : DEFAULT_REVIEW_STOP_MODE,
reviewerApplies: raw?.reviewerApplies === true,
+ // Faithful mirror of the stored scalars, deliberately NOT shape-checked here:
+ // `/api/code-review/local` passes these as a JSON request-body field where a
+ // delimiter is harmless, so narrowing them at this layer would reject an id
+ // that path can legitimately use. Every consumer that turns a scalar into a
+ // slashdo TOKEN re-validates first (`reviewerModelsFromDefaults`), and the
+ // settings schema rejects an unusable id at write time.
lmstudioModel: typeof raw?.lmstudioModel === 'string' && raw.lmstudioModel ? raw.lmstudioModel : null,
ollamaModel: typeof raw?.ollamaModel === 'string' && raw.ollamaModel ? raw.ollamaModel : null,
codexModel: typeof raw?.codexModel === 'string' && raw.codexModel ? raw.codexModel : null,