Open-source AI coworkers that each get a computer of their own: a browser, files and tools, with every action decided before it happens and recorded after. Bring any AG-UI agent.
Keep a channel cursor to the microsecond so no channel falls between pages (#689)
Omkar Chebalef0929a37638b
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 6c5401d0..318bf25b 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -8,6 +8,13 @@ Newest first. `Unreleased` is what is on `main` and not yet tagged.## Unreleased+### The channel list no longer skips channels made in the same millisecond++The channel list's page cursor kept the last channel's time to the millisecond, while PostgreSQL+keeps it to the microsecond. Channels later in that same millisecond, as a package sync or an+import makes them, sorted after the cursor and were on no page. The cursor now carries the time to+the microsecond, as the audit trail's cursor already did.+### A package skill's slug has the same shape as one made in the appThe skills screen, the skills API and the store all accept a slug of 2 to 40 lowercase letters,diff --git a/server/src/channels/routes.ts b/server/src/channels/routes.tsindex 91a24aea..2071c60a 100644--- a/server/src/channels/routes.ts+++ b/server/src/channels/routes.ts@@ -443,7 +443,13 @@ export function createChannelStore(const page = await database.select({id: channels.id,- recency: sql<Date>`${RECENCY}`,+ /*+ * To the microsecond, as text, for the cursor only: the audit reader's fix, for the same+ * fault. The column keeps microseconds and a `Date` keeps milliseconds, so a cursor made+ * from a `Date` named a moment just before its own row, and any channel later in that+ * millisecond compared as newer than the cursor and was on no page at all.+ */+ recency: sql<string>`to_char(${RECENCY} at time zone 'UTC', 'YYYY-MM-DD"T"HH24:MI:SS.US"Z"')`,pinned: sql<boolean>`${channelMemberships.pinnedAt} is not null`,}).from(channels)@@ -474,7 +480,7 @@ export function createChannelStore(page.length > limit && last? encodeChannelCursor({pinned: last.pinned,- recency: new Date(last.recency).toISOString(),+ recency: last.recency,id: last.id,}): null;diff --git a/server/tests/channel-activity.integration.test.ts b/server/tests/channel-activity.integration.test.tsindex ab8172de..5a880d3b 100644--- a/server/tests/channel-activity.integration.test.ts+++ b/server/tests/channel-activity.integration.test.ts@@ -1,6 +1,6 @@import { afterAll, afterEach, describe, expect, test } from "bun:test";import { randomUUID } from "node:crypto";-import { eq } from "drizzle-orm";+import { eq, inArray, sql } from "drizzle-orm";import {AgentNotFoundError,createAgentProfileStore,@@ -137,6 +137,35 @@ describe("reading a person's channels", () => {expect(seen.sort()).toEqual(expected.sort());});+ test("channels made in the same millisecond are each on a page", async () => {+ const owner = await createUser();+ const agentId = await createAgent(owner);+ const expected: string[] = [];+ for (let index = 0; index < 5; index += 1) {+ expected.push((await createChannel(owner, [agentId])).id);+ }+ // One transaction's worth of channels, as a package sync or an import makes them: the same+ // instant, kept by PostgreSQL to the microsecond and by a JavaScript `Date` to the millisecond.+ await database+ .update(channels)+ .set({ createdAt: sql`'2026-01-01 00:00:00.123456+00'::timestamptz` })+ .where(inArray(channels.id, expected));++ const seen: string[] = [];+ let cursor: string | undefined;+ for (let page = 0; page < 10; page += 1) {+ const result = await store.list(owner, {+ limit: 2,+ ...(cursor ? { cursor } : {}),+ });+ seen.push(...result.channels.map((channel) => channel.id));+ if (!result.nextCursor) break;+ cursor = result.nextCursor;+ }++ expect(seen.sort()).toEqual(expected.sort());+ });+test("a channel with two Bots is never split across pages", async () => {/** The reason the page is chosen over channels and the agents joined afterwards. Limiting the row