GeezerVison is showing github.com — perf(server): persist the wire projection for streaming tool.updated … · pingdotgg/t3code@66d0ce4
File treeExpand file treeCollapse file tree Open diff view settings apps/server/src/orchestration/Layers
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.activity.test.ts +60Lines changed: 60 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -82,3 +82,63 @@ describe("runtimeEventToActivities task progress", () => { | 82 | 82 | expect(usagePayload).not.toHaveProperty("status"); | 83 | 83 | }); | 84 | 84 | }); | | 85 | +describe("runtimeEventToActivities tool streaming persistence", () => { | | 86 | + const accumulatedStdout = [ | | 87 | + "first line of output", | | 88 | + ...Array.from({ length: 500 }, (_, index) => `Capturing frame ${index}/9028`), | | 89 | + ].join("\n"); | | 90 | + const streamingData = { | | 91 | + toolCallId: "tool-call-1", | | 92 | + kind: "execute", | | 93 | + command: "blender --render", | | 94 | + rawOutput: { stdout: accumulatedStdout }, | | 95 | + content: [{ type: "content", content: { type: "text", text: accumulatedStdout } }], | | 96 | + }; | | 97 | + | | 98 | + it("persists tool.updated with the wire projection of data, not the accumulated stream", () => { | | 99 | + const event = { | | 100 | + ...base, | | 101 | + type: "item.updated", | | 102 | + eventId: EventId.make("evt-tool-streaming-updated"), | | 103 | + payload: { | | 104 | + itemType: "command_execution", | | 105 | + status: "inProgress", | | 106 | + title: "Render", | | 107 | + detail: accumulatedStdout, | | 108 | + data: streamingData, | | 109 | + }, | | 110 | + } satisfies ProviderRuntimeEvent; | | 111 | + | | 112 | + const activities = runtimeEventToActivities(event); | | 113 | + | | 114 | + expect(activities).toHaveLength(1); | | 115 | + const payload = activities[0]?.payload as Record<string, unknown>; | | 116 | + const data = payload.data as Record<string, unknown>; | | 117 | + expect(payload.status).toBe("inProgress"); | | 118 | + expect(data.toolCallId).toBe("tool-call-1"); | | 119 | + expect(data.command).toBe("blender --render"); | | 120 | + expect(data.rawOutput).toEqual({ content: "first line of output" }); | | 121 | + expect(data.content).toBeUndefined(); | | 122 | + expect(JSON.stringify(data).length).toBeLessThan(1_000); | | 123 | + }); | | 124 | + | | 125 | + it("persists the full terminal payload on tool.completed", () => { | | 126 | + const event = { | | 127 | + ...base, | | 128 | + type: "item.completed", | | 129 | + eventId: EventId.make("evt-tool-streaming-completed"), | | 130 | + payload: { | | 131 | + itemType: "command_execution", | | 132 | + status: "completed", | | 133 | + title: "Render", | | 134 | + data: streamingData, | | 135 | + }, | | 136 | + } satisfies ProviderRuntimeEvent; | | 137 | + | | 138 | + const activities = runtimeEventToActivities(event); | | 139 | + | | 140 | + expect(activities).toHaveLength(1); | | 141 | + const payload = activities[0]?.payload as Record<string, unknown>; | | 142 | + expect(payload.data).toEqual(streamingData); | | 143 | + }); | | 144 | +}); |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts +10-2Lines changed: 10 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -41,6 +41,7 @@ import { | 41 | 41 | ProviderRuntimeIngestionService, | 42 | 42 | type ProviderRuntimeIngestionShape, | 43 | 43 | } from "../Services/ProviderRuntimeIngestion.ts"; | | 44 | +import { projectActivityPayload } from "../ActivityPayloadProjection.ts"; | 44 | 45 | import { forkParked } from "../../serverActivation.ts"; | 45 | 46 | import { ServerSettingsService } from "../../serverSettings.ts"; | 46 | 47 |
| @@ -785,8 +786,15 @@ export function runtimeEventToActivities( | 785 | 786 | if (!isToolLifecycleItemType(event.payload.itemType)) { | 786 | 787 | return []; | 787 | 788 | } | | 789 | + // A streaming update's `data` carries the full tool output accumulated | | 790 | + // so far (adapters merge state forward), and a new activity is emitted | | 791 | + // per chunk, so persisting `data` verbatim writes O(N²) bytes per tool | | 792 | + // call into both the event store and the projection table. No reader | | 793 | + // needs it: ws.ts and http.ts apply `projectActivityPayload` before any | | 794 | + // payload reaches a client. Persist the projected form for non-terminal | | 795 | + // updates; `item.completed` below still persists the full payload. | 788 | 796 | return [ | 789 | | - { | | 797 | + projectActivityPayload({ | 790 | 798 | id: event.eventId, | 791 | 799 | createdAt: event.createdAt, | 792 | 800 | tone: "tool", | @@ -804,7 +812,7 @@ export function runtimeEventToActivities( | 804 | 812 | }, | 805 | 813 | turnId: toTurnId(event.turnId) ?? null, | 806 | 814 | ...maybeSequence, | 807 | | - }, | | 815 | + }), | 808 | 816 | ]; | 809 | 817 | } | 810 | 818 |
| |
|