Skip to content

fix(gemini): prevent double release of requestSlot in awaitTurn (#22) - #23

Merged
Mag1cFall merged 2 commits into
Mag1cFall:mainfrom
chinbor:fix/video-semaphore-panic
Nov 17, 2026
Merged

Mag1cFall merged 2 commits into
Mag1cFall:mainfrom
chinbor:fix/video-semaphore-panic

Conversation

@chinbor

@chinbor chinbor commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Root Cause

When yieldingRelease in internal/adapter/hedge.go triggers release() on timeout (e.g. long-running gemini-video requests), c.requestSlot.Release(1) is already called. Later, awaitTurn in internal/gemini/research.go unconditionally calls c.requestSlot.Release(1) again, causing panic: semaphore: released more than held.

Fix

  • Added SlotYieldController and WithSlotYieldController in internal/gemini/client.go so callers can coordinate whether requestSlot has already been yielded/released.
  • Wired yieldingRelease in internal/adapter/hedge.go to mark the controller when the timer releases the slot early.
  • Guarded c.requestSlot.Release(1) in internal/gemini/research.go (awaitTurn) with alreadyReleased, skipping the duplicate release when already yielded.
  • Added regression unit tests in internal/gemini/research_slot_test.go.

Verification

  • go test -v ./internal/gemini -run TestAwaitTurn (2 passed)
  • go test ./internal/adapter/... (6 passed)
  • Verified locally with gemini-video requests without triggering semaphore panic.

Fixes #22

@Mag1cFall
Mag1cFall merged commit 012545a into Mag1cFall:main Nov 17, 2026
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.

bug: gemini-video 请求触发 panic: semaphore: released more than held

2 participants