fix(ai): handle client tool waits as invocation boundaries #996
main fromrefs/pull/996/headmerged by AlemTuzlak View on GitHub- packages/ai/src/activities/chat/index.ts lines 1277 to 1281Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -1037,5 +1070,6 @@1037107010381071 const pendingPhase = yield* this.checkForPendingToolCalls()10391072 if (pendingPhase === 'wait') {1073+ await this.runTerminalHook()10401074 return10411075 }testing/e2e/tests/client-tool-wait.spec.ts lines 49 to 71OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +51,21 @@51+ `${baseURL ?? ''}/api/middleware-test?testId=${encodeURIComponent(testId)}`,52+ )53+ expect(captureResponse.ok()).toBe(true)54+ const capture = await captureResponse.json()55+56+ const rootSpans = capture.spans.filter(57+ (span: any) => span.kind === SpanKind.INTERNAL,58+ )59+ expect(rootSpans).toHaveLength(1)60+ expect(rootSpans[0].ended).toBe(true)61+62+ const iterationSpans = capture.spans.filter(63+ (span: any) => span.kind === SpanKind.CLIENT,64+ )65+ expect(iterationSpans).toHaveLength(1)66+ expect(iterationSpans[0].ended).toBe(true)67+68+ const durationRecords = capture.histograms.filter(69+ (record: any) => record.name === 'gen_ai.client.operation.duration',70+ )71+ expect(durationRecords).toHaveLength(1)
JsonKim(GitHub profile, opens in a new tab) changed the title
github-actions[bot](GitHub profile, opens in a new tab) assignedAlemTuzlak
github-actions[bot](GitHub profile, opens in a new tab) added labelswaiting-on: maintainer
github-actions[bot](GitHub profile, opens in a new tab) added labelsmerge-conflicts
github-actions[bot](GitHub profile, opens in a new tab) added labelswaiting-on: author
github-actions[bot](GitHub profile, opens in a new tab) removed labelswaiting-on: maintainer
github-actions[bot](GitHub profile, opens in a new tab) added labelswaiting-on: maintainer
github-actions[bot](GitHub profile, opens in a new tab) removed labelswaiting-on: author
github-actions[bot](GitHub profile, opens in a new tab) removed labelsmerge-conflicts
github-actions[bot](GitHub profile, opens in a new tab) added labelsmerge-conflicts
github-actions[bot](GitHub profile, opens in a new tab) added labelswaiting-on: author
github-actions[bot](GitHub profile, opens in a new tab) removed labelswaiting-on: maintainer
tombeckenham removed labelsmerge-conflicts
github-actions[bot](GitHub profile, opens in a new tab) added labelswaiting-on: maintainer
github-actions[bot](GitHub profile, opens in a new tab) removed labelswaiting-on: author
github-actions[bot](GitHub profile, opens in a new tab) added labelsmerge-conflicts
github-actions[bot](GitHub profile, opens in a new tab) added labelswaiting-on: author
github-actions[bot](GitHub profile, opens in a new tab) removed labelswaiting-on: maintainer
github-actions[bot](GitHub profile, opens in a new tab) added labelswaiting-on: maintainer
github-actions[bot](GitHub profile, opens in a new tab) removed labelswaiting-on: author
github-actions[bot](GitHub profile, opens in a new tab) removed labelsmerge-conflicts
github-actions[bot](GitHub profile, opens in a new tab) added labelswaiting-on: author
github-actions[bot](GitHub profile, opens in a new tab) removed labelswaiting-on: maintainer
github-actions[bot](GitHub profile, opens in a new tab) added labelswaiting-on: maintainer
github-actions[bot](GitHub profile, opens in a new tab) removed labelswaiting-on: author
github-actions[bot](GitHub profile, opens in a new tab) added labelswaiting-on: author
github-actions[bot](GitHub profile, opens in a new tab) removed labelswaiting-on: maintainer
github-actions[bot](GitHub profile, opens in a new tab) added labelswaiting-on: maintainer
github-actions[bot](GitHub profile, opens in a new tab) removed labelswaiting-on: author
github-actions[bot](GitHub profile, opens in a new tab) added labelswaiting-on: author
github-actions[bot](GitHub profile, opens in a new tab) removed labelswaiting-on: maintainer
github-actions[bot](GitHub profile, opens in a new tab) added labelswaiting-on: maintainer
github-actions[bot](GitHub profile, opens in a new tab) removed labelswaiting-on: author
AlemTuzlak approved these changes
AlemTuzlak merged thisc54e20c
AlemTuzlak closed this
Sign in to join this conversation.
Note
Reviews paused#
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the
reviews.auto_review.auto_pause_after_reviewed_commitssetting.Use the following commands to manage reviews:
@coderabbitai resumeto resume automatic reviews.@coderabbitai reviewto trigger a single review.Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID:
ad5322b3-08cf-4880-b454-8936f78ea751📥 Commits
Reviewing files that changed from the base of the PR and between efe3b07688a29960a4b3e25c44219a253bb75a00 and 82ffe0404362b029630064b20b83f2b3d1a03a45.
📒 Files selected for processing (8)
.changeset/fuzzy-tools-wait.mdpackages/ai/src/activities/chat/index.tspackages/ai/tests/chat-client-tool-wait.test.tstesting/e2e/fixtures/middleware-test/structured-client-tool-wait.jsontesting/e2e/src/lib/middleware-test-tools.tstesting/e2e/src/routes/api.middleware-test.tstesting/e2e/src/routes/middleware-test.tsxtesting/e2e/tests/client-tool-wait.spec.ts🚧 Files skipped from review as they are similar to previous changes (8)
📝 Walkthrough
Walkthrough#
The chat activity now completes terminal middleware hooks during client-tool and approval waits. Structured-output finalization remains pending until a later invocation receives the client result. Unit and end-to-end tests cover lifecycle callbacks, telemetry, deferred output, and client-tool resolution.
Changes#
Client-tool wait lifecycle
packages/ai/src/activities/chat/index.ts,.changeset/fuzzy-tools-wait.mdonError, and invokes the hook for pending and completed paths.packages/ai/tests/chat-client-tool-wait.test.tstesting/e2e/src/lib/middleware-test-tools.ts,testing/e2e/fixtures/...,testing/e2e/src/routes/...,testing/e2e/tests/client-tool-wait.spec.tsEstimated code review effort: 3 (Moderate) | ~25 minutes
Sequence Diagram(s)#
Possibly related PRs
Suggested reviewers:
alemtuzlakMergeability Score: ⚪ Minimal · up to
82ffeThe PR updates client-tool wait lifecycle handling and structured-output resumption with focused unit and end-to-end coverage; no actionable merge-blocking risk remains, so it is ready after normal checks and review.
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
✅ Passed checks (4 passed)
#1028, including middleware completion, telemetry, error handling, and deferred structured-output finalization.✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share