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

refactor([issue-1335]): dedup importer progress emit + reuse ImporterProgress

[._.]/ Adam Eivyabc5c95f563e
diff --git a/client/src/pages/Importer.jsx b/client/src/pages/Importer.jsx
index bd4672ce27..045b051e57 100644
--- a/client/src/pages/Importer.jsx
+++ b/client/src/pages/Importer.jsx
@@ -749,12 +749,12 @@ function IntakeForm({
// Live checklist of the analyze phase's AI passes. `stages` is null until the
// server's first `importer:progress` frame arrives — show a generic spinner in
// that window so the panel never looks empty between click and first frame.
-function ImporterProgress({ stages }) {
+function ImporterProgress({ stages, message = 'Analyzing source — this runs several AI passes and can take a minute or two.' }) {
return (
<div className="bg-port-bg border border-port-border rounded-lg p-4 space-y-2">
<p className="text-sm font-medium flex items-center gap-2">
<Loader2 className="w-4 h-4 animate-spin text-port-accent" />
- Analyzing source — this runs several AI passes and can take a minute or two.
+ {message}
</p>
{Array.isArray(stages) && stages.length > 0 ? (
<ul className="space-y-1.5 mt-2">
@@ -951,26 +951,8 @@ function ReviewPanel({
<IssuesReviewSection issues={issuesDraft} setIssues={setIssuesDraft} seasons={seasonsDraft} arcRoles={arcRoles} excerptLabel={excerptLabel} />
- {committing && cleanupFormatting && Array.isArray(commitProgress) && commitProgress.length > 0 && (
- <div className="bg-port-bg border border-port-border rounded-lg p-4 space-y-2">
- <p className="text-sm font-medium flex items-center gap-2">
- <Loader2 className="w-4 h-4 animate-spin text-port-accent" />
- Cleaning up formatting — one AI pass per issue.
- </p>
- <ul className="space-y-1.5 mt-2">
- {commitProgress.map((s) => {
- const { Icon, className } = stageStatusIcon(s.status);
- return (
- <li key={s.id} className="flex items-center gap-2 text-sm">
- <Icon className={className} />
- <span className={s.status === 'running' ? 'text-port-text' : 'text-port-text-muted'}>
- {s.label}
- </span>
- </li>
- );
- })}
- </ul>
- </div>
+ {committing && cleanupFormatting && (
+ <ImporterProgress stages={commitProgress} message="Cleaning up formatting — one AI pass per issue." />
)}
<div className="sticky bottom-4 flex items-center justify-end gap-2 bg-port-card border border-port-border rounded-lg p-3 shadow-lg">
diff --git a/server/services/importer.js b/server/services/importer.js
index 571ef7de0e..e871f1b7ea 100644
--- a/server/services/importer.js
+++ b/server/services/importer.js
@@ -107,6 +107,26 @@ const CONTENT_TYPE_SEED_STAGE = Object.freeze({
const DEFAULT_SEED_STAGE = 'prose';
const seedStageFor = (contentType) => CONTENT_TYPE_SEED_STAGE[contentType] || DEFAULT_SEED_STAGE;
+/**
+ * One importer progress run: a fresh `runId` plus an `emitProgress(frame)` that
+ * stamps it on each frame and broadcasts via `emitImporterProgress`. The client
+ * uses `runId` to ignore stragglers from a prior run. Emitting is best-effort
+ * UI sugar — a listener throwing must never abort the importer, so the emit
+ * swallows + logs at this boundary. Shared by the analyze phase and the
+ * commit-time reformat pass so both runs broadcast identically.
+ */
+function makeImporterProgressEmitter() {
+ const runId = randomUUID();
+ const emitProgress = (frame) => {
+ try {
+ emitImporterProgress({ runId, ...frame });
+ } catch (err) {
+ console.error(`❌ importer progress emit failed: ${err.message}`);
+ }
+ };
+ return { runId, emitProgress };
+}
+
/**
* Best-effort AI cleanup of seeded excerpts at import time (issue #1335). The
* importer seeds each issue's verbatim `proseExcerpt` straight into its seed
@@ -131,16 +151,7 @@ export async function reformatSeededExcerpts(issues, { contentType = null } = {}
const stageId = seedStageFor(contentType);
const targets = (Array.isArray(issues) ? issues : []).filter((p) => p?.proseExcerpt);
if (targets.length === 0) return issues;
- const runId = randomUUID();
- // Emitting is best-effort UI sugar — never let a listener throw abort the
- // commit, so swallow + log at this boundary (mirrors analyze's emitProgress).
- const emit = (frame) => {
- try {
- emitImporterProgress({ runId, ...frame });
- } catch (err) {
- console.error(`❌ importer reformat progress emit failed: ${err.message}`);
- }
- };
+ const { emitProgress: emit } = makeImporterProgressEmitter();
// Index cleaned text by the original proposal reference so the returned array
// can be rebuilt without mutating the input objects.
const cleaned = new Map();
@@ -148,6 +159,9 @@ export async function reformatSeededExcerpts(issues, { contentType = null } = {}
type: 'start',
stages: targets.map((p, idx) => ({ id: `reformat-${idx}`, label: `Clean up formatting: ${p.title}` })),
});
+ // Sequential on purpose: one provider call at a time keeps a 20+ issue import
+ // from fanning out concurrent LLM calls (rough on a local model) and lets the
+ // checklist fill in reading order.
for (let idx = 0; idx < targets.length; idx++) {
const proposal = targets[idx];
emit({ type: 'stage', id: `reformat-${idx}`, status: 'running' });
@@ -159,8 +173,8 @@ export async function reformatSeededExcerpts(issues, { contentType = null } = {}
return null;
});
if (result?.text) cleaned.set(proposal, result.text);
- // Map both clean outcomes to 'done' and the fallback to 'error' so the
- // client's existing icon set renders them (no new status to teach the UI).
+ // Clean outcomes → 'done', the verbatim fallback → 'error' (the warning icon
+ // that flags "not cleaned"), reusing the client's existing status icon set.
emit({ type: 'stage', id: `reformat-${idx}`, status: result ? 'done' : 'error' });
}
emit({ type: 'done' });
@@ -763,14 +777,7 @@ export async function analyzeImport({
// `emitImporterProgress` records each frame into the live snapshot before
// broadcasting so a socket that (re)connects mid-analyze can be replayed the
// checklist (see importerEvents.js / socket.js).
- const runId = randomUUID();
- const emitProgress = (frame) => {
- try {
- emitImporterProgress({ runId, ...frame });
- } catch (err) {
- console.error(`❌ importer progress emit failed: ${err.message}`);
- }
- };
+ const { emitProgress } = makeImporterProgressEmitter();
const emitStage = (id, status) => emitProgress({ type: 'stage', id, status });
emitProgress({ type: 'start', stages: ANALYZE_STAGES });