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): enforce adaptive-clamped value in effective config

[._.]/ Adam Eivy94aa8f6587f9
diff --git a/server/lib/postAdaptive.js b/server/lib/postAdaptive.js
index 4f6605a4ba..43caeddbea 100644
--- a/server/lib/postAdaptive.js
+++ b/server/lib/postAdaptive.js
@@ -81,29 +81,34 @@ export function adaptDrillConfig(type, baseConfig = {}, signal = {}, opts = {})
out.to = current;
if (samples < options.minSamples) {
+ // Adaptive not engaged yet — leave the manual config untouched (the manual
+ // value stays the override until there's enough signal to manage difficulty).
out.reason = 'insufficient-samples';
return out;
}
const direction = scoreToDirection(score, options);
out.direction = direction;
- if (direction === 0) {
- out.reason = 'hold';
- return out;
- }
const valueDelta = direction * spec.step * (spec.harderIsHigher ? 1 : -1);
const next = clampNum(current + valueDelta, spec.min, spec.max);
out.to = next;
- if (next === current) {
+ // Once adaptive is engaged, ALWAYS write the adaptive-clamped value into the
+ // effective config — even on the hold/at-boundary paths where `next === current`.
+ // Otherwise a manual config the schema allows but the adaptive spec caps lower
+ // (e.g. steps=20 vs adaptive max 16) would be reported as clamped in the preview
+ // but still generated at the raw value, breaking the advertised bounds.
+ out.config = { ...base, [spec.field]: next };
+
+ if (direction === 0) {
+ out.reason = 'hold';
+ } else if (next === current) {
// Already at the difficulty boundary in the requested direction.
out.reason = direction > 0 ? 'at-hardest' : 'at-easiest';
- return out;
+ } else {
+ out.applied = true;
+ out.reason = direction > 0 ? 'harder' : 'easier';
}
-
- out.config = { ...base, [spec.field]: next };
- out.applied = true;
- out.reason = direction > 0 ? 'harder' : 'easier';
return out;
}
diff --git a/server/lib/postAdaptive.test.js b/server/lib/postAdaptive.test.js
index f4b87c3d56..ee9bc1b084 100644
--- a/server/lib/postAdaptive.test.js
+++ b/server/lib/postAdaptive.test.js
@@ -104,6 +104,36 @@ describe('adaptDrillConfig', () => {
expect(res.config.steps).toBe(spec.min);
});
+ it('clamps an out-of-spec manual value into the effective config once engaged', () => {
+ // The schema/UI allow doubling-chain steps up to 20, but the adaptive spec
+ // caps at 16. When adaptive is engaged, the effective config must carry the
+ // clamped value (16) — not the raw 20 — so generation honors the bounds the
+ // preview advertises. (Regression: codex P2 on PR #2003.)
+ const spec = ADAPTIVE_SPECS['doubling-chain'];
+ const res = adaptDrillConfig('doubling-chain', { steps: 20 }, { score: 99, samples: 8 });
+ expect(res.reason).toBe('at-hardest');
+ expect(res.config.steps).toBe(spec.max); // 16, not 20
+ expect(res.to).toBe(spec.max);
+ });
+
+ it('enforces the clamped value even on the hold path', () => {
+ // steps=20 (out of spec) with a mid-band score → hold, but the effective
+ // config is still clamped down to the adaptive max.
+ const spec = ADAPTIVE_SPECS['doubling-chain'];
+ const res = adaptDrillConfig('doubling-chain', { steps: 20 }, { score: 70, samples: 8 });
+ expect(res.reason).toBe('hold');
+ expect(res.applied).toBe(false);
+ expect(res.config.steps).toBe(spec.max);
+ });
+
+ it('leaves an out-of-spec manual value untouched until adaptive engages', () => {
+ // Below the sample gate, adaptive is not engaged — the manual value (even
+ // out of the adaptive spec range) passes through as the override.
+ const res = adaptDrillConfig('doubling-chain', { steps: 20 }, { score: 99, samples: 1 });
+ expect(res.reason).toBe('insufficient-samples');
+ expect(res.config.steps).toBe(20);
+ });
+
it('falls back to the spec base when the config omits the knob', () => {
const spec = ADAPTIVE_SPECS.multiplication;
const res = adaptDrillConfig('multiplication', {}, { score: 95, samples: 5 });