🤖 fix: compaction stream validation and replay blocking #1247
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fix several issues causing compaction (
/compact) and workspace refresh to fail:Stream replay blocking
caught-up:replayStream()iterated a livepartsarray that continued growing during an active stream. This could delay thecaught-upevent indefinitely, leaving the UI stuck on "Loading workspace…". Fixed by snapshottingpartsbefore iteration.ORPC validation failures for stream mode: Compaction used
mode: "compact"instream-startevents, but the schema only allowedplan | exec. This causedEVENT_ITERATOR_VALIDATION_FAILEDerrors, triggering resubscribe loops. Fixed by allowing any string for mode.Malformed init-output during replay: Persisted init state could contain malformed entries that failed schema validation when replayed. Added defensive checks to skip invalid entries.
Compaction tool policy bug:
toolPolicy: []was intended to disable tools but actually allowed all tools (empty policy = allow all). Fixed by using an explicit disable-all regex.Changes
src/node/services/streamManager.ts: Snapshot parts array before replay iterationsrc/common/orpc/schemas/stream.ts: Loosen mode toz.string().optional()src/common/orpc/schemas/workspaceStats.ts: Loosen ModeSchema to stringsrc/node/services/sessionTimingService.ts: Update mode type tostring | undefinedsrc/node/services/initStateManager.ts: Skip malformed init-output entries during replaysrc/browser/utils/messages/compactionOptions.ts: Use explicit disable-all tool policysrc/browser/utils/messages/StreamingMessageAggregator.ts: Remove unnecessary type assertionTesting
replayStream()snapshots parts and terminates promptly/compactwith workspace refreshGenerated with
mux• Model:anthropic:claude-opus-4-5• Thinking:high