GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — perf: make streaming projection and activity appends incremental by t3dotgg · Pull Request #9152 · pingdotgg/t3code

perf: make streaming projection and activity appends incremental #9152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
t3dotgg merged 4 commits into main from t3code/streaming-projection-incremental
Sep 2, 2026

Uh oh!

There was an error while loading. Please reload this page.

Merged

perf: make streaming projection and activity appends incremental #9152

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit Hold shift + click to select a range
a03016a
perf: make streaming projection and activity appends incremental
x1xhlol Aug 14, 2026
a80ec34
perf: index activity ids so streamed appends stop rescanning history
x1xhlol Aug 14, 2026
f9951e9
fix: gate the activity append fast path on reducer-produced ordering
x1xhlol Aug 14, 2026
c5ce425
test(server): trigger the shell summary refresh with a lifecycle acti…
t3dotgg Sep 2, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view
Prev Previous commit
Next Next commit
perf: index activity ids so streamed appends stop rescanning history
  • Loading branch information

Uh oh!

There was an error while loading. Please reload this page.

@x1xhlol @t3dotgg
x1xhlol authored and t3dotgg committed Sep 2, 2026
commit a80ec34eec15a3c99c0735ac4884fbcdb0ce7c95

There are no files selected for viewing

43 changes: 43 additions & 0 deletions 43 packages/client-runtime/src/state/threadReducer.test.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,49 @@ describe("applyThreadDetailEvent", () => {
}
});

it("dedupes a re-delivery arriving right after an in-order append", () => {
const makeActivity = (id: string, sequence: number, summary: string) => ({
id: EventId.make(id),
tone: "tool" as const,
kind: "command",
summary,
payload: {},
turnId: TurnId.make("turn-1"),
sequence,
createdAt: "2026-04-01T11:00:00.000Z",
});
const makeEvent = (sequence: number, activity: ReturnType<typeof makeActivity>) =>
({
...baseEventFields,
sequence,
occurredAt: "2026-04-01T11:01:00.000Z",
aggregateKind: "thread",
aggregateId: ThreadId.make("thread-1"),
type: "thread.activity-appended",
payload: { threadId: ThreadId.make("thread-1"), activity },
}) as const;
const first = applyThreadDetailEvent(
{ ...baseThread, activities: [makeActivity("activity-a", 1, "first")] },
makeEvent(133, makeActivity("activity-b", 2, "second")),
);
expect(first.kind).toBe("updated");
if (first.kind !== "updated") {
return;
}
const second = applyThreadDetailEvent(
first.thread,
makeEvent(134, makeActivity("activity-b", 3, "second (redelivered)")),
);
expect(second.kind).toBe("updated");
if (second.kind === "updated") {
expect(second.thread.activities.map((activity) => activity.id)).toEqual([
"activity-a",
"activity-b",
]);
expect(second.thread.activities[1]?.summary).toBe("second (redelivered)");
}
});

it("replaces a re-delivered activity instead of duplicating it", () => {
const makeActivity = (id: string, sequence: number, summary: string) => ({
id: EventId.make(id),
Expand Down
34 changes: 32 additions & 2 deletions 34 packages/client-runtime/src/state/threadReducer.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,29 @@ const activityOrder = O.combineAll<OrchestrationThreadActivity>([
O.mapInput(O.String, (a) => a.id),
]);

/**
* Id index for each activities array, so the streaming append path can check
* for a re-delivered id without scanning the whole history per event. Keyed
* by array identity: the append path moves the set forward to the array it
* produces, and any array reduced without a cached set (an older state, a
* snapshot) rebuilds it once.
*/
const activityIdIndex = new WeakMap<
ReadonlyArray<OrchestrationThreadActivity>,
Set<OrchestrationThreadActivity["id"]>
>();

function activityIds(
activities: ReadonlyArray<OrchestrationThreadActivity>,
): Set<OrchestrationThreadActivity["id"]> {
let ids = activityIdIndex.get(activities);
if (ids === undefined) {
ids = new Set(activities.map((activity) => activity.id));
activityIdIndex.set(activities, ids);
}
return ids;
}

/**
* Matches the validity rule in `deriveLatestContextWindowSnapshot` (and the
* server's snapshot-side `dropStaleContextWindowActivities`): rows without a
Expand Down Expand Up @@ -589,13 +612,20 @@ export function applyThreadDetailEvent(
if (
!supersedesContextWindow &&
(lastActivity === undefined || activityOrder(lastActivity, activity) <= 0) &&
!thread.activities.some((entry) => entry.id === activity.id)
!activityIds(thread.activities).has(activity.id)
) {
const activities = Arr.append(thread.activities, activity);
// Move the id set forward instead of copying it: the superseded array
// rebuilds its set on the off chance it is reduced against again.
const ids = activityIds(thread.activities);
activityIdIndex.delete(thread.activities);
ids.add(activity.id);
activityIdIndex.set(activities, ids);
return {
kind: "updated",
thread: {
...thread,
activities: Arr.append(thread.activities, activity),
activities,
updatedAt: event.occurredAt,
},
};
Expand Down
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.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.