Skip to content

Replace uniform mouse jitter with Gaussian-distributed delays#228

Merged
ulziibay-kernel merged 1 commit intomainfrom
ulziibay/gaussian-mouse-jitter
Apr 24, 2026
Merged

Replace uniform mouse jitter with Gaussian-distributed delays#228
ulziibay-kernel merged 1 commit intomainfrom
ulziibay/gaussian-mouse-jitter

Conversation

@ulziibay-kernel
Copy link
Copy Markdown
Contributor

@ulziibay-kernel ulziibay-kernel commented Apr 24, 2026

Summary

  • Replaces rand.Intn(5) - 2 (uniform ±2ms) mouse movement jitter with Gaussian-distributed delays
  • Affects both doMoveMouseSmooth and doDragMouseSmooth code paths
  • No change to average movement duration — only per-step variance increases

Problem

The uniform ±2ms jitter on smooth mouse movement delays produces near-constant inter-event timing (~40ms ± 2ms). Real human mouse movement has substantially more timing variance — humans accelerate, decelerate, and have natural motor noise that creates variable intervals between input events.

Measured inter-event intervals from current implementation:

[40.1, 40, 39, 40.2, 40.2, 40, 40.1, 39, 39.2, 40.1]

This is unnaturally uniform. Real human mouse input shows much wider spread.

Fix

New gaussianDelay(meanMs, minMs) function using Box-Muller transform:

  • Mean = same as before (preserves total movement duration on average)
  • Stddev = 40% of mean (e.g., 10ms mean → 4ms stddev → delays range ~3-30ms)
  • Floor = 3ms (prevents zero/negative delays)
  • Ceiling = 3x mean (prevents rare extreme outliers from stalling movement)

This produces inter-event timing that follows a bell curve instead of a flat line, matching real human motor noise characteristics.

Test plan

  • TestGaussianDelay — validates mean (within 15%), variance (>5), floor (≥3ms), ceiling (≤3x mean)
  • TestGaussianDelay_VarianceMuchHigherThanUniform — confirms >3x the old uniform variance
  • All existing tests pass

Made with Cursor


Note

Medium Risk
Changes core input timing behavior for MoveMouse/DragMouse, which could alter perceived speed/smoothness or impact consumers that assume consistent step delays. Logic is bounded/clamped and covered by new statistical unit tests, limiting risk.

Overview
Smooth mouse movement timing is now more human-like. The uniform ±2ms per-step jitter used during smooth MoveMouse and smooth DragMouse has been replaced with gaussianDelay() (Box–Muller), clamped to a floor and 3× mean, to introduce realistic inter-event variance.

Default step delay was increased from 10ms to 20ms for both API-side point calculation and mousetrajectory.GenerateMultiSegmentTrajectory, affecting how many trajectory points are generated when duration_ms is provided.

Adds unit tests validating gaussianDelay() mean/variance bounds and demonstrating higher variance vs the previous uniform jitter (including a Welford velocity-variance simulation).

Reviewed by Cursor Bugbot for commit 7e5c658. Bugbot is set up for automated code reviews on this repo. Configure here.

@firetiger-agent
Copy link
Copy Markdown

Firetiger deploy monitoring skipped

This PR didn't match the auto-monitor filter configured on your GitHub connection:

Any PR that changes the kernel API. Monitor changes to API endpoints (packages/api/cmd/api/) and Temporal workflows (packages/api/lib/temporal) in the kernel repo

Reason: PR modifies mouse jitter/delay logic in what appears to be a client or testing utility, not kernel API endpoints (packages/api/cmd/api/) or Temporal workflows (packages/api/lib/temporal) as specified in the filter.

To monitor this PR anyway, reply with @firetiger monitor this.

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 3f19e61. Configure here.

Comment thread server/cmd/api/api/computer.go
@ulziibay-kernel ulziibay-kernel force-pushed the ulziibay/gaussian-mouse-jitter branch from 3f19e61 to 513303d Compare April 24, 2026 19:40
@ulziibay-kernel ulziibay-kernel requested a review from rgarcia April 24, 2026 20:25
The per-step delay jitter for smooth mouse movements and drags used
a uniform ±2ms offset (rand.Intn(5) - 2), producing near-constant
inter-event timing. Real human mouse movement has substantially more
timing variance due to motor noise, acceleration phases, and
micro-hesitations.

Replace with a Gaussian distribution (Box-Muller, stddev = 40% of
mean delay, clamped to [3ms, 3x mean]). This preserves the average
movement duration while producing natural timing variance in each
step.

Affects both doMoveMouseSmooth and doDragMouseSmooth code paths.

Made-with: Cursor
@ulziibay-kernel ulziibay-kernel force-pushed the ulziibay/gaussian-mouse-jitter branch from 513303d to 7e5c658 Compare April 24, 2026 20:42
@ulziibay-kernel ulziibay-kernel requested a review from rgarcia April 24, 2026 20:52
@ulziibay-kernel ulziibay-kernel merged commit c058cb0 into main Apr 24, 2026
10 checks passed
@ulziibay-kernel ulziibay-kernel deleted the ulziibay/gaussian-mouse-jitter branch April 24, 2026 20:57
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.

2 participants