solid_objects 0.17.0 → 0.17.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +50 -0
- data/README.md +10 -1
- data/Rakefile +5 -0
- data/docs/agents.md +273 -0
- data/docs/operations.md +10 -8
- data/docs/virtual-actors.md +226 -0
- data/examples/quickstart/README.md +249 -0
- data/examples/quickstart/app/actors/ticket_sale.rb +22 -0
- data/examples/quickstart/smoke.rb +421 -0
- data/lib/solid_objects/version.rb +1 -1
- metadata +16 -9
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5e79dde8294572943d3d728fb8a6a5e4e334a15ee8645ccd46c0ab2914c538da
|
|
4
|
+
data.tar.gz: 82550704291588ebbdd3ea2ba0579f02807ecfa2835ce2c25202fcfdf9443cca
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 22f3ad5fe3c144a424cf74936780ab2196536b1d0c46ae71c47a14aef92f6815d842f43f791f398640f63651c0be5b473f715d3a008c00992a7995d78c7cfc5a
|
|
7
|
+
data.tar.gz: e678f2c1d603407b7f6d113d7a1c440f25e4481c300a2c040873883172979621823517cf341ec3128484a2ef7d683c485d69e6dcc550dffde62826aeb6a1d6cd
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,55 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.17.2 - 2026-10-08
|
|
4
|
+
|
|
5
|
+
- The README names the agent guide at the start of Installation, and the agent
|
|
6
|
+
guide says that a reminder changes state only when it runs under
|
|
7
|
+
`solid_objects start`, so a query must not compute expiry from the clock.
|
|
8
|
+
- `docs/agents.md` now tells agents to install the current release instead of
|
|
9
|
+
a remembered version, says that step 5 is required before the first call,
|
|
10
|
+
shows the two arguments of `reject`, and lists four API mistakes from
|
|
11
|
+
agent-written code with the correct form. The gem description now states
|
|
12
|
+
the Ruby 3.3 and Rails 7.1 requirement, because agents in the discovery
|
|
13
|
+
evaluation claimed Rails 8.0.
|
|
14
|
+
- Claim the Context7 library: `context7.json` now carries the library `url` and
|
|
15
|
+
the maintainer `public_key`.
|
|
16
|
+
- Add the Context7 refresh workflow. A push to `main` that changes the README,
|
|
17
|
+
`context7.json`, `docs/`, or `examples/` asks Context7 to refresh the index.
|
|
18
|
+
It uses the `CONTEXT7_API_KEY` repository secret.
|
|
19
|
+
|
|
20
|
+
## 0.17.1 - 2026-10-08
|
|
21
|
+
|
|
22
|
+
- Name the category in the gem metadata and the README: Solid Objects is a
|
|
23
|
+
SQL-backed virtual actor library for Ruby on Rails. The gem homepage now
|
|
24
|
+
links to `https://solidobjects.dev/ruby` instead of the site root, which
|
|
25
|
+
redirects to the Node page.
|
|
26
|
+
- Add `docs/virtual-actors.md`, a category guide with the definition, a small
|
|
27
|
+
example, fit and poor-fit criteria, comparisons, and an Orleans concept map.
|
|
28
|
+
- Add `docs/agents.md`, a consumer guide for coding agents with setup,
|
|
29
|
+
authorization, effect idempotency, verification, and troubleshooting steps.
|
|
30
|
+
Both guides ship in the gem.
|
|
31
|
+
- Add `context7.json` so that Context7 indexes the consumer documentation and
|
|
32
|
+
skips maintainer files.
|
|
33
|
+
- Add a Rails quickstart in `examples/quickstart/` and a `rake quickstart`
|
|
34
|
+
check that runs it against the built gem. The check builds the gem, creates
|
|
35
|
+
a new SQLite Rails application, installs the gem from `vendor/cache` with
|
|
36
|
+
`bundle install --local`, and confirms by checksum and load path that the
|
|
37
|
+
application loads the built gem. It runs the install generator, the
|
|
38
|
+
migrations, and the doctor, and grants only the message and query policies.
|
|
39
|
+
It sends eight concurrent holds from separate processes to the README's
|
|
40
|
+
`TicketSale` actor and confirms that exactly one hold commits. It stops the
|
|
41
|
+
runtime, waits until a reminder is past due, confirms that the reminder did
|
|
42
|
+
not run, restarts the runtime, and confirms that the reminder released the
|
|
43
|
+
hold once. The check also fails when a `TicketSale` sample in the README or
|
|
44
|
+
in `docs/` differs from the actor that it runs. A new `quickstart` CI job runs
|
|
45
|
+
the check, and the release job waits for it.
|
|
46
|
+
- Correct the `json` 3.x note in `docs/operations.md`. The `json` gem 3.x works
|
|
47
|
+
only with Active Support 8.1.4 or newer. Active Support 7.1, 7.2, and 8.0
|
|
48
|
+
raise `unknown keyword: quirks_mode`, and Active Support 8.1.3.1 and earlier
|
|
49
|
+
8.1 releases fail to decode. Upgrade Rails to 8.1.4 or newer, or pin `json`
|
|
50
|
+
to 2.x. The compatibility CI matrix now pins `json` 2.x for Rails 7.1, 7.2,
|
|
51
|
+
and 8.0, the configuration that the guide prescribes.
|
|
52
|
+
|
|
3
53
|
## 0.17.0 - 2026-10-03
|
|
4
54
|
|
|
5
55
|
- Publish RBS types for portable events, metric samples, actor diagnostics, and
|
data/README.md
CHANGED
|
@@ -5,6 +5,12 @@
|
|
|
5
5
|
|
|
6
6
|
**Open Source Durable Objects in your Rails app.**
|
|
7
7
|
|
|
8
|
+
Solid Objects is a SQL-backed virtual actor library for Ruby on Rails, with
|
|
9
|
+
durable state, ordered operations, and automatic activation. Each actor has a
|
|
10
|
+
stable identity, and its state lives in the SQL database that your app already
|
|
11
|
+
uses. [Virtual actors in Ruby on Rails](docs/virtual-actors.md) explains the
|
|
12
|
+
model and when to use it.
|
|
13
|
+
|
|
8
14
|
In a shopping cart, paying twice at the same time is a big problem. The payment provider might time out, and your Rails site could be restarting before recovery finishes.
|
|
9
15
|
|
|
10
16
|
To deal with this safely, you often need logic scattered between 7-10 files like database row locks, Redis locks, delayed jobs, retries, and cleanup code to keep that process straight. They are not all large, but they must agree about the same payment state and failure rules. That coordination is the difficult part.
|
|
@@ -38,7 +44,8 @@ And so much more.
|
|
|
38
44
|
|
|
39
45
|
## Installation
|
|
40
46
|
|
|
41
|
-
Solid Objects requires Ruby 3.3 or newer and Rails 7.1 or newer.
|
|
47
|
+
Solid Objects requires Ruby 3.3 or newer and Rails 7.1 or newer. Coding agents
|
|
48
|
+
should follow the [agent guide](docs/agents.md), which gives each step in order.
|
|
42
49
|
|
|
43
50
|
```bash
|
|
44
51
|
bundle add solid_objects
|
|
@@ -160,6 +167,8 @@ Exactly once is not hiding in a more advanced configuration. Read the
|
|
|
160
167
|
## Read more
|
|
161
168
|
|
|
162
169
|
- [Five-minute Rails guide](https://solidobjects.dev/5min/rails)
|
|
170
|
+
- [Virtual actors in Ruby on Rails](docs/virtual-actors.md)
|
|
171
|
+
- [Guide for coding agents](docs/agents.md)
|
|
163
172
|
- [Choosing Solid Objects](docs/fit.md)
|
|
164
173
|
- [Operations and recovery](docs/operations.md)
|
|
165
174
|
- [Observability and diagnostics](docs/observability.md)
|
data/Rakefile
CHANGED
|
@@ -37,6 +37,11 @@ task :at_least_once do
|
|
|
37
37
|
sh "bundle exec ruby examples/at_least_once/demo.rb"
|
|
38
38
|
end
|
|
39
39
|
|
|
40
|
+
desc "Install the built gem into a new Rails app and prove ordering and restart recovery"
|
|
41
|
+
task :quickstart do
|
|
42
|
+
sh "bundle exec ruby examples/quickstart/smoke.rb"
|
|
43
|
+
end
|
|
44
|
+
|
|
40
45
|
desc "Scan the Rails engine for security warnings"
|
|
41
46
|
task :security do
|
|
42
47
|
sh "bundle exec brakeman --force --no-pager -q ."
|
data/docs/agents.md
ADDED
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
# Solid Objects for coding agents (Rails)
|
|
2
|
+
|
|
3
|
+
This guide is for a coding agent that evaluates or adds Solid Objects in a
|
|
4
|
+
Ruby on Rails application. It gives the facts and steps in a fixed order. Each
|
|
5
|
+
step links to the maintained documentation for more detail.
|
|
6
|
+
|
|
7
|
+
## 1. Check the fit first
|
|
8
|
+
|
|
9
|
+
Use Solid Objects only if you can answer yes to most of these questions:
|
|
10
|
+
|
|
11
|
+
1. Does one identity, such as a cart, room, booking, account, or device, own
|
|
12
|
+
the state?
|
|
13
|
+
2. Must writes for that identity happen one at a time across requests, jobs,
|
|
14
|
+
and processes?
|
|
15
|
+
3. Must some work happen later or continue after a process restart?
|
|
16
|
+
4. Is the state a bounded JSON document, not a large relational dataset?
|
|
17
|
+
5. Can the application run one more process, `bundle exec solid_objects start`,
|
|
18
|
+
for reminders and background work?
|
|
19
|
+
|
|
20
|
+
Select a simpler tool in these cases:
|
|
21
|
+
|
|
22
|
+
| Requirement | Use instead |
|
|
23
|
+
| --- | --- |
|
|
24
|
+
| The invariant fits in one request | `with_lock`, a unique index, or a short transaction |
|
|
25
|
+
| CPU-intensive or parallel work | Background jobs or Ractors. An actor serializes work |
|
|
26
|
+
| Thousands of writes for each second to one key | A counter column, a cache, or Solid Objects Pro |
|
|
27
|
+
| One atomic change across two actor identities | One SQL transaction on normal tables |
|
|
28
|
+
| Exactly-once calls to an external API | Not available from any actor library. Use provider idempotency keys |
|
|
29
|
+
|
|
30
|
+
The full checklist is in [Choosing Solid Objects](fit.md). The category guide
|
|
31
|
+
is [Virtual actors in Ruby on Rails](virtual-actors.md).
|
|
32
|
+
|
|
33
|
+
## 2. Package identity
|
|
34
|
+
|
|
35
|
+
| Item | Value |
|
|
36
|
+
| --- | --- |
|
|
37
|
+
| Gem | `solid_objects` |
|
|
38
|
+
| Repository | <https://github.com/cardmagic/solid-objects-ruby> |
|
|
39
|
+
| Website | <https://solidobjects.dev/ruby> |
|
|
40
|
+
| Node.js package | `solid-objects` on npm, a separate port with the same model |
|
|
41
|
+
| Commercial extension | `solid_objects_pro`, a separate paid gem. The open-source gem does not need it |
|
|
42
|
+
|
|
43
|
+
Solid Objects is not part of Rails. It is not Solid Queue, Solid Cache, or
|
|
44
|
+
Solid Cable. It is not affiliated with Cloudflare.
|
|
45
|
+
|
|
46
|
+
## 3. Requirements
|
|
47
|
+
|
|
48
|
+
- Ruby 3.3 or newer.
|
|
49
|
+
- Rails 7.1 or newer. The gem is a Rails engine. It does not run without
|
|
50
|
+
Rails.
|
|
51
|
+
- SQLite 3.35 or newer, PostgreSQL 14 or newer, or MySQL 8.0 or newer with
|
|
52
|
+
InnoDB.
|
|
53
|
+
- No Redis and no separate actor service.
|
|
54
|
+
|
|
55
|
+
## 4. Install
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
bundle add solid_objects
|
|
59
|
+
bin/rails generate solid_objects:install
|
|
60
|
+
bin/rails db:migrate
|
|
61
|
+
bin/rails solid_objects:doctor
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
The generator adds an initializer and copies migrations into the application.
|
|
65
|
+
The doctor checks the configuration, the tables, and one real actor round trip.
|
|
66
|
+
|
|
67
|
+
Install the current release. `bundle add solid_objects` selects it. Do not pin
|
|
68
|
+
a version that you remember from earlier work; the API changed between
|
|
69
|
+
releases. The current version is on <https://rubygems.org/gems/solid_objects>.
|
|
70
|
+
|
|
71
|
+
The generated policies deny every call. Do step 5 before you call an actor.
|
|
72
|
+
|
|
73
|
+
The `json` gem 3.x works only with Active Support 8.1.4 or newer. On Rails
|
|
74
|
+
7.1, 7.2, 8.0, or 8.1 before 8.1.4, pin `gem "json", "~> 2"` in the
|
|
75
|
+
`Gemfile`. Without the pin, Active Support raises an `ArgumentError`, such as
|
|
76
|
+
`unknown keyword: quirks_mode`, for every JSON column.
|
|
77
|
+
|
|
78
|
+
[Installing and upgrading](operations.md#installing-and-upgrading) has the
|
|
79
|
+
details.
|
|
80
|
+
|
|
81
|
+
## 5. Authorize
|
|
82
|
+
|
|
83
|
+
Every policy in the generated initializer denies by default. A new
|
|
84
|
+
installation answers no actor call until you write a policy. Do not remove
|
|
85
|
+
this behavior.
|
|
86
|
+
|
|
87
|
+
For a local demonstration only, grant messages and queries:
|
|
88
|
+
|
|
89
|
+
```ruby
|
|
90
|
+
SolidObjects.configure do |configuration|
|
|
91
|
+
configuration.authorize_message = ->(**) { true }
|
|
92
|
+
configuration.authorize_query = ->(**) { true }
|
|
93
|
+
end
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Keep `authorize_destroy`, `authorize_subscription`,
|
|
97
|
+
`authorize_administration`, and `authorize_transmission` denied in a
|
|
98
|
+
demonstration.
|
|
99
|
+
|
|
100
|
+
A production policy must bind the actor type and ID to the authenticated user
|
|
101
|
+
or tenant. An actor ID is not a permission:
|
|
102
|
+
|
|
103
|
+
```ruby
|
|
104
|
+
SolidObjects.configure do |configuration|
|
|
105
|
+
owns_cart = lambda do |actor_type:, actor_id:, authorization_context:, **|
|
|
106
|
+
user = authorization_context
|
|
107
|
+
|
|
108
|
+
actor_type == "ShoppingCart" &&
|
|
109
|
+
user.present? &&
|
|
110
|
+
actor_id == user.id.to_s
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
configuration.authorize_message = owns_cart
|
|
114
|
+
configuration.authorize_query = owns_cart
|
|
115
|
+
end
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Pass the context on each call:
|
|
119
|
+
|
|
120
|
+
```ruby
|
|
121
|
+
ShoppingCart.ref(Current.user.id.to_s).add_item(
|
|
122
|
+
product_id: "shirt-123",
|
|
123
|
+
authorization_context: Current.user
|
|
124
|
+
)
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
[Authorization policies](authorization.md) lists each policy and its risk.
|
|
128
|
+
|
|
129
|
+
## 6. Define an actor
|
|
130
|
+
|
|
131
|
+
Put actors in `app/actors/`. This actor is the example from the README:
|
|
132
|
+
|
|
133
|
+
```ruby
|
|
134
|
+
class TicketSale < SolidObjects::Actor
|
|
135
|
+
attribute :available, default: 1
|
|
136
|
+
attribute :holds, default: -> { {} }
|
|
137
|
+
|
|
138
|
+
def hold(buyer:)
|
|
139
|
+
return { held: false, available: } if available.zero? || holds.key?(buyer)
|
|
140
|
+
|
|
141
|
+
self.available -= 1
|
|
142
|
+
self.holds = holds.merge(buyer => Time.current.to_i)
|
|
143
|
+
schedule(at: 10.minutes.from_now, key: buyer).expire(buyer:)
|
|
144
|
+
{ held: true, available: }
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def expire(buyer:)
|
|
148
|
+
return available unless holds.key?(buyer)
|
|
149
|
+
|
|
150
|
+
self.holds = holds.except(buyer)
|
|
151
|
+
self.available += 1
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Obey these rules in actor code:
|
|
157
|
+
|
|
158
|
+
- Keep state in `attribute` values. State must be JSON-compatible.
|
|
159
|
+
- Use `schedule(at:, key:)` for delayed work. A reminder is one named alarm
|
|
160
|
+
for each actor and key. A new `schedule` with the same key moves the alarm.
|
|
161
|
+
- Use `reject(code, message)` for a business rule failure that must not retry.
|
|
162
|
+
It takes a code and a message, for example
|
|
163
|
+
`reject(:room_full, "The room is full")`.
|
|
164
|
+
- Do not write Active Record models directly in a handler. The runtime raises
|
|
165
|
+
`SolidObjects::ApplicationWriteForbidden`. Use `commit_action` for a short
|
|
166
|
+
write in the same database.
|
|
167
|
+
- Do not call an external API in a handler. Use `emit` and an effect handler.
|
|
168
|
+
- Write each handler so that it can run again. Delivery is at least once.
|
|
169
|
+
- A reminder changes state only when it runs, and it runs only while
|
|
170
|
+
`solid_objects start` runs. Do not compute expiry from the clock in a query;
|
|
171
|
+
read the state that the reminder committed.
|
|
172
|
+
|
|
173
|
+
Avoid these mistakes:
|
|
174
|
+
|
|
175
|
+
| Mistake | Correct form |
|
|
176
|
+
| --- | --- |
|
|
177
|
+
| `schedule(at: deadline)` with no operation after it | `schedule(at: deadline, key: buyer).expire(buyer:)`. `schedule` stages a reminder only when you call an operation on its result |
|
|
178
|
+
| `reject "room full"` | `reject(:room_full, "The room is full")` |
|
|
179
|
+
| `id` inside an actor | `actor_id`. An actor has no `id` method |
|
|
180
|
+
| `register_effect(:name) { \|context, arguments\| ... }` | `register_effect(:name) { \|arguments, context\| ... }`. The arguments come first |
|
|
181
|
+
|
|
182
|
+
[Reminders](reminders.md) and the [architecture guide](architecture.md) give
|
|
183
|
+
the full actor API.
|
|
184
|
+
|
|
185
|
+
## 7. Run the runtime process
|
|
186
|
+
|
|
187
|
+
A direct call, such as `TicketSale.ref("event-42").hold(buyer: "ada")`, runs in
|
|
188
|
+
the caller. It needs no worker. These features need the runtime process:
|
|
189
|
+
|
|
190
|
+
- Reminders from `schedule`.
|
|
191
|
+
- `async` calls.
|
|
192
|
+
- Effects from `emit` and their callbacks.
|
|
193
|
+
- Broadcasts to Action Cable.
|
|
194
|
+
|
|
195
|
+
Start it beside the web process:
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
bundle exec solid_objects start
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
Add it to the `Procfile`, the process manager, or the deployment
|
|
202
|
+
configuration. When it stops, pending work stays in SQL and runs after it
|
|
203
|
+
starts again. [Operations](operations.md#runtime) covers roles and shutdown.
|
|
204
|
+
|
|
205
|
+
## 8. Make external effects idempotent
|
|
206
|
+
|
|
207
|
+
Register an effect handler at boot. Use `context.id` as the provider
|
|
208
|
+
idempotency key:
|
|
209
|
+
|
|
210
|
+
```ruby
|
|
211
|
+
SolidObjects.register_effect(:charge_payment) do |arguments, context|
|
|
212
|
+
Payments.charge(
|
|
213
|
+
idempotency_key: context.id,
|
|
214
|
+
payment_id: arguments.fetch("payment_id"),
|
|
215
|
+
amount_cents: arguments.fetch("amount_cents")
|
|
216
|
+
)
|
|
217
|
+
end
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
Stage it from the actor:
|
|
221
|
+
|
|
222
|
+
```ruby
|
|
223
|
+
emit :charge_payment, payment_id:, amount_cents:, on_success: :charged
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
The effect can run more than once after a crash. The `context.id` value is the
|
|
227
|
+
same each time. [Effect recovery](effect-recovery.md) explains how to retire
|
|
228
|
+
abandoned work.
|
|
229
|
+
|
|
230
|
+
## 9. Verify the implementation
|
|
231
|
+
|
|
232
|
+
Do these checks before you report that the work is complete:
|
|
233
|
+
|
|
234
|
+
1. Run `bin/rails solid_objects:doctor`. It must report no failures.
|
|
235
|
+
2. Write a test that includes `SolidObjects::TestHelper`. Send concurrent
|
|
236
|
+
calls to one identity from several threads. Assert the final state, for
|
|
237
|
+
example that only one hold succeeded.
|
|
238
|
+
3. Use `run_due_reminders(now:)` and `drain_solid_objects` to test delayed
|
|
239
|
+
work without sleeps.
|
|
240
|
+
4. Start `bundle exec solid_objects start`, schedule a short reminder, and stop
|
|
241
|
+
the process. Start it again after the deadline and confirm that the reminder
|
|
242
|
+
ran.
|
|
243
|
+
5. Confirm that each effect handler deduplicates with `context.id`.
|
|
244
|
+
6. Confirm that production policies do not grant access to every caller.
|
|
245
|
+
|
|
246
|
+
[Host application tests](development.md#host-application-tests) describes the
|
|
247
|
+
test helper. The [clean-install quickstart](../examples/quickstart/README.md)
|
|
248
|
+
runs checks 2 and 4 against a new Rails application.
|
|
249
|
+
|
|
250
|
+
## 10. Troubleshooting
|
|
251
|
+
|
|
252
|
+
| Symptom | Cause and fix |
|
|
253
|
+
| --- | --- |
|
|
254
|
+
| `SolidObjects::Unauthorized` | A policy denied the call. Write the policy, and pass `authorization_context:` |
|
|
255
|
+
| A reminder or `async` call does not run | The runtime process is not running. Start `bundle exec solid_objects start` |
|
|
256
|
+
| `SolidObjects::SyncInsideTransaction` | The call ran inside an open transaction. Call the actor outside the transaction. In tests, include `SolidObjects::TestHelper` |
|
|
257
|
+
| `SolidObjects::SyncTimeout` | The call did not finish in time. The message is still durable. Use its `message_reference` to wait for the result |
|
|
258
|
+
| `SolidObjects::ApplicationWriteForbidden` | A handler wrote a model directly. Use `commit_action` or `emit` |
|
|
259
|
+
| `SolidObjects::Rejected` | The actor called `reject`. This is a business result, not a retry |
|
|
260
|
+
| `ArgumentError` from `ActiveSupport::JSON`, such as `unknown keyword: quirks_mode` | `json` 3.x with Active Support before 8.1.4. Upgrade Rails to 8.1.4 or newer, or pin `gem "json", "~> 2"` |
|
|
261
|
+
|
|
262
|
+
## 11. Guarantees to state correctly
|
|
263
|
+
|
|
264
|
+
When you explain Solid Objects to a user, state these limits:
|
|
265
|
+
|
|
266
|
+
- Delivery is at least once, not exactly once.
|
|
267
|
+
- Calls for one identity are ordered. Different identities run concurrently.
|
|
268
|
+
- There are no transactions across actor identities.
|
|
269
|
+
- Fencing stops a stale activation from a commit, but its code can continue to
|
|
270
|
+
run.
|
|
271
|
+
- The gem is pre-1.0 and makes no production-ready claim.
|
|
272
|
+
|
|
273
|
+
The [correctness contract](correctness.md) is the source for each guarantee.
|
data/docs/operations.md
CHANGED
|
@@ -26,22 +26,24 @@ reports a failed or warned check rather than raising out of the command.
|
|
|
26
26
|
## Installing and upgrading
|
|
27
27
|
|
|
28
28
|
Solid Objects keeps actor state, message arguments, results, and the remembered
|
|
29
|
-
idempotency keys in JSON columns. Active Support decodes every one
|
|
30
|
-
|
|
29
|
+
idempotency keys in JSON columns. Active Support encodes and decodes every one
|
|
30
|
+
of them. The `json` gem 3.x works only with Active Support 8.1.4 or newer:
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
ArgumentError:
|
|
34
|
-
|
|
32
|
+
- Active Support 7.1, 7.2, and 8.0 raise
|
|
33
|
+
`ArgumentError: unknown keyword: quirks_mode` when they encode or decode.
|
|
34
|
+
- Active Support 8.1.3.1 and earlier 8.1 releases raise
|
|
35
|
+
`ArgumentError: wrong number of arguments (given 2, expected 1)` when they
|
|
36
|
+
decode.
|
|
35
37
|
|
|
36
38
|
The failure is in Active Support rather than in Solid Objects, and it reaches
|
|
37
|
-
every JSON column in a Rails application.
|
|
38
|
-
|
|
39
|
+
every JSON column in a Rails application. Upgrade Rails to 8.1.4 or newer. On
|
|
40
|
+
an older Rails release, pin the 2.x series of `json`:
|
|
39
41
|
|
|
40
42
|
```ruby
|
|
41
43
|
gem "json", "~> 2"
|
|
42
44
|
```
|
|
43
45
|
|
|
44
|
-
Review [CHANGELOG.md](CHANGELOG.md) for compatibility and deployment-order
|
|
46
|
+
Review [CHANGELOG.md](../CHANGELOG.md) for compatibility and deployment-order
|
|
45
47
|
notes, then update the gem:
|
|
46
48
|
|
|
47
49
|
```bash
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
# Virtual actors in Ruby on Rails
|
|
2
|
+
|
|
3
|
+
## Short answer
|
|
4
|
+
|
|
5
|
+
Yes. Solid Objects is a SQL-backed virtual actor library for Ruby on Rails.
|
|
6
|
+
The gem is `solid_objects`. It gives each actor a stable identity, durable
|
|
7
|
+
state, ordered operations, and automatic activation.
|
|
8
|
+
|
|
9
|
+
Solid Objects requires Rails. It is a Rails engine for Ruby 3.3 or newer and
|
|
10
|
+
Rails 7.1 or newer. It is not a framework-independent Ruby actor runtime.
|
|
11
|
+
State and mailboxes live in the SQLite, PostgreSQL, or MySQL database that the
|
|
12
|
+
Rails application already uses. Redis and a separate actor service are not
|
|
13
|
+
necessary.
|
|
14
|
+
|
|
15
|
+
Solid Objects is a pre-1.0 release. It makes no production-ready claim. Read
|
|
16
|
+
[Compatibility and maturity](#compatibility-and-maturity) before you choose it.
|
|
17
|
+
|
|
18
|
+
## What a virtual actor is
|
|
19
|
+
|
|
20
|
+
A virtual actor is a logical object that always exists by name. The caller
|
|
21
|
+
does not create it, start it, or stop it. The runtime loads it when a message
|
|
22
|
+
arrives and releases it when it is idle. Microsoft Orleans made this model
|
|
23
|
+
known as "virtual actors".
|
|
24
|
+
|
|
25
|
+
Solid Objects implements four properties of that model:
|
|
26
|
+
|
|
27
|
+
| Property | What it means | How Solid Objects does it |
|
|
28
|
+
| --- | --- | --- |
|
|
29
|
+
| Stable identity | An actor is addressed by type and ID, for example one cart per user. | `ShoppingCart.ref(user.id)` returns a cheap reference. The reference does not load the actor. |
|
|
30
|
+
| Automatic activation | The first message activates the actor. An idle actor is released. | A process claims a fenced activation lease when work arrives. The lease is released after the idle timeout. |
|
|
31
|
+
| Durable state | State survives process restarts and deploys. | Actor attributes are a JSON document in the application database. |
|
|
32
|
+
| Ordered turns | One identity runs one operation at a time, in a fixed order. | Each call is a durable mailbox message with a per-actor sequence number. |
|
|
33
|
+
|
|
34
|
+
Different identities run concurrently. One identity is a serialization point
|
|
35
|
+
on purpose.
|
|
36
|
+
|
|
37
|
+
## A small example
|
|
38
|
+
|
|
39
|
+
This actor holds one ticket for a buyer and releases the hold after ten
|
|
40
|
+
minutes. Put it in `app/actors/ticket_sale.rb`:
|
|
41
|
+
|
|
42
|
+
```ruby
|
|
43
|
+
class TicketSale < SolidObjects::Actor
|
|
44
|
+
attribute :available, default: 1
|
|
45
|
+
attribute :holds, default: -> { {} }
|
|
46
|
+
|
|
47
|
+
def hold(buyer:)
|
|
48
|
+
return { held: false, available: } if available.zero? || holds.key?(buyer)
|
|
49
|
+
|
|
50
|
+
self.available -= 1
|
|
51
|
+
self.holds = holds.merge(buyer => Time.current.to_i)
|
|
52
|
+
schedule(at: 10.minutes.from_now, key: buyer).expire(buyer:)
|
|
53
|
+
{ held: true, available: }
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def expire(buyer:)
|
|
57
|
+
return available unless holds.key?(buyer)
|
|
58
|
+
|
|
59
|
+
self.holds = holds.except(buyer)
|
|
60
|
+
self.available += 1
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Call it from a controller, a job, or the console:
|
|
66
|
+
|
|
67
|
+
```ruby
|
|
68
|
+
TicketSale.ref("event-42").hold(buyer: "ada")
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Two concurrent `hold` calls for `event-42` enter the same mailbox. They commit
|
|
72
|
+
one at a time, so only one buyer gets the ticket. The hold and its reminder
|
|
73
|
+
commit in one transaction. The reminder runs in the Solid Objects runtime
|
|
74
|
+
process:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
bundle exec solid_objects start
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
If that process stops, the reminder stays in SQL. It runs when the process
|
|
81
|
+
starts again.
|
|
82
|
+
|
|
83
|
+
The example needs installation, migrations, and an authorization policy. The
|
|
84
|
+
generated policies deny every operation by default. For the complete setup,
|
|
85
|
+
use one of these guides:
|
|
86
|
+
|
|
87
|
+
- [Installation](../README.md#installation) in the README.
|
|
88
|
+
- [The clean-install quickstart](../examples/quickstart/README.md), which a
|
|
89
|
+
smoke check runs against the built gem in a new Rails application.
|
|
90
|
+
- [The agent guide](agents.md), which gives setup and verification steps for
|
|
91
|
+
coding agents.
|
|
92
|
+
|
|
93
|
+
## When to use it
|
|
94
|
+
|
|
95
|
+
Solid Objects is a good candidate when most of these conditions are true:
|
|
96
|
+
|
|
97
|
+
- State belongs to one durable identity, such as a cart, room, booking,
|
|
98
|
+
device, account, or workflow.
|
|
99
|
+
- Writes for that identity must be serialized across requests, jobs, and
|
|
100
|
+
processes.
|
|
101
|
+
- The work must happen later, survive a restart, or stay ordered across more
|
|
102
|
+
than one request.
|
|
103
|
+
- The state is a bounded JSON document.
|
|
104
|
+
- The identity needs reminders, external effects, or reactive Rails views that
|
|
105
|
+
follow its committed state.
|
|
106
|
+
|
|
107
|
+
## When to use something else
|
|
108
|
+
|
|
109
|
+
Do not use an actor when a simpler tool enforces the invariant:
|
|
110
|
+
|
|
111
|
+
- One short transaction, `with_lock`, or a database constraint is enough. A row
|
|
112
|
+
lock is often the clearest answer.
|
|
113
|
+
- The work is CPU-intensive or data-parallel. An actor serializes work. It does
|
|
114
|
+
not add CPU parallelism.
|
|
115
|
+
- One hot identity must accept many writes for each second, for example a
|
|
116
|
+
request-path rate limiter or a page-view counter.
|
|
117
|
+
- The state is large, relational, or query-heavy. Keep that data in normal
|
|
118
|
+
tables.
|
|
119
|
+
- The operation must change two actor identities in one atomic transaction.
|
|
120
|
+
Solid Objects has no cross-actor transactions.
|
|
121
|
+
- You need exactly-once calls to an external API. No actor library can promise
|
|
122
|
+
that through every network failure. Solid Objects gives at-least-once
|
|
123
|
+
delivery and stable effect IDs for idempotency keys.
|
|
124
|
+
- You need replay of named workflow steps from a step log. That is a durable
|
|
125
|
+
execution engine, not an actor.
|
|
126
|
+
|
|
127
|
+
[Choosing Solid Objects](fit.md) has the full checklist and the cost model.
|
|
128
|
+
|
|
129
|
+
## How it compares
|
|
130
|
+
|
|
131
|
+
This table compares coordination models for a Rails application. It does not
|
|
132
|
+
rank the projects. Facts about other projects were checked on October 7, 2026,
|
|
133
|
+
against the sources in [Primary references](#primary-references).
|
|
134
|
+
|
|
135
|
+
| Approach | Unit of order | Durable state | Delayed work | Extra service | Good for |
|
|
136
|
+
| --- | --- | --- | --- | --- | --- |
|
|
137
|
+
| `with_lock` or a short SQL transaction | Rows in one transaction | Application tables | None | No | An invariant that fits in one request |
|
|
138
|
+
| Active Job with Solid Queue | None. `limits_concurrency` limits overlap for each key, but it does not set an order | Application tables, owned by the application | Scheduled jobs | No; Solid Queue uses the database | Background work that does not own entity state |
|
|
139
|
+
| Sidekiq | None in the open-source gem. Unique jobs and rate limits are Sidekiq Enterprise features | Application tables, owned by the application | Scheduled jobs | Redis | High-volume background jobs |
|
|
140
|
+
| In-process concurrency: Ractor, `concurrent-ruby-edge` actors, Async | One Ruby object in one process | None. State is lost when the process stops | In process only | No | Parallel or concurrent work inside one process. Ractor is experimental in Ruby 4.0 |
|
|
141
|
+
| Solid Objects | Actor type and ID | JSON state in the application database | Durable per-actor reminders | No; the `solid_objects start` process runs in the app | Durable per-identity state with ordered operations |
|
|
142
|
+
| Dapr actors | Actor type and ID, one turn at a time | A transactional Dapr state store | Durable reminders through the Dapr Scheduler service | A Dapr sidecar, plus the placement and Scheduler services. Dapr has no official Ruby SDK | Polyglot services on a Dapr platform |
|
|
143
|
+
| Temporal (`temporalio` gem) | A workflow execution | Temporal event history | Durable timers | A Temporal Service, self-hosted or Temporal Cloud | Long-running workflows that replay deterministic code |
|
|
144
|
+
|
|
145
|
+
### Orleans concept map
|
|
146
|
+
|
|
147
|
+
Orleans is the reference design for virtual actors on .NET. Solid Objects
|
|
148
|
+
uses the same programming model on a SQL database. It does not copy the
|
|
149
|
+
Orleans cluster, placement, or feature set.
|
|
150
|
+
|
|
151
|
+
| Orleans | Solid Objects | Difference |
|
|
152
|
+
| --- | --- | --- |
|
|
153
|
+
| Grain class | `SolidObjects::Actor` subclass | None in concept |
|
|
154
|
+
| Grain identity (key) | Actor type and actor ID | None in concept |
|
|
155
|
+
| Activation on first call | Activation lease on first claimed message | Solid Objects fences each activation with a database generation |
|
|
156
|
+
| Turn-based execution | Ordered mailbox, one turn at a time | Orleans can enable reentrancy. Solid Objects turns for one identity never interleave |
|
|
157
|
+
| Grain persistence | JSON attributes in the application database | An Orleans grain calls `WriteStateAsync`. Solid Objects persists state with the turn that changed it |
|
|
158
|
+
| Reminders | `schedule` | Both are durable. Orleans skips a tick that falls due while the cluster is down. A due Solid Objects reminder runs when a runtime process starts. Solid Objects has no non-durable timers |
|
|
159
|
+
| Silos and cluster membership | Any Rails process that runs `solid_objects start` | Solid Objects has no placement, directory, or cluster membership. The database is the coordination point |
|
|
160
|
+
| Streams | Observables, broadcasts, and reactive ERB | Solid Objects delivers committed revisions to Action Cable |
|
|
161
|
+
|
|
162
|
+
Solid Objects delivery is at least once. Write each handler so that it can run
|
|
163
|
+
again without harm.
|
|
164
|
+
|
|
165
|
+
## Guarantees and boundaries
|
|
166
|
+
|
|
167
|
+
- Calls are durably ordered per identity. Different identities can run
|
|
168
|
+
concurrently.
|
|
169
|
+
- Delivery is at least once, not exactly once. A handler can start again after
|
|
170
|
+
a crash or a lost lease.
|
|
171
|
+
- Ordered turns do not cancel stale Ruby code. Fencing stops a stale activation
|
|
172
|
+
from a commit, but that code can continue to run.
|
|
173
|
+
- External effects can run more than once. Use the stable effect ID, or
|
|
174
|
+
another durable key, as the idempotency key at the provider.
|
|
175
|
+
- There are no transactions across actor identities, and there is no replay of
|
|
176
|
+
durable function steps.
|
|
177
|
+
- Reminders, `async` calls, effects, and broadcasts need the
|
|
178
|
+
`bundle exec solid_objects start` process. When that process stops, the work
|
|
179
|
+
waits in SQL. The gem does not supply a hosted worker.
|
|
180
|
+
- One hot identity is sequential. The core gem is not a high-throughput
|
|
181
|
+
request-path rate limiter.
|
|
182
|
+
- The guarantees apply only to changes made through the actor APIs. Actor
|
|
183
|
+
fencing does not protect direct writes to the same data or other external
|
|
184
|
+
requests.
|
|
185
|
+
|
|
186
|
+
The [correctness contract](correctness.md) states each guarantee and the crash
|
|
187
|
+
matrix.
|
|
188
|
+
|
|
189
|
+
## Compatibility and maturity
|
|
190
|
+
|
|
191
|
+
- Ruby 3.3 or newer and Rails 7.1 or newer. CI runs Ruby 3.3, 3.4, and 4.0
|
|
192
|
+
against Rails 7.1, 7.2, 8.0, and 8.1.
|
|
193
|
+
- SQLite 3.35 or newer, PostgreSQL 14 or newer, or MySQL 8.0 or newer with
|
|
194
|
+
InnoDB. MySQL works through `mysql2` or `trilogy`.
|
|
195
|
+
- SQLite is correct for the same contract, but it is best for development and
|
|
196
|
+
modest single-host workloads.
|
|
197
|
+
- Pre-1.0. Expect changes that break compatibility. The correctness core has tests against all
|
|
198
|
+
three databases. The project has no production-ready claim and no measured
|
|
199
|
+
scale claim.
|
|
200
|
+
|
|
201
|
+
The [roadmap](roadmap.md) records what is tested, what is partial, and what is
|
|
202
|
+
next. For TypeScript and Node.js, use the
|
|
203
|
+
[solid-objects](https://github.com/cardmagic/solid-objects-js) package.
|
|
204
|
+
|
|
205
|
+
## Primary references
|
|
206
|
+
|
|
207
|
+
- Orleans: [Overview](https://learn.microsoft.com/en-us/dotnet/orleans/overview),
|
|
208
|
+
[Request scheduling](https://learn.microsoft.com/en-us/dotnet/orleans/grains/request-scheduling),
|
|
209
|
+
[Timers and reminders](https://learn.microsoft.com/en-us/dotnet/orleans/grains/timers-and-reminders),
|
|
210
|
+
[Grain persistence](https://learn.microsoft.com/en-us/dotnet/orleans/grains/grain-persistence/),
|
|
211
|
+
and [Grain placement](https://learn.microsoft.com/en-us/dotnet/orleans/grains/grain-placement).
|
|
212
|
+
- Ruby: [Ractor](https://docs.ruby-lang.org/en/4.0/Ractor.html) and the
|
|
213
|
+
[Ruby 4.0.0 release notes](https://www.ruby-lang.org/en/news/2025/12/25/ruby-4-0-0-released/).
|
|
214
|
+
- concurrent-ruby: [repository](https://github.com/ruby-concurrency/concurrent-ruby)
|
|
215
|
+
and [`Concurrent::Actor`](https://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Actor.html).
|
|
216
|
+
- Solid Queue: [concurrency controls](https://github.com/rails/solid_queue#concurrency-controls).
|
|
217
|
+
- Sidekiq: [Enterprise unique jobs](https://github.com/sidekiq/sidekiq/wiki/Ent-Unique-Jobs)
|
|
218
|
+
and [Enterprise rate limiting](https://github.com/sidekiq/sidekiq/wiki/Ent-Rate-Limiting).
|
|
219
|
+
- Dapr: [Actors overview](https://docs.dapr.io/developing-applications/building-blocks/actors/actors-overview/),
|
|
220
|
+
[Actor timers and reminders](https://docs.dapr.io/developing-applications/building-blocks/actors/actors-timers-reminders/),
|
|
221
|
+
and [SDKs](https://docs.dapr.io/developing-applications/sdks/).
|
|
222
|
+
- Temporal: [Ruby SDK](https://github.com/temporalio/sdk-ruby) and
|
|
223
|
+
[Event History](https://docs.temporal.io/encyclopedia/event-history).
|
|
224
|
+
|
|
225
|
+
Other projects change. Check these sources again before you base an
|
|
226
|
+
architecture decision on one row.
|