Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

fix(community): write initial status for new bots

Gus187dbf8b3a01
diff --git a/src/ws-do/src/ws-durable.test.ts b/src/ws-do/src/ws-durable.test.ts
index 0584814c6..1d094bbc0 100644
--- a/src/ws-do/src/ws-durable.test.ts
+++ b/src/ws-do/src/ws-durable.test.ts
@@ -1388,6 +1388,33 @@ describe("WebSocketDurableObject", () => {
expect(mockStubFetch).not.toHaveBeenCalled()
})
+ it("regression #3b — a BRAND-NEW bot (profile row exists but status unset: emoji=null, text=\"\") still gets its status written", async () => {
+ // `status_text` defaults to "" in the schema, so an unset status reads
+ // back as (null, "") not (null, null). The custom-status guard must treat
+ // that as "no status" (writable), NOT mistake "" for a custom status —
+ // otherwise new bots never get a pill (the reported regression).
+ const { durable, store } = createDO()
+ store.set("community-machine-identity", {
+ userId: "u_1",
+ machineId: "cm_1",
+ credentialHash: "0".repeat(64),
+ })
+ mockGetBotBinding.mockResolvedValue({ machineId: "cm_1", runtime: "codex" })
+ mockGetCoMemberUserIds.mockResolvedValue(["viewer-1"])
+ mockGetProfile.mockResolvedValue({ statusEmoji: null, statusText: "" })
+
+ const ws = createMockWebSocket()
+ ws.serializeAttachment({ type: "community-machine", machineId: "cm_1", userId: "u_1", authenticated: true })
+
+ const frame = JSON.stringify({ type: "agent_activity", agentId: "bot_1", state: "running" })
+ await durable.webSocketMessage(ws as any, frame)
+
+ expect(mockUpdateProfile).toHaveBeenCalledWith(expect.anything(), "bot_1", {
+ statusEmoji: "⚡",
+ statusText: "Working on it",
+ })
+ })
+
it("regression #4 — a known idle preset still flips to running (guard didn't over-reach)", async () => {
const { durable, store } = createDO()
store.set("community-machine-identity", {
diff --git a/src/ws-do/src/ws-durable.ts b/src/ws-do/src/ws-durable.ts
index 8eeb72179..0532d7e2e 100644
--- a/src/ws-do/src/ws-durable.ts
+++ b/src/ws-do/src/ws-durable.ts
@@ -796,12 +796,15 @@ export class WebSocketDurableObject extends DurableObject<Env> {
write: async () => {
const prior = await queries.communityUserProfile.getProfile(db, agentId)
const priorEmoji = prior?.statusEmoji ?? null
- const priorText = prior?.statusText ?? null
+ // `status_text` defaults to "" (schema), so an unset status reads back
+ // as (null, "") not (null, null). Normalize "" → null so "no status"
+ // is treated uniformly as writable, not mistaken for a custom status.
+ const priorText = prior?.statusText ? prior.statusText : null
// The activity pipeline only owns pills it wrote itself. If the bot
// carries an owner-set custom status (a non-preset pair), leave it —
// matches the reconciler's declared intent and stops the heartbeat
- // re-assert from stomping a custom status every interval. A null pair
- // (no status yet) is still writable.
+ // re-assert from stomping a custom status every interval. An empty
+ // pair (no status yet) is still writable.
if (
(priorEmoji !== null || priorText !== null) &&
!isBotActivityStatus(priorEmoji, priorText)