Skip to content

Add error codes + details to SeqError - #28

Merged
chrisboulton merged 2 commits into
mainfrom
rate-limit-errors
Jul 24, 2026
Merged

Add error codes + details to SeqError#28
chrisboulton merged 2 commits into
mainfrom
rate-limit-errors

Conversation

@chrisboulton

@chrisboulton chrisboulton commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Right now SeqError just returns an error message - we should have something more strictly structured/reliable. We also want to be able to pass additional detail about an error - such as for a rate limiting error, how many RPM/TPM have been consumed and what's remaining. Here, we code and details, which are generic but for now are specifically designed to handle the rate limiting case.

Backwards compatibility is retained - both fields are optional and omitted when absent.

Example error payload:

{
  "event": "error",
  "cid": "gen_01JABC123",
  "seq_id": "seq_01JXYZ789",
  "message": "Rate limit exceeded",
  "code": "rate_limit_exceeded",
  "details": {
    "rpm_limit": 60,
    "rpm_remaining": 0,
    "tpm_limit": 100000,
    "tpm_remaining": 42000,
    "retry_after_ms": 1000
  }
}

Summary by CodeRabbit

  • New Features

    • Remote errors now preserve optional error codes and structured details, making failures easier to understand and handle.
    • Connection, command, streaming, and embedding errors consistently expose the available remote error information.
  • Bug Fixes

    • Improved error propagation so details are not lost during connection or command failures.
    • Existing error messages without codes or details remain fully compatible.
  • Release

    • Updated the package version to 0.5.1.

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The protocol now supports optional structured remote error codes and details. Model socket opening, command handling, sequence failures, and pending request propagation preserve those fields, with tests covering backward compatibility and structured error delivery. The crate version advances to 0.5.1.

Changes

Remote error propagation

Layer / File(s) Summary
Error event contract and release metadata
Cargo.toml, src/protocol.rs
MSEvent::Error supports optional JSON error fields with backward-compatible serialization and deserialization, and the package version changes to 0.5.1.
Structured open error routing
src/client/mod.rs
Opening failures now produce ModelSocketError::Remote values containing the remote message, code, and details.
Structured sequence request failures
src/client/seq.rs
Command-level and sequence-level failures propagate structured remote errors to pending commands, generation streams, and embedding requests, with updated tests.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Remote
  participant MSEvent
  participant ModelSocket
  participant Seq
  participant PendingRequests
  Remote->>MSEvent: Emit error with message, code, and details
  MSEvent->>ModelSocket: Route opening-seq error
  ModelSocket->>PendingRequests: Fail open request with ModelSocketError::Remote
  MSEvent->>Seq: Route command or sequence error
  Seq->>PendingRequests: Fail pending commands, streams, and embeddings with remote details
Loading

Suggested reviewers: zackangelo

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: adding structured error codes and details to SeqError-related error handling.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch rate-limit-errors

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@Cargo.toml`:
- Line 3: Update the package version declaration in Cargo.toml from 0.5.1 to
0.6.0 to reflect the breaking public ModelSocketError contract changes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7ca354e2-14fb-42b8-bded-cf4c4a0ca615

📥 Commits

Reviewing files that changed from the base of the PR and between cf831ce and 51bd75d.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (4)
  • Cargo.toml
  • src/client/mod.rs
  • src/client/seq.rs
  • src/protocol.rs

Comment thread Cargo.toml
[package]
name = "modelsocket"
version = "0.5.0"
version = "0.5.1"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

sed -n '1,70p' src/client/mod.rs
sed -n '35,145p' src/protocol.rs
rg -nP --glob '*.rs' 'ModelSocketError::(Open|Command|Remote)|MSEvent::Error\s*\{' .

Repository: mixlayer/modelsocket-rs

Length of output: 6011


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

rg -n --hidden --glob '!target' --glob '!**/Cargo.lock' -i 'semver|versioning|breaking change|major release|minor release|patch release' .

Repository: mixlayer/modelsocket-rs

Length of output: 161


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

sed -n '1,90p' src/client/mod.rs
printf '\n---\n'
sed -n '240,320p' src/client/mod.rs
printf '\n---\n'
sed -n '520,580p' src/client/mod.rs
printf '\n---\n'
sed -n '700,820p' src/client/seq.rs

Repository: mixlayer/modelsocket-rs

Length of output: 9753


Bump this to 0.6.0

Cargo.toml:3 is still a patch release, but this PR changes the public error contract (ModelSocketError adds Remote, and some failures now return it instead of Open/Command). That can break downstream exhaustive matches, so this should ship as 0.6.0.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Cargo.toml` at line 3, Update the package version declaration in Cargo.toml
from 0.5.1 to 0.6.0 to reflect the breaking public ModelSocketError contract
changes.

@chrisboulton
chrisboulton merged commit 096c3aa into main Jul 24, 2026
16 checks passed
@chrisboulton
chrisboulton deleted the rate-limit-errors branch July 24, 2026 16:49
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