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

fix: guard concurrent deck prompt runs

[._.]/ Adam Eivyd50b0b1b0b51
diff --git a/client/src/components/decks/DeckRenderControls.jsx b/client/src/components/decks/DeckRenderControls.jsx
index 29db1c4fcc..ca73a46c7e 100644
--- a/client/src/components/decks/DeckRenderControls.jsx
+++ b/client/src/components/decks/DeckRenderControls.jsx
@@ -100,7 +100,7 @@ export default function DeckRenderControls({
/>
<div className="grid grid-cols-1 gap-3 sm:grid-cols-2">
- <Step step="1" title="Prompts" note={promptNote({ generating, generatingStatus, unprompted, total })}>
+ <Step step="1" title="Prompts" note={promptNote({ generating, generatingStatus, unprompted, total })} live={generating}>
{(noteId) => (<>
<button
type="button"
@@ -230,7 +230,7 @@ const renderNote = ({ prompted, rendering, missing, inFlight, runtimeBlocked })
// carry it. The note is real page text rather than a `title`: a disabled button
// is neither focusable nor hoverable on touch, so a tooltip on it reaches
// nobody.
-function Step({ step, title, note, children }) {
+function Step({ step, title, note, live = false, children }) {
const noteId = useId();
return (
<section className="rounded border border-port-border/60 bg-port-bg/30 p-2.5 space-y-2" aria-label={`Step ${step}: ${title}`}>
@@ -238,7 +238,12 @@ function Step({ step, title, note, children }) {
<span className="text-port-accent">{step}</span> · {title}
</h3>
<div className="flex items-center gap-2 flex-wrap">{children(noteId)}</div>
- <p id={noteId} className="text-[11px] leading-snug text-gray-400">{note}</p>
+ <p
+ id={noteId}
+ className="text-[11px] leading-snug text-gray-400"
+ role={live ? 'status' : undefined}
+ aria-live={live ? 'polite' : undefined}
+ >{note}</p>
</section>
);
}
diff --git a/client/src/components/decks/DeckRenderControls.test.jsx b/client/src/components/decks/DeckRenderControls.test.jsx
index 0360f34615..43f1600daf 100644
--- a/client/src/components/decks/DeckRenderControls.test.jsx
+++ b/client/src/components/decks/DeckRenderControls.test.jsx
@@ -191,7 +191,9 @@ describe('DeckRenderControls prompt progress', () => {
generating: true,
generatingStatus: 'Writing prompts… 24 of 79 · batch 2 of 7',
});
- expect(screen.getByText('Writing prompts… 24 of 79 · batch 2 of 7')).toBeInTheDocument();
+ const status = screen.getByRole('status');
+ expect(status).toHaveTextContent('Writing prompts… 24 of 79 · batch 2 of 7');
+ expect(status).toHaveAttribute('aria-live', 'polite');
});
it('names the casting phase before the first prompt chunk lands', async () => {
diff --git a/server/routes/decks.js b/server/routes/decks.js
index f25c718778..c33e5abee1 100644
--- a/server/routes/decks.js
+++ b/server/routes/decks.js
@@ -134,8 +134,12 @@ router.post('/:id/generate-prompts', asyncHandler(async (req, res) => {
let universe = null;
let cast = null;
+ if (!beginPromptProgress(deck.id)) {
+ throw new ServerError('Prompt generation is already running for this deck.', {
+ status: 409, code: 'DECK_PROMPT_GENERATION_IN_PROGRESS',
+ });
+ }
try {
- beginPromptProgress(deck.id);
if (deck.universeId) {
const { getUniverse } = await import('../services/universeBuilder.js');
universe = await getUniverse(deck.universeId).catch(() => null);
diff --git a/server/routes/decks.test.js b/server/routes/decks.test.js
index c6506bfc17..6adf789e55 100644
--- a/server/routes/decks.test.js
+++ b/server/routes/decks.test.js
@@ -148,6 +148,16 @@ describe('deck routes', () => {
expect(generateDeckCardPrompts).not.toHaveBeenCalled();
});
+ it('rejects a second generate-prompts run while the deck already has one active', async () => {
+ beginPromptProgress.mockReturnValueOnce(false);
+ const res = await request(makeApp()).post(`/api/decks/${D1}/generate-prompts`).send({ overwrite: true });
+ expect(res.status).toBe(409);
+ expect(res.body.code).toBe('DECK_PROMPT_GENERATION_IN_PROGRESS');
+ expect(generateDeckCardPrompts).not.toHaveBeenCalled();
+ // The conflict must not close the first run's channel with a false error.
+ expect(finishPromptProgress).not.toHaveBeenCalled();
+ });
+
it('generate-prompts streams start/chunk/complete progress frames', async () => {
const res = await request(makeApp()).post(`/api/decks/${D1}/generate-prompts`).send({});
expect(res.status).toBe(200);
diff --git a/server/services/deckPromptProgress.js b/server/services/deckPromptProgress.js
index 9ff827e8f7..b413b7cad2 100644
--- a/server/services/deckPromptProgress.js
+++ b/server/services/deckPromptProgress.js
@@ -76,6 +76,10 @@ const ensureChannel = (key, deckId) => {
export function beginPromptProgress(deckId) {
const key = String(deckId);
const channel = ensureChannel(key, deckId);
+ // A started, unfinished channel belongs to an active generation run. Only
+ // one prompt POST may own a deck channel at a time; otherwise one run could
+ // publish the other run's chunks or terminal frame to every subscriber.
+ if (channel.started) return false;
if (!channel.started) {
channel.started = true;
clearTimer(channel);
diff --git a/server/services/deckPromptProgress.test.js b/server/services/deckPromptProgress.test.js
index b2b99c7f75..7204b36f3d 100644
--- a/server/services/deckPromptProgress.test.js
+++ b/server/services/deckPromptProgress.test.js
@@ -68,6 +68,14 @@ describe('deck prompt progress channel', () => {
expect(framesOf(res).at(-1)).toEqual({ type: 'chunk', written: 24, requested: 79, chunk: 2, chunks: 7 });
});
+ it('allows only one active prompt run per deck and releases the channel after finish', () => {
+ expect(beginPromptProgress('deck-1')).toBe(true);
+ expect(beginPromptProgress('deck-1')).toBe(false);
+
+ finishPromptProgress('deck-1', { type: 'complete' });
+ expect(beginPromptProgress('deck-1')).toBe(true);
+ });
+
it('keeps channels separate per deck', () => {
const first = fakeRes();
const second = fakeRes();