Commit Graph
167 Commits
Author SHA1 Message Date
Eric Eastwood 5ce6b8a307 Better failure_to_pyerr 2026-06-24 17:53:28 -05:00
Eric Eastwood b5ea2f7154 Avoid String allocation 2026-06-24 17:40:59 -05:00
Eric Eastwood 619507482a Only return runInteraction result if it succeeded
Previous logic (LLM summary):

> The current logic always prefers captured over outcome, even when outcome is an Err. Consider: callback runs successfully → slot = Some(Ok(value)) → returns None → but then runInteraction's commit fails and the deferred errbacks. Now captured = Some(Ok(value)) and outcome = Err(...), and we'd return Ok(value) — silently swallowing the commit failure.
>
> Whether that's reachable depends on Synapse's retry behavior (it may retry the whole interaction on commit failure, re-running the callback). It's likely a narrow edge case, but the comment ("we only trust this slot once the deferred has fired") implies the slot is authoritative once fired, which isn't quite true if the deferred fires with an error after a successful callback run.
2026-06-24 17:28:57 -05:00
Eric Eastwood 0090330585 Iterate on python_db_pool comments 2026-06-24 16:40:28 -05:00
Eric Eastwood a2e68adb1c Explain more about python_db_pool 2026-06-24 16:17:00 -05:00
Eric Eastwood 79a8cc1f71 Rename Row -> DbRow 2026-06-24 16:12:43 -05:00
Eric Eastwood 8ddab4f23e Iterate on Database trait comments 2026-06-24 16:09:29 -05:00
Eric Eastwood 7ed525ddd1 Rename SynapseConfig -> SynapseHomeServerConfig 2026-06-24 16:02:19 -05:00
Eric Eastwood 59228e5f58 Fill in the rest of the config 2026-06-24 15:37:42 -05:00
Eric Eastwood 2a609a5cdf Fill in missing experimental config 2026-06-24 15:32:38 -05:00
Eric Eastwood 590fd2b95b Fill in the rest of rust/src/handlers/versions.rs 2026-06-24 15:27:53 -05:00
Eric Eastwood 87ca67d4b6 Update comments 2026-06-24 15:03:51 -05:00
Eric Eastwood a4e4af7fa8 "Dyn-compatibility" is the new name for "object safety"
> This concept was formerly known as object safety.
>
> *-- https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility*
2026-06-24 14:55:47 -05:00
Eric Eastwood adeb03960c Sync trait not needed on run_interaction
LLM summary:

func only ever needs to be moved to a thread and called there sequentially, never shared by & across threads:

- In the erasure, func is captured by-move into the Box<dyn Fn ... + Send> callback (only Send is required to box it that way).
- The Python pool moves that callback into the runInteraction DB-thread closure and calls it there; the Rust pool calls it within a single async task. Neither sends &func to multiple threads concurrently.
2026-06-24 14:51:16 -05:00
Eric Eastwood 683f264a7f LLM simplify dyn DatabasePool
Prompt:
```
Compare this with a previous approach that was swapped out in `d9a111bdfaf51cd4cadfdc071f9956eec47aea43` (look at the removals). Anything we should change/simplify or something you like better/worse about that one? Give the new approach a review and simplify and make things more clear as necessary
```

Changes made (LLM summary):

1. #[async_trait] on the object-safe method. The core trait method is now async fn run_interaction_erased(...) -> ErasedResult instead of a hand-rolled fn ... -> BoxFuture<'a, _>. This is the convention already used by Transaction in the same file, and it removed the async move { ... }.boxed() wrapper (plus the BoxFuture/FutureExt imports) from both pool impls — their bodies are now plain async fns again.
2. Dropped the constrain / erase_interaction helper. I'd over-engineered the closure erasure out of a worry that higher-ranked-lifetime inference would fail. The previous code proved a direct let erased: ErasedInteraction = Box::new(move |txn| {...}) compiles — the type annotation on the binding is enough. ~30 lines gone.
3. Dropped the unneeded + Sync on the erased callback type. ErasedInteraction is + Send only now; the boxed callback is moved to a single DB thread and called there, never shared by reference.
2026-06-24 14:45:55 -05:00
Eric Eastwood 2860e4ea01 LLM attempt at switching back to Store with dyn DatabasePool 2026-06-24 14:34:47 -05:00
Eric Eastwood c21dbbdc1f Rename Value -> DbValue 2026-06-23 21:20:45 -05:00
Eric Eastwood f42ba674b6 Avoid circular import issues
```
[ERROR]
Traceback (most recent call last):
  File "/home/eric/.cache/pypoetry/virtualenvs/matrix-synapse-xCtC9ulO-py3.14/lib/python3.14/site-packages/twisted/trial/runner.py", line 711, in loadByName
    return self.suiteFactory([self.findByName(name, recurse=recurse)])
  File "/home/eric/.cache/pypoetry/virtualenvs/matrix-synapse-xCtC9ulO-py3.14/lib/python3.14/site-packages/twisted/trial/runner.py", line 474, in findByName
    obj = reflect.namedModule(searchName)
  File "/home/eric/.cache/pypoetry/virtualenvs/matrix-synapse-xCtC9ulO-py3.14/lib/python3.14/site-packages/twisted/python/reflect.py", line 156, in namedModule
    topLevel = __import__(name)
  File "/home/eric/Documents/github/element/synapse/tests/__init__.py", line 24, in <module>
    from synapse.util.patch_inline_callbacks import do_patch
  File "/home/eric/Documents/github/element/synapse/synapse/__init__.py", line 31, in <module>
    from synapse.util.rust import check_rust_lib_up_to_date
  File "/home/eric/Documents/github/element/synapse/synapse/util/__init__.py", line 41, in <module>
    from synapse.types import JsonDict
  File "/home/eric/Documents/github/element/synapse/synapse/types/__init__.py", line 63, in <module>
    from synapse.api.errors import Codes, SynapseError
  File "/home/eric/Documents/github/element/synapse/synapse/api/errors.py", line 33, in <module>
    from synapse.util.json import json_decoder
  File "/home/eric/Documents/github/element/synapse/synapse/util/json.py", line 23, in <module>
    from synapse.synapse_rust.events import JsonObject
  File "/home/eric/Documents/github/element/synapse/synapse/logging/context.py", line 55, in <module>
    from synapse.util.stringutils import random_string_insecure_fast
  File "/home/eric/Documents/github/element/synapse/synapse/util/stringutils.py", line 31, in <module>
    from synapse.api.errors import Codes, SynapseError
builtins.ImportError: cannot import name 'Codes' from partially initialized module 'synapse.api.errors' (most likely due to a circular import) (/home/eric/Documents/github/element/synapse/synapse/api/errors.py)
```
2026-06-23 20:38:04 -05:00
Eric Eastwood 37ff66099a Align imports on OnceCell which has get_or_try_init 2026-06-23 20:29:45 -05:00
Eric Eastwood 746657498a Less wordy 2026-06-23 20:10:38 -05:00
Eric Eastwood 441e580b53 Fix logcontext 2026-06-23 20:04:07 -05:00
Eric Eastwood 065c5cb4c8 Non-working: Try to save/restore logcontext 2026-06-23 19:32:29 -05:00
Eric Eastwood d40adfad21 Explain why poll_once 2026-06-22 17:34:55 -05:00
Eric Eastwood 505b599332 Panic for programming error 2026-06-22 17:33:39 -05:00
Eric Eastwood 874178afac poll_once instead of futures::executor::block_on
See https://github.com/element-hq/synapse/pull/19846#discussion_r3394989664
2026-06-22 17:29:28 -05:00
Eric Eastwood dc93a239af Fix grammar, add intended fix 2026-06-22 16:51:22 -05:00
Eric Eastwood 4eec02ce00 Explain possible better future for async fn that need to be Send 2026-06-22 16:47:31 -05:00
Eric Eastwood 5f23dc6c74 Fix lint 2026-06-22 14:11:56 -05:00
Eric Eastwood d9a02d3c47 Merge branch 'develop' into madlittlemods/rust-db-access-using-python-db-pool-run-interaction-llm1
Conflicts:
	rust/src/deferred.rs
	rust/src/lib.rs
	rust/src/tokio_runtime.rs
2026-06-22 14:05:02 -05:00
Eric EastwoodandGitHub 42138ad602 Split out deferred and tokio_runtime to their own Rust modules (#19868)
Spawning from https://github.com/element-hq/synapse/pull/19824 /
https://github.com/element-hq/synapse/pull/19846 and wanting to use
`create_deferred` in more than just the `http_client.rs`
2026-06-19 22:21:48 -05:00
Eric Eastwood 7aec5a0786 Stub remaining features 2026-06-19 00:51:54 -05:00
Eric Eastwood 7c2790a48c Serde UnstableFeatureMap 2026-06-19 00:48:18 -05:00
Eric Eastwood 941188c05d Remove unused msc4222 2026-06-19 00:13:20 -05:00
Eric Eastwood 9688d48f33 Fix RoomCreationPreset 2026-06-19 00:13:03 -05:00
Eric Eastwood 5b1a1aef15 WIP: RoomCreationPreset 2026-06-19 00:07:13 -05:00
Eric Eastwood 29e5830610 Fix Rust warnings 2026-06-18 21:05:45 -05:00
Eric Eastwood f76c8c160b Refactor to remove SynapseConfig from shared code 2026-06-18 21:03:48 -05:00
Eric Eastwood ca1371e1a3 Refactor deferred and tokio_runtime to their own crates 2026-06-18 19:55:00 -05:00
Eric Eastwood 0226a67858 Add comments why row expectations 2026-06-17 18:45:47 -05:00
Eric Eastwood 65ba851f2c Concrete Row type 2026-06-17 18:25:07 -05:00
Eric Eastwood d3af0c4e18 LLM further Row 2026-06-17 17:48:35 -05:00
Eric Eastwood 6b5e9f2577 Partial Row 2026-06-17 17:29:43 -05:00
Eric Eastwood d9a111bdfa LLM attempt at simplifying 2026-06-10 15:44:15 -05:00
Eric Eastwood 8f0768d491 LLM attempt 1 2026-06-09 20:22:29 -05:00
Eric Eastwood bb4c55546b Adjust comment 2026-06-09 19:13:42 -05:00
Eric Eastwood c63b40e756 A little bit of iterating 2026-06-09 19:09:12 -05:00
Eric Eastwood 3696e7cecc Splat based on #19824 2026-06-09 18:19:57 -05:00
Erik JohnstonandGitHub ac21bf08f3 Port Requester class to Rust. (#19828)
This is in prep for converting the event serialization to Rust.

This is a fairly mechanical port, except that we store the appservice ID
rather than the appservice object. This avoids us having to store a
`Py<..>` (or port the appservice object over).
2026-06-09 10:26:04 +01:00
b8cacf7537 Fix Event.__repr__ (#19817)
Follow on from #19701 

This (more or less) matches what we had before. Otherwise we just get a
default `<builtins.Event at 0x...>`

---------

Co-authored-by: Eric Eastwood <erice@element.io>
2026-06-03 15:19:27 +01:00
Erik JohnstonandGitHub e8e5a42180 Fix parsing events that have large integers (#19819)
Follow on from https://github.com/element-hq/synapse/pull/19701.

Unfortunately serde has a bug when using `#[serde(flatten)]` with
`arbitrary-precision` feature when handling integers that fit in a i128
when doing `serde_json::from_value`. See
https://github.com/serde-rs/serde/issues/2230.

The `depythonize` hits the same issue. To fix this we make it so we only
parse events from strings and not values.
2026-06-03 14:52:05 +01:00