Repository navigation
fix(server): an agent can mark its own thread unread when its turn ends #24157
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.
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
dfedee3
7e25929
2477eca
19235a6
6831fad
ee96b4b
08b1f88
27d803c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -415,6 +415,26 @@ export interface ThreadManagementServiceShape { | |
| { readonly sequence: number } | { readonly settlesWhenTurnEnds: true }, | ||
| Orchestrator.OrchestratorV2Error | ThreadManagementProviderInstanceDisabledError | ||
| >; | ||
| /** | ||
| * Marking unread rewinds the visit to just before the latest run completed, | ||
| * so an agent that marks its own thread unread uses this to wait for its | ||
| * turn to end. A run that ends any other way leaves the thread as it was, | ||
| * as does anything `thread.mark-unread` refuses then, such as a queued | ||
| * message. | ||
| */ | ||
| readonly markUnreadAfterRun: (input: { | ||
| readonly projectId: ProjectId; | ||
| readonly threadId: ThreadId; | ||
| readonly runId: RunId; | ||
| }) => Effect.Effect<void, ThreadManagementFailure>; | ||
| readonly markThreadUnread: (input: { | ||
| readonly threadId: ThreadId; | ||
| readonly commandId: CommandId; | ||
| readonly byOwnAgent: boolean; | ||
| }) => Effect.Effect< | ||
| { readonly sequence: number } | { readonly marksUnreadWhenTurnEnds: true }, | ||
| Orchestrator.OrchestratorV2Error | ThreadManagementProviderInstanceDisabledError | ||
| >; | ||
| readonly interruptThread: ( | ||
| input: ThreadManagementInterruptInput, | ||
| ) => Effect.Effect<ThreadManagementInterruptResult, ThreadManagementFailure>; | ||
|
|
@@ -505,7 +525,7 @@ function latestSteerableRun( | |
| .toSorted((left, right) => right.ordinal - left.ordinal)[0]; | ||
| } | ||
|
|
||
| const SETTLE_AFTER_RUN_WAIT_MS = 24 * 60 * 60 * 1_000; | ||
| const AFTER_RUN_WAIT_MS = 24 * 60 * 60 * 1_000; | ||
|
|
||
| const make = Effect.gen(function* () { | ||
| const threadDispatch = yield* ThreadCommandExecutor.ThreadCommandExecutor; | ||
|
|
@@ -932,7 +952,7 @@ const make = Effect.gen(function* () { | |
| const settleAfterRun: ThreadManagementServiceShape["settleAfterRun"] = Effect.fn( | ||
| "orchestrationV2.threadManagement.settleAfterRun", | ||
| )(function* (input) { | ||
| const { run } = yield* waitForThread({ ...input, timeoutMs: SETTLE_AFTER_RUN_WAIT_MS }); | ||
| const { run } = yield* waitForThread({ ...input, timeoutMs: AFTER_RUN_WAIT_MS }); | ||
| if (run?.status !== "completed") return; | ||
| yield* dispatch({ | ||
| type: "thread.settle", | ||
|
|
@@ -961,6 +981,38 @@ const make = Effect.gen(function* () { | |
| return { sequence: result.sequence }; | ||
| }); | ||
|
|
||
| const markUnreadAfterRun: ThreadManagementServiceShape["markUnreadAfterRun"] = Effect.fn( | ||
| "orchestrationV2.threadManagement.markUnreadAfterRun", | ||
| )(function* (input) { | ||
| const { run } = yield* waitForThread({ ...input, timeoutMs: AFTER_RUN_WAIT_MS }); | ||
| if (run?.status !== "completed") return; | ||
| yield* dispatch({ | ||
| type: "thread.mark-unread", | ||
| commandId: CommandId.make(`server:mark-unread-after-run:${input.runId}`), | ||
| threadId: input.threadId, | ||
| }); | ||
|
Comment on lines
+988
to
+993
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win 🔎 Supported by static analysis
Preserve newer visits during deferred marking.
🤖 Prompt for AI Agents
|
||
| }); | ||
|
|
||
| const markThreadUnread: ThreadManagementServiceShape["markThreadUnread"] = Effect.fn( | ||
| "orchestrationV2.threadManagement.markThreadUnread", | ||
| )(function* (input) { | ||
| const shell = input.byOwnAgent ? yield* orchestrator.getThreadShell(input.threadId) : null; | ||
| if (shell != null && shell.activeRunId !== null) { | ||
| yield* markUnreadAfterRun({ | ||
| projectId: shell.projectId, | ||
| threadId: shell.id, | ||
| runId: shell.activeRunId, | ||
| }).pipe(Effect.ignoreCause({ log: true }), Effect.forkIn(layerScope)); | ||
| return { marksUnreadWhenTurnEnds: true } as const; | ||
| } | ||
| const result = yield* dispatch({ | ||
| type: "thread.mark-unread", | ||
| commandId: input.commandId, | ||
| threadId: input.threadId, | ||
| }); | ||
| return { sequence: result.sequence }; | ||
| }); | ||
|
|
||
| const interruptThread: ThreadManagementServiceShape["interruptThread"] = Effect.fn( | ||
| "ThreadManagementService.interruptThread", | ||
| )(function* (input) { | ||
|
|
@@ -1186,6 +1238,8 @@ const make = Effect.gen(function* () { | |
| waitForThread, | ||
| settleAfterRun, | ||
| settleThread, | ||
| markUnreadAfterRun, | ||
| markThreadUnread, | ||
| interruptThread, | ||
| stopDelegatedTasks, | ||
| stopWorkflow, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Do not mark unread when the wait times out.
waitForThreadcan return a completed run withtimedOut: truewhile a restart continuation is still pending. This status-only check then dispatchesthread.mark-unreadbefore the turn finishes. ChecktimedOutas well asrun.statusbefore dispatching.🤖 Prompt for AI Agents