Skip to content

Commit ba371bd

Browse files
Skip stale working-task notifications
- Stop publishing start-intent awareness snapshots - Recheck queued APNs jobs against current activity state
1 parent c1ec191 commit ba371bd

9 files changed

Lines changed: 406 additions & 13 deletions

‎apps/server/src/relay/AgentAwarenessRelay.test.ts‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ describe.sequential("signRelayAgentActivityPublishProof", () => {
137137
expect(AgentAwarenessRelay.eventThreadId(event)).toBe(threadId);
138138
});
139139

140-
it("does not publish streaming content or non-awareness activity events", () => {
140+
it("does not publish start intents, streaming content, or non-awareness activity events", () => {
141141
const now = "2026-05-25T00:00:00.000Z";
142142
const base = {
143143
sequence: 1,
@@ -191,7 +191,16 @@ describe.sequential("signRelayAgentActivityPublishProof", () => {
191191
streaming: false,
192192
},
193193
} as unknown as OrchestrationEvent),
194-
).toBe(true);
194+
).toBe(false);
195+
expect(
196+
AgentAwarenessRelay.shouldPublishAgentAwarenessEvent({
197+
...base,
198+
type: "thread.turn-start-requested",
199+
payload: {
200+
threadId: "thread-1" as ThreadId,
201+
},
202+
} as unknown as OrchestrationEvent),
203+
).toBe(false);
195204
});
196205

197206
it("deduplicates awareness state updates whose only change is their event timestamp", () => {

‎apps/server/src/relay/AgentAwarenessRelay.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,13 @@ export function eventThreadId(event: OrchestrationEvent): ThreadId | null {
6767
export function shouldPublishAgentAwarenessEvent(event: OrchestrationEvent): boolean {
6868
switch (event.type) {
6969
case "thread.message-sent":
70-
return !event.payload.streaming;
70+
case "thread.turn-start-requested":
71+
// These events express intent to start work, but the shell still contains
72+
// the previous turn's terminal state until the provider acknowledges the
73+
// new turn. Publishing that snapshot can queue a fresh "Done" alert just
74+
// before the real running state arrives. Provider lifecycle events publish
75+
// the authoritative starting/running state instead.
76+
return false;
7177
case "thread.proposed-plan-upserted":
7278
case "thread.runtime-mode-set":
7379
case "thread.interaction-mode-set":

‎infra/relay/src/agentActivity/AgentActivityPublisher.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ function makeAgentActivityRows(
6464
remove: () => Effect.void,
6565
pruneTerminal: () => Effect.void,
6666
listForUser: () => Effect.succeed([state]),
67+
getForUserThread: () => Effect.succeed(state),
6768
...overrides,
6869
};
6970
}

‎infra/relay/src/agentActivity/AgentActivityRows.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,15 @@ describe("AgentActivityRows", () => {
7575
const listError = yield* rows.listForUser({ userId: "user-2" }).pipe(Effect.flip);
7676
expect(listError).toMatchObject({ userId: "user-2", cause });
7777
expect(listError.message).toBe("Failed to list agent activity state for user user-2.");
78+
79+
const getError = yield* rows
80+
.getForUserThread({
81+
userId: "user-2",
82+
environmentId: "env-1",
83+
threadId: "thread-1",
84+
})
85+
.pipe(Effect.flip);
86+
expect(getError).toMatchObject({ userId: "user-2", cause });
7887
}).pipe(
7988
Effect.provide(
8089
AgentActivityRows.layer.pipe(Layer.provide(Layer.succeed(RelayDb.RelayDb, failingDb))),

‎infra/relay/src/agentActivity/AgentActivityRows.ts‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ export class AgentActivityRows extends Context.Service<
8383
ReadonlyArray<RelayAgentActivityState>,
8484
AgentActivityRowListPersistenceError
8585
>;
86+
readonly getForUserThread: (input: {
87+
readonly userId: string;
88+
readonly environmentId: string;
89+
readonly threadId: string;
90+
}) => Effect.Effect<RelayAgentActivityState | null, AgentActivityRowListPersistenceError>;
8691
}
8792
>()("t3code-relay/agentActivity/AgentActivityRows") {}
8893

@@ -241,6 +246,54 @@ export const make = Effect.gen(function* () {
241246
),
242247
);
243248
}),
249+
250+
getForUserThread: Effect.fn("relay.agent_activity_rows.get_for_user_thread")(function* (input) {
251+
return yield* db
252+
.select({ stateJson: relayAgentActivityRows.stateJson })
253+
.from(relayAgentActivityRows)
254+
.innerJoin(
255+
relayEnvironmentLinks,
256+
and(
257+
eq(relayEnvironmentLinks.environmentId, relayAgentActivityRows.environmentId),
258+
eq(
259+
relayEnvironmentLinks.environmentPublicKey,
260+
relayAgentActivityRows.environmentPublicKey,
261+
),
262+
),
263+
)
264+
.where(
265+
and(
266+
eq(relayEnvironmentLinks.userId, input.userId),
267+
isNull(relayEnvironmentLinks.revokedAt),
268+
eq(relayAgentActivityRows.environmentId, input.environmentId),
269+
eq(relayAgentActivityRows.threadId, input.threadId),
270+
),
271+
)
272+
.orderBy(desc(relayAgentActivityRows.updatedAt))
273+
.pipe(
274+
Effect.flatMap((rows) =>
275+
Effect.forEach(rows, (row) => encodeJsonValue(row.stateJson), {
276+
concurrency: "unbounded",
277+
}),
278+
),
279+
Effect.map((rows) => {
280+
for (const row of rows) {
281+
const decoded = decodeRelayAgentActivityStateJson(row);
282+
if (Option.isSome(decoded)) {
283+
return decoded.value;
284+
}
285+
}
286+
return null;
287+
}),
288+
Effect.mapError(
289+
(cause) =>
290+
new AgentActivityRowListPersistenceError({
291+
userId: input.userId,
292+
cause,
293+
}),
294+
),
295+
);
296+
}),
244297
});
245298
});
246299

0 commit comments

Comments
 (0)