-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Guard provider lifecycle and checkpoints to primary thread/active turn #106
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
Changes from all commits
d19b2f5
7dab240
5b13d20
4e3e689
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 |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ import { | |
| EventId, | ||
| MessageId, | ||
| ProviderSessionId, | ||
| ProviderThreadId, | ||
| ThreadId, | ||
| TurnId, | ||
| type OrchestrationEvent, | ||
|
|
@@ -36,6 +37,17 @@ function toTurnId(value: string | undefined): TurnId | null { | |
| return value === undefined ? null : TurnId.makeUnsafe(value); | ||
| } | ||
|
|
||
| function toProviderThreadId(value: string | undefined): ProviderThreadId | null { | ||
| return value === undefined ? null : ProviderThreadId.makeUnsafe(value); | ||
| } | ||
|
|
||
| function sameId(left: string | null | undefined, right: string | null | undefined): boolean { | ||
| if (left === null || left === undefined || right === null || right === undefined) { | ||
| return false; | ||
| } | ||
| return left === right; | ||
| } | ||
|
|
||
| function checkpointStatusFromRuntime(status: string | undefined): "ready" | "missing" | "error" { | ||
| switch (status) { | ||
| case "failed": | ||
|
|
@@ -173,6 +185,21 @@ const make = Effect.gen(function* () { | |
| return; | ||
| } | ||
|
|
||
| const projectedProviderThreadId = thread.session?.providerThreadId ?? null; | ||
| const eventProviderThreadId = toProviderThreadId(event.threadId); | ||
| if ( | ||
| projectedProviderThreadId !== null && | ||
| eventProviderThreadId !== null && | ||
| !sameId(projectedProviderThreadId, eventProviderThreadId) | ||
| ) { | ||
| return; | ||
| } | ||
|
|
||
| // When a primary turn is active, only that turn may produce completion checkpoints. | ||
| if (thread.session?.activeTurnId && !sameId(thread.session.activeTurnId, turnId)) { | ||
|
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. 🟡 Medium Race condition: 🚀 Reply "fix it for me" or copy this AI Prompt for your agent: |
||
| return; | ||
| } | ||
|
|
||
| if (thread.checkpoints.some((checkpoint) => checkpoint.turnId === turnId)) { | ||
| return; | ||
| } | ||
|
|
||
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.
Remove timing-based mid-assertion to avoid flaky/false-positive behavior.
Line 438 uses a fixed sleep, and Line 441 can pass before the auxiliary event is actually processed. This makes the test nondeterministic under load.
♻️ Suggested test hardening
Based on learnings: "For integration tests: Prefer deterministic inputs and explicit state checks; avoid relying on logs or timing assumptions."
🤖 Prompt for AI Agents