refactor(harness): use @decocms/shared/std's sleep in gemini-interactions poll loop - #5338
Open
pedrofrxncx wants to merge 1 commit into
Open
refactor(harness): use @decocms/shared/std's sleep in gemini-interactions poll loop#5338pedrofrxncx wants to merge 1 commit into
pedrofrxncx wants to merge 1 commit into
Conversation
…ions poll loop Replaces a hand-rolled Promise + setTimeout + AbortController sleep with the canonical @decocms/shared/std sleep primitive already used elsewhere in this package (liveness-heartbeat.ts).
pedrofrxncx
enabled auto-merge (squash)
July 28, 2026 18:08
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Source: C1 reduction — reinvented stdlib.
pollInteraction's poll loop (Gemini Deep Research usage/cost tracking path,packages/harness/src/decopilot/gemini-interactions.ts) hand-rolled anew Promise+setTimeout+AbortControllersleep instead of using@decocms/shared/std's canonicalsleep(ms, { signal }), which is already the established pattern elsewhere in this same package (seeliveness-heartbeat.ts, which explicitly calls out this rule from CLAUDE.md/AGENTS.md).Why a maintainer wants it: one fewer hand-rolled setTimeout/AbortController wait to maintain, consistent with the repo's consolidated async-primitives rule; net line reduction (-11/+7 in the source file).
Behavior preserved:
@decocms/shared/std'ssleepmay reject with a rawAbortSignal.reason(which can be aDOMException, NOTinstanceof Error), whereas callers here (andclassifyStreamError'serror instanceof Error && error.name === "AbortError"check) expect a realError. The replacement keeps the existingmakeAbortErrornormalization by wrapping the sharedsleepcall in a.catch()that re-throws through it — so the rejection shape is byte-identical to before in both the pre-aborted and abort-mid-sleep cases.Regression test: added
gemini-interactions.test.ts, which mocksfetchto abort mid-poll and assertspollInteractionrejects with anErrornamed"AbortError"— this is the case the manual wrapper exists to guarantee, and it would have caught a naive swap-in of the sharedsleepwithout the normalization.Reviewer check:
bun test packages/harness/src/decopilot/gemini-interactions.test.tsLocally verified:
bun run fmt,cd packages/harness && bunx tsc --noEmit(clean), and the targeted test above (1 pass). Full CI validates the rest.Summary by cubic
Replaced the custom sleep in the Gemini interactions poll loop with the shared
sleepfrom@decocms/shared/std, keeping abort behavior identical. Added a regression test to ensure aborts still throw an Error named "AbortError".@decocms/shared/std'ssleep(ms, { signal })inpollInteractioninstead of a manual Promise/timeout.sleeprejections and rethrow viamakeAbortErrorto preserve the exactErrorshape for pre-abort and mid-sleep aborts.Written for commit 4093c05. Summary will update on new commits.