Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ Naming/MethodParameterName:
# Complex files need relaxed metrics
Metrics/ClassLength:
Exclude:
- "lib/restate/server.rb"
- "lib/restate/server_context.rb"
- "lib/restate/server/handler.rb"
- "lib/restate/server/context.rb"
- "lib/restate/testing.rb"
- "lib/restate/vm.rb"

Expand All @@ -47,8 +47,8 @@ Metrics/MethodLength:
- "examples/**/*"
- "lib/restate/discovery.rb"
- "lib/restate/handler.rb"
- "lib/restate/server.rb"
- "lib/restate/server_context.rb"
- "lib/restate/server/handler.rb"
- "lib/restate/server/context.rb"
- "lib/restate/service.rb"
- "lib/restate/testing.rb"
- "lib/restate/virtual_object.rb"
Expand All @@ -57,39 +57,39 @@ Metrics/MethodLength:

Metrics/AbcSize:
Exclude:
- "lib/restate/server.rb"
- "lib/restate/server_context.rb"
- "lib/restate/server/handler.rb"
- "lib/restate/server/context.rb"
- "lib/restate/vm.rb"

Metrics/CyclomaticComplexity:
Exclude:
- "lib/restate/server.rb"
- "lib/restate/server_context.rb"
- "lib/restate/server/handler.rb"
- "lib/restate/server/context.rb"
- "lib/restate/vm.rb"

Metrics/PerceivedComplexity:
Exclude:
- "lib/restate/server.rb"
- "lib/restate/server_context.rb"
- "lib/restate/server/handler.rb"
- "lib/restate/server/context.rb"
- "lib/restate/vm.rb"

Metrics/BlockLength:
Exclude:
- "lib/restate/server.rb"
- "lib/restate/server_context.rb"
- "lib/restate/server/handler.rb"
- "lib/restate/server/context.rb"

Metrics/ParameterLists:
Exclude:
- "lib/restate.rb"
- "lib/restate/context.rb"
- "lib/restate/server_context.rb"
- "lib/restate/server/context.rb"
- "lib/restate/virtual_object.rb"
- "lib/restate/vm.rb"

# The default branch handles the empty accept header case
Lint/DuplicateBranch:
Exclude:
- "lib/restate/server.rb"
- "lib/restate/server/handler.rb"

# These marker classes are intentionally empty (used as type tags)
Lint/EmptyClass:
Expand Down
18 changes: 9 additions & 9 deletions docs/INTERNALS.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ the codebase.
Falcon (HTTP/2 server, fiber-based via Async)
│ Rack 3 interface
Restate::Server ← lib/restate/server.rb
Restate::Server::Handler ← lib/restate/server/handler.rb
│ routes requests, manages streaming I/O
Restate::ServerContext ← lib/restate/server_context.rb
Restate::Server::Context ← lib/restate/server/context.rb
│ progress loop, context API for handlers
Restate::VMWrapper ← lib/restate/vm.rb
Expand Down Expand Up @@ -123,7 +123,7 @@ Thin Ruby wrapper that:
3. Maps native result types to Ruby-side types (e.g., `Internal::Suspended` → `Restate::Suspended`,
`Internal::Failure` → `Restate::Failure`).
4. Catches `Internal::VMError` from `do_progress`/`take_notification` and returns it as a value
(not raised), so `ServerContext` can handle it.
(not raised), so `Server::Context` can handle it.

**Key types defined here:**
- `Invocation` Struct: `{invocation_id, random_seed, headers, input_buffer, key}`
Expand Down Expand Up @@ -153,7 +153,7 @@ forced protocol setting.

This is the most complex part. See [Invocation Execution Flow](#invocation-execution-flow) below.

### ServerContext (`lib/restate/server_context.rb`)
### Server::Context (`lib/restate/server/context.rb`)

The context object that backs the `Restate.*` top-level API. Implements:

Expand Down Expand Up @@ -277,7 +277,7 @@ Useful for long-running handlers that need to flush work or perform cleanup befo
| `DisconnectedError` | HTTP connection lost | No (control flow) |

`SuspendedError` and `InternalError` are dangerous because bare `rescue => e` in user handlers
will catch them. `ServerContext#enter` walks the exception cause chain to detect this.
will catch them. `Server::Context#enter` walks the exception cause chain to detect this.

### Discovery (`lib/restate/discovery.rb`)

Expand Down Expand Up @@ -338,7 +338,7 @@ After the VM is ready:
1. `vm.sys_input` returns the `Invocation` (id, headers, input buffer, key).
2. A background **input reader** Async task continues reading remaining HTTP body into
`input_queue`.
3. A `ServerContext` is created with the VM, handler, invocation, output callback, and input queue.
3. A `Server::Context` is created with the VM, handler, invocation, output callback, and input queue.

### Phase 3: Handler Execution (Async task)

Expand Down Expand Up @@ -717,8 +717,8 @@ so naive checks like `break unless output` create infinite loops.
**Always use**: `break if output.nil? || output.empty?`

This applies in two places:
- `ServerContext#flush_output` (progress loop output drain)
- `Server#process_invocation` (final output drain after handler completes)
- `Server::Context#flush_output` (progress loop output drain)
- `Server::Handler#process_invocation` (final output drain after handler completes)

### 3. Async::Queue, Not Thread::Queue

Expand Down Expand Up @@ -746,7 +746,7 @@ passing them to `notify_input`, `sys_set_state`, `sys_write_output_success`, etc
### 6. Error Handling in Handlers

`SuspendedError` and `InternalError` are internal control flow exceptions. User handlers that
use bare `rescue => e` will accidentally catch these. The `ServerContext#enter` method walks the
use bare `rescue => e` will accidentally catch these. The `Server::Context#enter` method walks the
exception cause chain to detect wrapped internal exceptions.

### 7. `Internal::Failure.new` Requires 3 Arguments
Expand Down
1 change: 0 additions & 1 deletion lib/restate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
require_relative 'restate/service'
require_relative 'restate/virtual_object'
require_relative 'restate/workflow'
require_relative 'restate/server_context'
require_relative 'restate/durable_future'
require_relative 'restate/discovery'
require_relative 'restate/endpoint'
Expand Down
4 changes: 2 additions & 2 deletions lib/restate/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ def use_outbound(klass, *args, **kwargs)

# Build and return the Rack-compatible application.
def app
require_relative 'server'
Server.new(self)
require_relative 'server/handler'
Server::Handler.new(self)
end

private
Expand Down
Loading
Loading