Repository navigation
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 30, 2026, 9:48 PM ET / October 1, 2026, 01:48 UTC (Revision 6). ClawSweeper reviewWhat this changesThe Discord voice worker measures connection readiness and retry time with a monotonic clock, with tests for clock skew and an exhausted timeout. Merge readiness✅ Ready for maintainer review Current main still gives Discord voice connections a wall-clock-based timeout budget. This PR addresses that distinct defect, and the submitted transport trace and maintainer verification support the fix. Priority: P2 Review scores
Verification
How this fits togetherA Discord voice join passes its configured timeout to an audio worker. The worker waits for the Discord voice SDK to become ready, then reports success or failure to the voice session. flowchart LR
A[Voice join request] --> B[Configured timeout]
B --> C[Discord audio worker]
C --> D[Remaining readiness budget]
D --> E[Discord voice SDK]
E --> F[Join result]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +1, Tests +45. Total +46 across 3 files. View PR surface stats
Review metricsNone. Technical reviewBest possible solution: Keep the timeout calculation in the Discord audio worker and preserve the configured allowance across both readiness attempts. Do we have a high-confidence way to reproduce the issue? Yes, with high confidence from current source and the recorded before/after clock-skew traces. This read-only review did not execute the PR. Is this the best way to solve the issue? Yes. The worker already owns the connection deadline; using one monotonic clock for its creation and consumption is a narrow repair. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 80680fb3428a. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (5 earlier review cycles)
|
DiscordAudioWorker.connect() seeded its readiness deadline with Date.now() (wall clock) but consumed the remaining budget through AbortSignal.timeout, which is a monotonic libuv timer. A wall-clock rollback enlarged the remaining budget past connectTimeoutMs (stalling the readiness wait), and a forward jump shrank it toward the Math.max(1, ...) floor, misjudging healthy connections as timed out. Seed and read the deadline with performance.now() instead, flooring the budget so AbortSignal.timeout keeps its integer contract. Ref: BUG-092-discord-voice-connect-deadline-wall-clock (local finding)
9d48e13 to
365964d
Compare
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review. |
|
🦞👀 Re-review progress:
|
|
I verified the voice deadline and shortened its comments in 8cadf90d.
|
|
Merged via squash.
|
…penclaw#156979) Keep Discord voice connection waits within the configured elapsed-time budget across wall-clock changes. - Use one monotonic deadline across readiness attempts and floor the native timeout input. - Existing Linux Crabbox proof: 47 tests passed; the real SDK keeps a 500 ms allowance across steady, rewound, and advanced wall clocks. - Current-head CI and ClawSweeper pass with no findings. - Authenticated Discord joining and audio playback remain untested. Co-authored-by: Altay <[email protected]>
What Problem This Solves
Joining a Discord voice channel can stall or fail spuriously when the system clock moves: the readiness deadline was seeded with
Date.now()(wall clock) but consumed throughAbortSignal.timeout(a monotonic libuv timer), so a clock rollback enlarged the remaining budget pastconnectTimeoutMsand a forward jump shrank it toward theMath.max(1, ...)floor, misjudging healthy connections as timed out.DiscordAudioWorker.connect()computeddeadline = Date.now() + connectTimeoutMs, then passedMath.max(1, deadline - Date.now())toAbortSignal.timeout. Wall-clock skew twisted the budget both ways — connections hung or were rejected twice and surfaced as "cannot join voice channel".performance.now()(monotonic), flooring the budget soAbortSignal.timeoutkeeps its integer contract.audio-worker.tsthree sites inconnect()— deadline seed (L79),AbortSignal.timeoutbudget (L115), retry guard (L145).reconnectGraceMs/PLAYBACK_READY_TIMEOUT_MS(L331/L565) already pass integer constants;receivedAt: Date.now()(L487) is an epoch telemetry timestamp and correctly stays wall-clock.Why This Change Was Made
Matches the canonical pattern already shipped for the same wall-clock-vs-monotonic class: #155603 (codex remote transfer, merged), #155648 (meeting browser), #155323 (provider discovery).
Math.flooris required becauseperformance.now()is sub-millisecond andAbortSignal.timeoutrejects non-integer delays withERR_OUT_OF_RANGE(verified below). The fix lands in the single owner of the readiness deadline with no new parser, policy branch, or config surface.User Impact
Joining a Discord voice channel now respects the configured
connectTimeoutMsregardless of system clock adjustments (NTP, DST, manual changes, container drift). Connections no longer hang past the timeout, and healthy connections are no longer rejected as timed out during a forward clock jump.Evidence
Math.flooris mandatory —AbortSignal.timeoutrejects the sub-millisecond floatperformance.now()produces:Without
Math.floorthe fix throws insideconnect()and destroys the attempt beforeentersStateruns.Pre-fix RED (source reverted, regression test kept) — the 10s wall-clock rollback enlarges the budget to
30000 + 10000 = 40000ms:Post-fix GREEN — the budget stays monotonic under the same skew. The regression test asserts
AbortSignal.timeoutreceives[29900, 30000](monotonic, minus elapsed ms) not[30000, 40000](wall-clock + rollback):CI regression caught and fixed — the existing
voice-session.lifecycle.test.tscase "does not retry an aborted voice connection readiness wait after the timeout budget is spent" mockedDate.now()to simulate budget exhaustion. Switching production code toperformance.now()made that mock a no-op, so the join spuriously succeeded (expected true to be false). The test mock now spiesperformance.now()with the same return sequence:Full
voice-session.lifecycle.test.ts(43) +audio-worker-deadline-clock.test.ts+voice-session.timeouts.test.ts= 47/47 green. New test file: 36ms wall, ~15s file-level Duration (vitest overhead), amortized in the existingchanged-extensions-configshard.Production-path transport trace —
node --import tsxdirectly instantiates the productionDiscordAudioWorker(real@discordjs/voiceSDK, fake credentials, no live gateway).connect()runs the realjoinVoiceChannel→entersStatepath; the connection never reaches Ready and is bounded by theAbortSignal.timeoutbudget. ADate.nowmonkey-patch rolls the wall clock back 10s to verify the budget is not inflated:The real
@discordjs/voicetransport sendsVoiceStateUpdate(op 4) viagateway-send, confirming the production connect path ran. Under a 10s wall-clock rollback the budget stays at 2999ms (not 12999ms) — the monotonic clock bounds the readiness wait regardless of wall-clock skew.Not tested: a live Discord voice gateway join (requires bot credentials and a real voice channel). The production transport trace above exercises the real SDK connect path and shows the bounded timeout under clock skew; no stored-data contract changes.
AI Assistance
AI-assisted: Yes. Per review, fixed a CI regression where an existing lifecycle test mocked
Date.now()to simulate budget exhaustion; the mock now spiesperformance.now()to match the monotonic clock domain, reported the new test file's wall time and CI cost, and added a production-path transport trace showing the bounded timeout under wall-clock skew.