Skip to content

fix(relay): never panic on multibyte request ids when naming worker threads - #27

Merged
duyetbot merged 1 commit into
mainfrom
cursor/002-relay-id-char-boundary-95b9
Aug 28, 2026
Merged

fix(relay): never panic on multibyte request ids when naming worker threads#27
duyetbot merged 1 commit into
mainfrom
cursor/002-relay-id-char-boundary-95b9

Conversation

@duyet

@duyet duyet commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Summary

The relay named worker threads by byte-slicing the first 8 bytes of a cloud-controlled request id. A multibyte UTF-8 character in those bytes panics (byte index N is not a char boundary). Release is panic = "abort", so one bad frame killed the whole relay.

This truncates the id by Unicode scalar values (chars().take(8)) for the thread name only. The in-flight map still keys on the full id.

Closes #17 (Plan 002).

Checklist

  • Version stays on 0.1.x (do not introduce 0.2 / 1.0)
  • Do not auto-merge release-please PRs

Skip co-authors

  • I skipped co-author trailers on purpose

Plan verification

  • Drift check: git diff --stat 61ee3c7..HEAD -- src/relay.rs was empty before the change; live spawn_request matched the issue excerpt.
  • Only src/relay.rs changed.
  • grep -n 'frame.id\[' src/relay.rs → no matches.
  • grep -n 'chars().take' src/relay.rs → helper at the short_id definition.
  • cargo build --locked → exit 0 (local sandbox rustc 1.98.0, matching CI @stable).
  • cargo test --locked --lib relay → 15 passed, including short_id_is_char_boundary_safe_and_bounded.
  • cargo clippy --locked --all-targets → 13 pre-existing lib warnings; none new in relay.rs.

Out of scope (reported, not fixed)

No other untrusted-string (&str[..n]) slices remain in relay.rs. The other .. slices are on raw byte buffers (buf / pending) after utf8_flush_len, plus unit-test fixtures.

Open in Web Open in Cursor 

…hreads

Thread names sliced the first 8 bytes of the cloud-controlled request
id. A multibyte UTF-8 character in those bytes panics on a char
boundary; release is panic = "abort", so one bad frame killed the
relay. Truncate by characters instead.

Closes #17

Co-authored-by: duyet <duyet@users.noreply.github.com>
@duyet
duyet marked this pull request as ready for review August 28, 2026 04:28
@duyetbot
duyetbot merged commit 77adf3a into main Aug 28, 2026
7 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

anyr size and startup

Startup is wall time for a cold anyr --version / anyr --help (median of 21 runs). Size is the stripped release binary, or the .wasm for the browser demo.

Size budget: anyr-linux-x86_64 must stay ≤ 4.0 MiB (4194304 bytes) stripped.

Asset Kind Size --version median --help median
anyr-darwin-arm64 native 2.7 MiB 2.88 ms 2.51 ms
anyr-darwin-x86_64 native 2.9 MiB 35.89 ms 33.77 ms
anyr-linux-arm64 native 2.6 MiB 0.7 ms 0.76 ms
anyr-linux-x86_64 native 3.0 MiB 0.95 ms 0.94 ms
anyr-windows-x86_64.exe native 2.5 MiB 8.72 ms 8.79 ms
anyr.wasm wasm 175.1 KiB

Budget check: ok

raw timings
[
  {
    "asset": "anyr-darwin-arm64",
    "kind": "native",
    "path": "/Users/runner/work/cli/cli/anyr-darwin-arm64",
    "bytes": 2803480,
    "size": "2.7 MiB",
    "version": "0.1.11 (built 2026-08-28 04:29:16)",
    "target": "aarch64-apple-darwin",
    "os": "macos-latest",
    "startup_version": {
      "n": 21,
      "min_ms": 2.62,
      "median_ms": 2.88,
      "p95_ms": 7.0,
      "mean_ms": 3.93
    },
    "startup_help": {
      "n": 21,
      "min_ms": 2.29,
      "median_ms": 2.51,
      "p95_ms": 3.89,
      "mean_ms": 3.02
    }
  },
  {
    "asset": "anyr-darwin-x86_64",
    "kind": "native",
    "path": "/Users/runner/work/cli/cli/anyr-darwin-x86_64",
    "bytes": 3010560,
    "size": "2.9 MiB",
    "version": "0.1.11 (built 2026-08-28 04:29:32)",
    "target": "x86_64-apple-darwin",
    "os": "macos-latest",
    "startup_version": {
      "n": 21,
      "min_ms": 28.3,
      "median_ms": 35.89,
      "p95_ms": 49.81,
      "mean_ms": 36.59
    },
    "startup_help": {
      "n": 21,
      "min_ms": 27.06,
      "median_ms": 33.77,
      "p95_ms": 46.18,
      "mean_ms": 34.47
    }
  },
  {
    "asset": "anyr-linux-arm64",
    "kind": "native",
    "path": "/home/runner/work/cli/cli/anyr-linux-arm64",
    "bytes": 2757672,
    "size": "2.6 MiB",
    "version": "0.1.11 (built 2026-08-28 04:29:16)",
    "target": "aarch64-unknown-linux-gnu",
    "os": "ubuntu-24.04-arm",
    "startup_version": {
      "n": 21,
      "min_ms": 0.66,
      "median_ms": 0.7,
      "p95_ms": 0.84,
      "mean_ms": 0.72
    },
    "startup_help": {
      "n": 21,
      "min_ms": 0.7,
      "median_ms": 0.76,
      "p95_ms": 0.83,
      "mean_ms": 0.76
    }
  },
  {
    "asset": "anyr-linux-x86_64",
    "kind": "native",
    "path": "/home/runner/work/cli/cli/anyr-linux-x86_64",
    "bytes": 3110504,
    "size": "3.0 MiB",
    "version": "0.1.11 (built 2026-08-28 04:29:20)",
    "target": "x86_64-unknown-linux-gnu",
    "os": "ubuntu-latest",
    "startup_version": {
      "n": 21,
      "min_ms": 0.94,
      "median_ms": 0.95,
      "p95_ms": 1.0,
      "mean_ms": 0.96
    },
    "startup_help": {
      "n": 21,
      "min_ms": 0.91,
      "median_ms": 0.94,
      "p95_ms": 1.04,
      "mean_ms": 0.95
    }
  },
  {
    "asset": "anyr-windows-x86_64.exe",
    "kind": "native",
    "path": "D:\\a\\cli\\cli\\anyr-windows-x86_64.exe",
    "bytes": 2576384,
    "size": "2.5 MiB",
    "version": "0.1.11 (built 2026-08-28T04:30:28Z)",
    "target": "x86_64-pc-windows-msvc",
    "os": "windows-latest",
    "startup_version": {
      "n": 21,
      "min_ms": 8.54,
      "median_ms": 8.72,
      "p95_ms": 9.25,
      "mean_ms": 8.77
    },
    "startup_help": {
      "n": 21,
      "min_ms": 8.62,
      "median_ms": 8.79,
      "p95_ms": 10.94,
      "mean_ms": 9.18
    }
  },
  {
    "asset": "anyr.wasm",
    "kind": "wasm",
    "path": "/home/runner/work/cli/cli/target/wasm-pkg/anyr_cli_bg.wasm",
    "bytes": 179312,
    "size": "175.1 KiB",
    "version": "wasm",
    "target": "wasm32-unknown-unknown",
    "os": ""
  }
]

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.

Plan 002: Stop the relay from panicking on non-ASCII request IDs

3 participants