perf(server): reduce streaming projection overhead #5651
Closedt3-code-bot[bot](GitHub profile, opens in a new tab)wants to merge 4 commits into
main fromt3bot/streaming-projection-performanceopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/server/src/orchestration/Layers/ProjectionPipeline.ts lines 1343 to 1345OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1296,5 +1329,17 @@1329+ const existingTurn = yield* projectionTurnRepository.getByTurnId({1330+ threadId: event.payload.threadId,1331+ turnId: event.payload.turnId,1332+ });1333+ // The first chunk attaches the assistant message to the turn. Later1334+ // chunks do not change turn state, so avoid rewriting it per token.1335+ if (1336+ event.payload.streaming &&1337+ Option.isSome(existingTurn) &&1338+ existingTurn.value.assistantMessageId === event.payload.messageId1339+ ) {1340+ return;1341+ }12961342 // A completed assistant message only settles the turn once the1297- // session is no longer running it — providers may emit several1298- // assistant messages per turn (commentary between tool calls), and1299- // the turn must stay unsettled until the provider reports turn end1300- // (projected as thread.session-set leaving the "running" status).1343+ // session is no longer running it. Providers may emit several1344+ // assistant messages per turn, and the turn must stay unsettled1345+ // until the provider reports turn end.apps/server/src/orchestration/Layers/ProjectionPipeline.ts lines 1769 to 1771OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1700,0 +1751,21 @@1751+ ),1752+ )1753+ .pipe(1754+ Effect.flatMap(() =>1755+ runAttachmentSideEffects(attachmentSideEffects).pipe(1756+ Effect.catch((cause) =>1757+ Effect.logWarning("failed to apply projected attachment side-effects", {1758+ sequence: event.sequence,1759+ eventType: event.type,1760+ cause,1761+ }),1762+ ),1763+ ),1764+ ),1765+ Effect.provideService(FileSystem.FileSystem, fileSystem),1766+ Effect.provideService(Path.Path, path),1767+ Effect.provideService(ServerConfig, serverConfig),1768+ Effect.asVoid,1769+ Effect.catchTag("SqlError", (sqlError) =>1770+ Effect.fail(toPersistenceSqlError("ProjectionPipeline.projectEvent:query")(sqlError)),1771+ ),
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed
Effect service conventions review: two issues in
Posted via Macroscope — Effect Service Conventionsapps/server/src/orchestration/Layers/ProjectionPipeline.ts. The new repository operations (appendStreaming,touchUpdatedAt) follow the existing persistence layer conventions and are covered by focused tests.