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): keep flux2 final-step adapter tied to finalStep

[._.]/ Adam Eivy8f51fcfa4239
diff --git a/server/services/loraTraining/checkpoints.js b/server/services/loraTraining/checkpoints.js
index 9b547a72bd..7588749baa 100644
--- a/server/services/loraTraining/checkpoints.js
+++ b/server/services/loraTraining/checkpoints.js
@@ -192,22 +192,20 @@ export async function resolveCheckpointAdapterBuffer(run, step) {
*/
export async function selectDeployableCheckpoint(run, finalAdapterPath, finalStep) {
const samples = sampleByStep(run);
- const all = listRunCheckpoints(run);
- const withPreview = all.filter((c) => c.hasPreview);
- // The step to record as "deployed" is the newest recorded checkpoint (the
- // one `finalAdapterPath` was extracted from), NOT the trainer's raw end-step
- // counter — using a listed checkpoint's step keeps the picker's deployed flag
- // accurate. Fall back to finalStep when no checkpoints were recorded.
- const finalCkptStep = all.length ? all[all.length - 1].step : finalStep;
- // Health proxy for the final adapter: its own preview, or — since mflux
- // saves the final checkpoint a few steps PAST the last sampled step, so the
- // final usually has no preview of its own — the most recent preview.
+ const withPreview = listRunCheckpoints(run).filter((c) => c.hasPreview);
+ // `finalStep` is the trainer's reported end step, which IS the deployed
+ // adapter: for mflux it equals the final checkpoint's (filename-derived)
+ // step, so the picker's deployed flag matches a listed checkpoint; for flux2
+ // the final adapter is written separately AT finalStep (not as a checkpoint),
+ // and flux2 renders a sample at that step, so the proxy below still finds it.
+ // Health proxy: the final step's own preview, or — since mflux saves the
+ // final checkpoint a few steps PAST the last sampled step — the most recent.
const latest = withPreview.length ? withPreview[withPreview.length - 1] : null;
- const finalPreviewName = samples.get(finalCkptStep) || (latest ? samples.get(latest.step) : null);
+ const finalPreviewName = samples.get(finalStep) || (latest ? samples.get(latest.step) : null);
const readFinal = async (reason = null) => ({
buffer: await readFile(finalAdapterPath),
- step: finalCkptStep,
+ step: finalStep,
previewUrl: sampleUrl(run.id, finalPreviewName),
autoSelected: false,
reason,
@@ -221,7 +219,7 @@ export async function selectDeployableCheckpoint(run, finalAdapterPath, finalSte
// Final diverged. Walk earlier checkpoints newest→oldest for a healthy one.
const earlier = withPreview
- .filter((c) => c.step < finalCkptStep)
+ .filter((c) => c.step < finalStep)
.sort((a, b) => b.step - a.step);
for (const cand of earlier) {
const previewName = samples.get(cand.step);
@@ -239,5 +237,5 @@ export async function selectDeployableCheckpoint(run, finalAdapterPath, finalSte
}
// Every preview collapsed (or no earlier adapter recoverable) — keep final
// so the run still registers a (flawed) LoRA the user can inspect/replace.
- return readFinal(`all previews collapsed — kept final step ${finalCkptStep}`);
+ return readFinal(`all previews collapsed — kept final step ${finalStep}`);
}
diff --git a/server/services/loraTraining/checkpoints.test.js b/server/services/loraTraining/checkpoints.test.js
index db10d32897..d8310f3b4a 100644
--- a/server/services/loraTraining/checkpoints.test.js
+++ b/server/services/loraTraining/checkpoints.test.js
@@ -168,20 +168,23 @@ describe('loraTraining/checkpoints', () => {
expect(sel.reason).toMatch(/collapsed/);
});
- it('guard: keeps the final adapter when its (latest checkpoint) preview is healthy', async () => {
- // Latest checkpoint is 250 with the noisy (healthy) preview → no override.
- const run = buildRun({
- artifacts: {
- checkpoints: [{ step: 250, path: '0000250_checkpoint.zip', loss: 0.64 }],
- samples: ['0000250_preview_image_preview_1.png'],
- },
- });
- const sel = await selectDeployableCheckpoint(run, finalAdapterPath, 250);
+ it('guard: keeps the final adapter when its preview is healthy', async () => {
+ // finalStep 250 has the noisy (healthy) preview → no override.
+ const sel = await selectDeployableCheckpoint(buildRun(), finalAdapterPath, 250);
expect(sel.autoSelected).toBe(false);
expect(sel.step).toBe(250);
expect(sel.buffer.toString()).toBe(ADAPTER_500.toString()); // returns the on-disk final adapter as-is
});
+ it('guard: for flux2 keeps the separate final-step adapter even though it is not a recorded checkpoint', async () => {
+ // flux2 writes the final adapter at finalStep separately (not as a
+ // checkpoint), and renders a sample there. finalStep 500 is past the only
+ // recorded checkpoint (250); its preview (black) collapses → falls back.
+ const sel = await selectDeployableCheckpoint(buildRun(), finalAdapterPath, 500);
+ expect(sel.autoSelected).toBe(true);
+ expect(sel.step).toBe(250); // latest healthy checkpoint
+ });
+
it('guard: trusts the final adapter when there are no previews to judge', async () => {
const run = buildRun({ artifacts: { checkpoints: [{ step: 500, path: '0000500_checkpoint.zip', loss: 0.5 }], samples: [] } });
const sel = await selectDeployableCheckpoint(run, finalAdapterPath, 500);