Commit ff13eeb
authored
feat/river schema v2 compatibility (#106)
Why
===
River Schema v2 compatibility so we can start getting rid of the
compatibility layer.
What changed
============
Client
---
Significantly restructured the `river.v2.*`.
- Nearly all `asyncio.Lock`'s have been removed
- Background tasks are now cleaned up correctly, which should reduce the
amount of noise around tasks being GC'd while they're still running
- Move websocket state ownership from Client transport down into Client
Session. This significantly simplifies transparent reconnects, since we
don't need to coordinate state shifting.
- There are four background tasks:
- Heartbeat checker. This keeps track of whether we've gotten any
heartbeats from the server recently.
- "Close session" checker. This keeps track of whether we've exceeded
the grace period for transparent reconnects.
- Buffered message sender. One downside with the previous implementation
was that we had [a
race](https://us5.datadoghq.com/logs?query=%40river.tags%3Ainvariant-violation%20-%40river.extras.badASN%3Atrue%20service%3Apid2%20status%3Awarn%20%22received%20out%20of%20order%20msg%20closing%20connection%20got%20seq%22%20%22wanted%20seq%22&agg_m=count&agg_m_source=base&agg_t=count&cols=host%2Cservice&fromUser=true&messageDisplay=inline&refresh_mode=sliding&storage=hot&stream_sort=desc&viz=stream&from_ts=1742751250088&to_ts=1743010450088&live=true)
on sending messages over the websocket, since we had no coordination
between calls to `send_message` when called concurrently, so we'd end up
with `seq` bound and incremented but then messages would become
out-of-order by the time the `ws.send` method returned. Now we just
atomically append to a
[`deque`](https://docs.python.org/3/library/collections.html#collections.deque)
as we push onto the send buffer, and when we get a confirmation from the
ws library we move the message over to an ack buffer (also a `deque`)
waiting for incoming messages from the server to allow us to drain.
Codegen
---
- `init` is now required for all method types, `input` is now optional.
This simplifies `rpc` and `stream` codegen.
- Fixed some bugs where `init` was being used in `input` position and
vice versa.
- Swapping `f"'{foo}'"` encoding for `f"{repr(foo)}"`, giving greater
safety post-generation (to avoid situations where `f"'{None}'"` gets
rendered as `"None"`. `f"{repr(None)}"` would render as `None` which
would fail typechecks.)
Test plan
=========
Manually ran codegen against v2 generated schemas, everything
typechecks.1 parent b72caf8 commit ff13eeb
File tree
99 files changed
+5468
-698
lines changed- scripts
- parity
- src/replit_river
- codegen
- v2
- tests
- fixtures
- v1
- codegen
- rpc
- generated
- test_service
- snapshot
- parity
- snapshots
- parity
- pydantic_inputs
- agentToolLanguageServer
- aiExec
- conmanFilesystem
- replspaceApi
- shellExec
- typeddict_inputs
- agentToolLanguageServer
- aiExec
- conmanFilesystem
- replspaceApi
- shellExec
- test_basic_stream
- test_service
- test_pathological_types
- test_service
- test_unknown_enum
- enumService
- stream
- types
- river_fixtures
- v2
- codegen/snapshot/snapshots
- test_basic_rpc
- test_service
- test_basic_stream
- test_service
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
99 files changed
+5468
-698
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| |||
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | 4 | | |
| |||
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| 24 | + | |
23 | 25 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
226 | 226 | | |
227 | 227 | | |
228 | 228 | | |
| 229 | + | |
229 | 230 | | |
230 | 231 | | |
231 | 232 | | |
| 233 | + | |
232 | 234 | | |
233 | 235 | | |
234 | 236 | | |
| |||
239 | 241 | | |
240 | 242 | | |
241 | 243 | | |
242 | | - | |
243 | 244 | | |
244 | 245 | | |
245 | 246 | | |
| |||
0 commit comments