fix(viewer): preserve attachment ownership and cancel playground turns

Merged
LO
21d ago
+860-574

Attachments added after Send were cleared by the first reply chunk, and overlapping file batches could exceed six slots. Playground turns also continued after Stop, unmount, or IFC replacement. A dropdown choice must apply to the next turn while the current turn finishes on its fixed modelId.

Remove only the sent attachment ids and check live composer capacity/lifetime when extraction commits. The first-chunk regression now mounts the real ChatPanel on the cheap /api/chat proxy route, without mountNative or a WASM fixture.

Use the merged useAsyncRun for playground ownership, reentry, busy state, signals, and owner-checked settlement. The IFC model object owns the run; dropdown changes apply to the next turn. Stop calls reset(), displays a square stop glyph, and gives an empty assistant reply a localized, live displayTextKey. English, German, French, Italian, and Russian have the new status key. Received text is preserved. Extract the existing model/key header controls and lower the main component’s size budget from 791 to 715 lines.

The model-choice, empty-status, and glyph tests failed before the fixes. Final focused coverage: 21 passed, zero skipped. The same-tick regression also asserts one transcript turn, so a superseding duplicate cannot pass merely because only one request reaches the network.

Rebased onto main 94ca2db4d6a13771a837cc9d342729ca9cfaefc6. Full validation at 874e7361ad298525ea3291e23708755961e830ca on Pop!_OS (Node 24.22.0, pnpm 10.8.1). All commands below used an 8 GiB hard cap, zero swap, and a two-CPU quota. The final gate used the lane rules’ direct capped fallback after its disk-refused queued fleet request was cancelled and finalized. Foreign jobs and benchmarks were untouched.

CommandResult
systemd-run --user --scope -q -p MemoryMax=8G -p MemorySwapMax=0 -p CPUQuota=200% -- pnpm install --frozen-lockfile --ignore-scriptsPassed; refreshed workspace links without lifecycle builds
systemd-run --user --scope -q -p MemoryMax=8G -p MemorySwapMax=0 -p CPUQuota=200% -- env TEST_PATTERN='ChatPanel|playground-|components/mcp/PlaygroundChat|document-upload|request-attachments|message-capabilities|useAsyncRun|/i18n/' pnpm test --filter=@ifc-lite/viewer --only744 passed; 1 skipped
systemd-run --user --scope -q -p MemoryMax=8G -p MemorySwapMax=0 -p CPUQuota=200% -- env NODE_OPTIONS=--max-old-space-size=8192 TURBO_CONCURRENCY=1 pnpm typecheck:ciPassed, including viewer and viewer-embed test sources
systemd-run --user --scope -q -p MemoryMax=8G -p MemorySwapMax=0 -p CPUQuota=200% -- env AEE3_LINT_TSC_LOCK=/tmp/aee4-tsc-chat.lock NODE_OPTIONS=--import=file:///tmp/aee3-serialize-tsc.mjs pnpm lintPassed, including unused locals
systemd-run --user --scope -q -p MemoryMax=8G -p MemorySwapMax=0 -p CPUQuota=200% -- node scripts/check-module-size.mjsPassed
systemd-run --user --scope -q -p MemoryMax=8G -p MemorySwapMax=0 -p CPUQuota=200% -- node scripts/check-source-text-assertions.mjsPassed
systemd-run --user --scope -q -p MemoryMax=8G -p MemorySwapMax=0 -p CPUQuota=200% -- node --test scripts/check-unused-locals-baseline.test.mjsPassed
systemd-run --user --scope -q -p MemoryMax=8G -p MemorySwapMax=0 -p CPUQuota=200% -- node scripts/pre-handoff.mjsPassed
systemd-run --user --scope -q -p MemoryMax=8G -p MemorySwapMax=0 -p CPUQuota=200% -- node scripts/check-base-freshness.mjs --pr 9577Passed against current main b4fd83590; cleared the inherited stale-base advisory label

Root typecheck:ci uses prepared dependency artifacts and retains the root test-program coverage tail. TypeScript outputs were refreshed under the same cap via root pnpm build --filter=<package> --only for @ifc-lite/{data,wasm-lifecycle,geometry,mutations,export,cache,clash,create,collab,rhino3dm,cli,renderer}. No Rust/WASM build was run.

Family skips: skip: canonical cost fixture missing — run pnpm fixtures; ﹣ dispatches canonical cost data and evaluation (0.673017ms) # SKIP.

Pre-handoff skipped coverage: SKIPPED retained-free viewer: apps/viewer/dist absent; build the default viewer first.

Lint serializes its compiler children to fit the whole command within 8 GiB; all checks, compiler flags, and baselines are unchanged. The private preload below was verified with a three-process fixture to hold the lock for each compiler’s full lifetime.

Lint compiler serialization preload
import { openSync } from 'node:fs';
import { spawnSync } from 'node:child_process';

// Bound the existing lint worker pool's compiler overlap without changing diagnostics.
if (process.argv[1]?.endsWith('/typescript/bin/tsc')) {
  const path = process.env.AEE3_LINT_TSC_LOCK;
  if (!path) throw new Error('AEE3_LINT_TSC_LOCK is required for serialized lint');
  const descriptor = openSync(path, 'a', 0o600);
  const result = spawnSync('flock', ['--exclusive', '3'], {
    stdio: ['ignore', 'ignore', 'pipe', descriptor],
  });
  if (result.error || result.status !== 0) {
    throw new Error(`Cannot acquire TypeScript lint lock: ${result.error?.message ?? result.stderr}`);
  }
  // Keep this descriptor open: Linux flock follows the shared open description
  // after the flock child exits, and the compiler's exit releases it.
}

Mutation command, one restored mutation at a time: systemd-run --user --scope -q -p MemoryMax=8G -p MemorySwapMax=0 -p CPUQuota=200% -- pnpm test --filter=@ifc-lite/viewer --only, with TEST_PATTERN set to ChatPanel.attachments, ChatPanel.i18n, playground-credentials.

GuardResult / named failing test
playground-ifc-ownerKilled — playground replace aborts the current API turn
playground-model-choice-survivesKilled — #9577 changing the model dropdown preserves the current turn and its fixed modelId
playground-reentryKilled — playground same-tick submissions start one API turn
playground-signalKilled — playground replace aborts the current API turn
playground-after-apiKilled — playground Stop during response prevents subsequent tool mutations
playground-after-toolKilled — playground Stop during tool prevents subsequent tool mutations
playground-update-ownerSurvived — defensive callback ownership check; the runner’s independently killed post-API/post-tool signal checks already prevent stale callbacks from reaching it.
playground-error-ownerKilled — playground replace aborts the current API turn
playground-shared-settleKilled — playground an old API completion cannot clear a replacement run or show its error
playground-shared-invalidateKilled — playground replace aborts the current API turn
playground-shared-abortKilled — playground replace aborts the current API turn
playground-stop-resetKilled — playground stop aborts the current API turn
playground-stop-uiKilled — playground stop aborts the current API turn
playground-stop-statusKilled — #9577 stopping before text shows a localized stopped status
playground-stop-retains-textKilled — playground Stop during tool prevents subsequent tool mutations
playground-stop-live-localeKilled — #9577 stopping before text shows a localized stopped status
playground-stop-glyphKilled — #9577 stopping before text shows a stop glyph
playground-stop-locale-enKilled — #9577 stopping before text shows a localized stopped status
playground-stop-locale-deKilled — #9577 stopping before text shows a localized stopped status
playground-stop-locale-frKilled — #9577 stopping before text shows a localized stopped status
playground-stop-locale-itKilled — #9577 stopping before text shows a localized stopped status
playground-stop-locale-ruKilled — #9577 stopping before text shows a localized stopped status
attachment-capacityKilled — C-6 overlapping file batches never exceed six attachments
attachment-currentKilled — C-6 a text extraction completing after unmount cannot attach to the next composer
attachment-turnKilled — C-6 first streamed chunk preserves attachments added after Send
attachment-loop-capacityKilled — C-6 overlapping file batches never exceed six attachments

25 killed; one documented defensive survivor. Shared-helper mutations exercise its guarantees through the real playground component; the helper itself has no production change in this PR.

Known separate follow-up N1: a dispatch already in flight at Stop can finish its side effect before the runner records its result, and Send currently re-enables before that dispatch settles. The transcript can mark a completed mutation as incomplete, leading the assistant to retry it. The follow-up must record that actual result before aborting, pass the signal into DispatchContext and long tools / each mutation_batch operation, and hold Send until dispatch settles. It overlaps both PlaygroundChat and the conversation runner introduced here, so its separate PR must branch from fresh main after #9577 merges.

Unverified: real paid-provider calls, PDF-worker extraction, and N1’s in-flight dispatch correction. The mounted playground tests use real IFC parsing/tool dispatch with deferred transport; the headline attachment test uses the real proxy transport/composer and has no WASM prerequisite.

🤖 Generated with Claude Code