GeezerVison is showing github.com — Skip stale working-task notifications (#3961) · darjss/t3code@10891bb
File treeExpand file treeCollapse file tree Open diff view settings infra/relay/src/agentActivity
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/server/src/relay/AgentAwarenessRelay.test.ts +11-2Lines changed: 11 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -137,7 +137,7 @@ describe.sequential("signRelayAgentActivityPublishProof", () => { | 137 | 137 | expect(AgentAwarenessRelay.eventThreadId(event)).toBe(threadId); | 138 | 138 | }); | 139 | 139 |
| 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", () => { | 141 | 141 | const now = "2026-05-25T00:00:00.000Z"; | 142 | 142 | const base = { | 143 | 143 | sequence: 1, | @@ -191,7 +191,16 @@ describe.sequential("signRelayAgentActivityPublishProof", () => { | 191 | 191 | streaming: false, | 192 | 192 | }, | 193 | 193 | } 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); | 195 | 204 | }); | 196 | 205 |
| 197 | 206 | it("deduplicates awareness state updates whose only change is their event timestamp", () => { | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/relay/AgentAwarenessRelay.ts +7-1Lines changed: 7 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -67,7 +67,13 @@ export function eventThreadId(event: OrchestrationEvent): ThreadId | null { | 67 | 67 | export function shouldPublishAgentAwarenessEvent(event: OrchestrationEvent): boolean { | 68 | 68 | switch (event.type) { | 69 | 69 | 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; | 71 | 77 | case "thread.proposed-plan-upserted": | 72 | 78 | case "thread.runtime-mode-set": | 73 | 79 | case "thread.interaction-mode-set": | |
Collapse file Copy file name to clipboardExpand all lines: infra/relay/src/agentActivity/AgentActivityPublisher.test.ts +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -64,6 +64,7 @@ function makeAgentActivityRows( | 64 | 64 | remove: () => Effect.void, | 65 | 65 | pruneTerminal: () => Effect.void, | 66 | 66 | listForUser: () => Effect.succeed([state]), | | 67 | + getForUserThread: () => Effect.succeed(state), | 67 | 68 | ...overrides, | 68 | 69 | }; | 69 | 70 | } | |
Collapse file Copy file name to clipboardExpand all lines: infra/relay/src/agentActivity/AgentActivityRows.test.ts +9Lines changed: 9 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -75,6 +75,15 @@ describe("AgentActivityRows", () => { | 75 | 75 | const listError = yield* rows.listForUser({ userId: "user-2" }).pipe(Effect.flip); | 76 | 76 | expect(listError).toMatchObject({ userId: "user-2", cause }); | 77 | 77 | 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 }); | 78 | 87 | }).pipe( | 79 | 88 | Effect.provide( | 80 | 89 | AgentActivityRows.layer.pipe(Layer.provide(Layer.succeed(RelayDb.RelayDb, failingDb))), | |
Collapse file Copy file name to clipboardExpand all lines: infra/relay/src/agentActivity/AgentActivityRows.ts +53Lines changed: 53 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -83,6 +83,11 @@ export class AgentActivityRows extends Context.Service< | 83 | 83 | ReadonlyArray<RelayAgentActivityState>, | 84 | 84 | AgentActivityRowListPersistenceError | 85 | 85 | >; | | 86 | + readonly getForUserThread: (input: { | | 87 | + readonly userId: string; | | 88 | + readonly environmentId: string; | | 89 | + readonly threadId: string; | | 90 | + }) => Effect.Effect<RelayAgentActivityState | null, AgentActivityRowListPersistenceError>; | 86 | 91 | } | 87 | 92 | >()("t3code-relay/agentActivity/AgentActivityRows") {} | 88 | 93 |
| @@ -241,6 +246,54 @@ export const make = Effect.gen(function* () { | 241 | 246 | ), | 242 | 247 | ); | 243 | 248 | }), | | 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 | + }), | 244 | 297 | }); | 245 | 298 | }); | 246 | 299 |
| |
|