Skip to content

refactor(harness): use @decocms/shared/std's sleep in gemini-interactions poll loop - #5338

Open
pedrofrxncx wants to merge 1 commit into
mainfrom
refactor/gemini-interactions-shared-sleep-w3
Open

refactor(harness): use @decocms/shared/std's sleep in gemini-interactions poll loop#5338
pedrofrxncx wants to merge 1 commit into
mainfrom
refactor/gemini-interactions-shared-sleep-w3

Conversation

@pedrofrxncx

@pedrofrxncx pedrofrxncx commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

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 a new Promise + setTimeout + AbortController sleep instead of using @decocms/shared/std's canonical sleep(ms, { signal }), which is already the established pattern elsewhere in this same package (see liveness-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's sleep may reject with a raw AbortSignal.reason (which can be a DOMException, NOT instanceof Error), whereas callers here (and classifyStreamError's error instanceof Error && error.name === "AbortError" check) expect a real Error. The replacement keeps the existing makeAbortError normalization by wrapping the shared sleep call 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 mocks fetch to abort mid-poll and asserts pollInteraction rejects with an Error named "AbortError" — this is the case the manual wrapper exists to guarantee, and it would have caught a naive swap-in of the shared sleep without the normalization.

Reviewer check: bun test packages/harness/src/decopilot/gemini-interactions.test.ts

Locally 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 sleep from @decocms/shared/std, keeping abort behavior identical. Added a regression test to ensure aborts still throw an Error named "AbortError".

  • Refactors
    • Use @decocms/shared/std's sleep(ms, { signal }) in pollInteraction instead of a manual Promise/timeout.
    • Catch sleep rejections and rethrow via makeAbortError to preserve the exact Error shape for pre-abort and mid-sleep aborts.

Written for commit 4093c05. Summary will update on new commits.

Review in cubic

…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
pedrofrxncx enabled auto-merge (squash) July 28, 2026 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant