Commit graph

9624 commits

Author SHA1 Message Date
Oneric
8da0828b4a Merge pull request 'reload emoji asynchronously and optimise emoji updates' (#998) from Oneric/akkoma:async-emoji-reload into develop
Reviewed-on: https://akkoma.dev/AkkomaGang/akkoma/pulls/998
2025-11-06 14:55:56 +00:00
Oneric
ccde26725f Merge pull request 'api_spec/cast: iteratively retry to clean all offending parameters' (#995) from Oneric/akkoma:apispec-cast-multitolerance into develop
Reviewed-on: https://akkoma.dev/AkkomaGang/akkoma/pulls/995
2025-11-06 14:55:38 +00:00
Oneric
7e6efb2356 api_spec/cast: iteratively retry to clean all offending parameters
While the function signature allows returning many errors at once,
OpenApiSpex.cast_and_validate currently only ever returns the first
invalid field it encounters. Thus we need to retry multiple times to
clean up all offenders.

Fixes: https://akkoma.dev/AkkomaGang/akkoma/pulls/992#issuecomment-15027
2025-11-05 00:00:00 +00:00
Oneric
e7d76bb194 emoji: reload asynchronously
No caller of `reload` actually uses the result in any way
so there’s no need to wait for a response and risk running
into a timeout (by default 5 seconds).

Discovered-by: sn0w <me@sn0w.re>
Based-on: 1fb54d5c2c
2025-10-30 00:00:00 +00:00
Oneric
318ee6ee17 emoji: avoid full reloads when possible
Reloading the entire emoji set from disk, reparsing all pack JSON files,
etc is unnecessarily costly for large emoji sets. We already know which
single or few changes we want to apply, so do just that instead.
2025-10-29 00:00:00 +00:00
Oneric
f86a88ca19 emoji: store in unordered set
No caller cares about the order
(and although, rare with concurrent reads at same time like a write
the table might return unordered results anyway).
Unordered sets have a constant read time,
ordered sets logarithmic times, but there’s no benfit for us
2025-10-29 00:00:00 +00:00
Oneric
d38ca268c4 cosmetic/emoji: fix misleading docs and var names 2025-10-29 00:00:00 +00:00
Oneric
0cb2807667 emoji/pack: fix newly created pack having nil name
At the next reload the name was already set to the directory name,
but if using the created pack directly issues arose.
2025-10-29 00:00:00 +00:00
Oneric
47ac4ee817 Do not try to redirect to post display URLs for non-Create activities
Display will fail for all but Create and Announce anyway since
0c9bb0594a. We exclude Announce
activities from redirects here since they are not identical
with the announced post and akkoma-fe stripping the repeat header
on he /notice/ page might lead to confusion about which is which.

In particular those redirects exiting breaks the assumptions from
the above commit’s commit message and made it possible to obtain
database IDs for activities other than one’s own likes allowing
slightly more mischief with the rendering bug it fixed.

Note: while 0c9bb0594a speculated about
public likes also leaking IDs to other users, the public like endpoint
is actually paginated by post id/date not like id/date like the private
endpoint. Thus it does not allow getting database IDs of others’ likes.
2025-10-26 00:00:00 +00:00
Oneric
8857c98eaf Merge pull request 'Use types for filtering notifications' (#993) from mkljczk/akkoma:akkoma-notification-types into develop
Reviewed-on: https://akkoma.dev/AkkomaGang/akkoma/pulls/993
Reviewed-by: Oneric <oneric@noreply.akkoma>
2025-10-24 19:05:27 +00:00
nicole mikołajczyk
b3a0833d30 Use types for filtering notifications
Signed-off-by: nicole mikołajczyk <git@mkljczk.pl>
2025-10-15 09:06:43 +02:00
Oneric
0907521971 Treat known quotes and replies as such even if parent unavailable
Happens commonly for e.g. replies to follower-only posts
if no one one your instance follows the replied-to account
or replies/quotes of deleted posts.
Before this change Masto API response would treat those
replies as root posts, making it hard to automatically or
mentally filter them out.

With this change replies already show up sensibly as
recognisable  replies in akkoma-fe.
Quotes of unavailable posts however still show up as if they
weren’t quotes at all, but this can only be improved client-side.

Fixes: https://akkoma.dev/AkkomaGang/akkoma/issues/715
2025-10-13 10:26:57 +00:00
Oneric
ed5d609ba4 http: do not add adapter pool options to individual requests
They do nothing. As documented[1] only three specific
options regarding timeouts are parsed for individual request
and none of them is set by AdapterHelper, only pool-specific options.

In particular this means we always relied on Mint’s default CA cert
verification based on queries to the CAStore package (which we include).

[1]: https://hexdocs.pm/finch/Finch.html#request/3-options
2025-10-10 00:00:00 +00:00
Oneric
c94a3b10ee Delete barely used logger mock
It required a bunch of and even call-specific boilerplate
and is not necessary since we can just capture the real logger
as laready done in other tests.
2025-10-10 00:00:00 +00:00
Oneric
f4e188af0a Delete useless, custom JobQueueMonitor
While its data was included in healthcheck responses,
it was not used to determine the healthy status
and for informational purposes Prometheus metrics,
ObanWeb dashboard or the Phoenix live dashboard are all better fits.
In particular, the data shown in healtcheck responses had no temporal
information, but there’s quite a difference between X failures scattered
across many days of uptime and X failures within a couple minutes.
2025-10-10 00:00:00 +00:00
Oneric
6dc546eda7 Merge pull request 'api: order follow requests by date of request' (#984) from Oneric/akkoma:followreq-order into develop
Reviewed-on: https://akkoma.dev/AkkomaGang/akkoma/pulls/984
2025-10-09 23:55:09 +00:00
Oneric
6fbc8330db Merge pull request 'Fix some typos and remove unused code' (#985) from mkljczk/akkoma:akkoma-typos into develop
Reviewed-on: https://akkoma.dev/AkkomaGang/akkoma/pulls/985
Reviewed-by: Oneric <oneric@noreply.akkoma>
2025-10-09 21:53:03 +00:00
nicole mikołajczyk
794b2cde45 Fix some typos and remove unused code
Signed-off-by: nicole mikołajczyk <git@mkljczk.pl>
2025-10-09 15:26:35 +02:00
Oneric
0c9bb0594a Restrict Masto statuses API to Create and Announce activities
If the id of another activity type was used
it would show the post referenced by the activity
but wrongly attributing it to the activity actor
instead of the actual author.

E.g. ids of like activities can be obtained from
pagiantion info of the favourites endpoint.
For all other activity types the id would need to be guessed
which is considered practically infeasible for Flake UUIDs.

This should’ve been mostly harmless in practice, since:
  - since the activity has the same context as the original post,
    both the original and misattributed duplicate will show up in the
    same thread
  - only posts liked by a user can be misattributed to them,
    presumably making it hard/impossible to associate someone with
    content they disagree with
  - by default only the liking user themself can view their like history
    and therefore obtain IDs for their like activities.
    Notably though, there is a user seting to allow anyone to browse
    ones like history and therefore obtain like IDs. However, since
    akkoma-fe has no support for actually displaying those, there might
    be no actual users of this features.
2025-10-09 00:00:00 +00:00
Oneric
06a0cf4278 api: order follow requests by date of request
This is more intuitive for users.
On the flip side, this makes the API more confusing
since now min_id/max_id no longer correspond to ids returned in the
response and only link headers can be used to traverse all response
pages. However, Mastodon already does this according to its
documentation, so clients should already handle this well.

The only other usage of get_follow_requests_query is only interested
in the total count of requests (from active users), thus changing its
select part is safe.
Also gets rid of (outside tests unused) User.get_follow_requests.

Fixes: https://akkoma.dev/AkkomaGang/akkoma/issues/380
2025-10-09 00:00:00 +00:00
Oneric
521dfa4670 Use keyed lists for pagination with foreign id
The old approach required adding a special virtual field
to any table potentially needing such foreign-id pagination and
also still required manually sorting according to pagiantion settings
since the pagination helper does not know whether
this virtual field was set or not.

Using lists with each entry containing the pagination id and the actual
entry insterad allows any table to use this mechanism unchanged and
does not require manually sorting.

Since it was unused, this also drops the pagination mode paramter from
fetch_favourited_with_fav_id.

Furthermore, as a side effect of this change a bug in the favourite
benchmark is fixed. It used to incorrectly attempt to use IDs of
the liked objects for pagination instead of the like IDs as advertised
in Link headers.
2025-10-09 00:00:00 +00:00
Oneric
24d828d9a6 Merge pull request 'telemetry: expose count of currently pending/scheduled jobs per queue' (#982) from Oneric/akkoma:telemetry-job-queue-pending into develop
Reviewed-on: https://akkoma.dev/AkkomaGang/akkoma/pulls/982
2025-10-04 22:44:50 +00:00
Oneric
2190f3bede Merge pull request 'Do not federate undo->block activities' (#958) from undo-block-federation into develop
Reviewed-on: https://akkoma.dev/AkkomaGang/akkoma/pulls/958
Reviewed-by: Oneric <oneric@noreply.akkoma>
2025-10-04 22:43:50 +00:00
Oneric
8c33eed93e Merge pull request 'Renew HTTP signatures when following redirects' (#973) from Oneric/akkoma:httpsig_redirect_resign into develop
Reviewed-on: https://akkoma.dev/AkkomaGang/akkoma/pulls/973
2025-10-04 16:25:49 +00:00
Oneric
43d4716b5a telemetry: expose count of currently pending jobs per queue
Split into scheduled (intentionally delayed until a later trigger date)
and available (eligible for immediate processing but did not yet start).
This will help in diagnosing overloaded instances or too-low queue
limits as well as expose configuration mishaps like
https://akkoma.dev/AkkomaGang/akkoma/issues/924.
(The latter by violently crashing the telemetry poller process while
attempting put_in for a non-configured queue creating well visible logs)
2025-10-03 00:00:00 +00:00
nicole mikołajczyk
545a83a5f1 optimize follow_request_count for own account view
Signed-off-by: nicole mikołajczyk <git@mkljczk.pl>
2025-09-28 23:59:24 +02:00
Oneric
b1e5dda26a telemetry: reduce polling frequency for periodic measurements
Instancce stats are cached only renewed every 5 minutes anyway
and IO stats are cumulative over the entire runtime so no info
is lost.
Polling those every 10s is wasteful and the next commit will add a
periodic measurement which is (comparetively) more costly to compute.
2025-09-21 00:00:00 +00:00
Oneric
155c939070 mix/database: exempt hashtag cleanup from timeouts
As other prune queries already do. While this one is usually rather
quick, it can still run into the default limit.

Reported by ivy on IRC
2025-09-20 11:39:29 +00:00
Oneric
cb19d3285a Drop superfluous RequestBuilder
It’s only used in one place and there not even all of
its functionality is needed. It’s not only simpler and shorter,
but easier to understand if Tesla’s keyword list is just inlined.

The only useful bit which is now migrated to Pleroma.HTTP is
addition of the user-agent header (except, sometimes, in tests)
2025-09-07 00:00:00 +00:00
Oneric
c607387b4a http: do not mix and duplicate Tesla opts into adapter opts 2025-09-07 00:00:00 +00:00
Oneric
271d7d14d4 media_proxy: use :head atom instead of binary
It automatically uses correct capitalisation and is the preferred form.
2025-09-07 00:00:00 +00:00
Oneric
7f9e898781 reverse_proxy: delete unused dynamic client
Since 364b6969eb the reverse proxy
is fixed to use the default HTTP module and all these modules
have been unused since
2025-09-07 00:00:00 +00:00
Oneric
882d8e0320 http/tzdata: ignore unsupported opts
Tzdata assumes Hackney opt names and only uses it to
enable following redirects which we already do anyway.
2025-09-07 00:00:00 +00:00
Oneric
a95b0a5d61 http/webpush: ignore opts due to incompatible format
The web_push_encryption lib assumes HTTPoison semantics
which is why we also need to convert the header format.
Inspecting the libraries source shows that Tesla won’t
understand the options anyway and its only used to enable TLS/SSL.
2025-09-07 00:00:00 +00:00
Oneric
5d59cb7ac3 rel_me: drop unsupported http option
Enforcing a hard response body limit is currently not possible with
Finch. Presumably a leftover from when multiple backends were supported.
2025-09-07 00:00:00 +00:00
Oneric
d34f6ebcdd rich_media/helpers: drop unsupported http opts
When this was ported from Pleroma in
5da9cbd8a5
we did not take into acount that Akkoma’s and Pleroma’s
HTTP backend take different options.
There’s no need for the :pool option
and enforcing a body limit on download
is currently not possible with Finch
2025-09-07 00:00:00 +00:00
Oneric
2b4b68eba7 Ensure private keys are not logged
Ideally we’d use a single common HTTP request error format handling
for _all_ HTTP requests (including non-ActivityPub requests, e.g. NodeInfo).
But for the purpose of this commit this would create too much noise
and it is significant effort to go through all error pattern matches etc
too ensure it is still all correct or update as needed.
2025-09-07 00:00:00 +00:00
Oneric
ff46e448c8 refactor: move creation of date strings for signatures into plug
The Signature module now handles interaction with the HTTPSignature library
and the plug everything related to HTTP itself. It now also no longer needs to be public.
2025-09-06 00:00:00 +00:00
Oneric
4c4982d611 Re-sign requests when following redirects
To achieve this signatures are now generated by a custom
Tesla Middleware placed after the FollowRedirects Middleware.
Any requests which should be signed needs
to pass the signing key via opts.

This also unifies the associated header logic between fetching and
publishing, notably resolving a divergence wrt the "host" header.
Relevant spec demands the host header shall include a port
identification if not using the protocols standard port.

Fixes: https://akkoma.dev/AkkomaGang/akkoma/issues/731
2025-09-06 00:00:00 +00:00
Oneric
86988e71f0 mix/database/resync_inlined_caches: also resync reactions
Relies on the fixups from preceding commits being applied.
2025-08-30 00:00:00 +00:00
Oneric
89801abad5 federation/in: drop remote part from received emoji reactions
The remote part is included in federated emoji names by e.g.
Iceshrimp.NET ever since remote emoji support was added in
4d21aa1670
and as of writing it still continues to do so.
It adds no value for us though; we add the remote part automatically
based on the URL and it makes it more difficult to correctly coalesce
the original reaction (from a user for whom the moji was local)
and the subsequent reactions with the identical emoji from users of
other instances. Additionally the remote part can cause issues when
later used with our REST API.

For non-reactions this is unproblematic and thus
there’s no need to change anything there.

Use a migration to fix up existing activities.
This will cause some (further) desync from the inlined reactions
array, but will be fixable with the resync mix task and avoids
issues when running the resync without first fixing existing activities.
2025-08-30 00:00:00 +00:00
Oneric
4765b79b49 Remove deprecated :warnings_as_errors from startup
This was already removed from mix.exs in
ea5a2a9f21
but as it turns out it was also re-set
during runtime.
Since we never set it outside of CI in
the first place there’s no need to
force-disable it here.
2025-08-30 00:00:00 +00:00
Oneric
16d0250c24 mix/database: by default fix replies count after object prune
Even if --keep-threads is used, replies of
pinned posts might still be pruned as documented
for this option.
Thus keep-threads is no reason to skip reply counter recalculation.
2025-08-30 00:00:00 +00:00
Oneric
fcf4867ddf mix/database: add task to resync inlined array duplicates
Presumably those inlined copies were added to avoid the need for queries
each time the info is needed. However, they tend to desync from the actual
activities for not yet fully understood reasons; see:
https://akkoma.dev/AkkomaGang/akkoma/issues/956

As a workaround until the root cause is identified and fixed and/or
we no longer rely on the inliend copies add a mix task to regenerate
the inlined "cache" from the authorative activity data.

Does not yet deal with inlined emoji reactions
since its format is a pain to deal with.
2025-08-27 00:00:00 +00:00
Oneric
97e1eccf89 mix/database: add task to empty inlined replies lists
Those arrays are only used on first post receipt in side effect processing
and but an useless waste of space and misleading afterwards.
2025-08-27 00:00:00 +00:00
Oneric
ce73239e08 Fix private remote replies changing reply counter
In the ActivityPub module counter changes are already limited to
only publicly-visible replies. Apply the same limitiation here.
2025-08-27 00:00:00 +00:00
Oneric
f754feb67d federation: include required actor fields in minimal user fallback
ActivityPub spec demands each actor has at least an inbox and outbox.
Furthermore, the current representation wouldn’t even be accepted by
ourselves, since our processing requires objects to be flagged with a
sensible type else we don't know what to do with it.
Including the nickname is just a peemptive measure.

There were no reports of this causing problems in real-world deployments
and at least for federation with other Akkoma instances we should have
never run into this, since we _always_ expose the full representation of
the instance actor and atm also always use the latter for fetching
remote content (which prevents us from fetching followers-only content).
Nonetheless, serving something which violates spec and we wouldn’t even
accept ourselves seems obviously bad, so fix it and add tests to prevent
this from reoccuring.

Fixes bug introduced in 8f322456a0
2025-08-27 00:00:00 +00:00
Oneric
7f9823258a metrics: adjust router and db buckets
Most HTTPS requests actually fall into the single-digit millisecond
range or below on average. Even the more costly endpoints almost always
average around the lower third of the millisecond magnitude.
Only endpoints doing synchronous remote HTTP fetches (e.g. for signing
keys) occasionally spike into the order of seconds.
As is, the bucket resolution is completely unfit to reason about
anything and even just averages are better indications.

Most database queries take less than a millisecond and even in total
almost all take less than 50ms for me. Decode time is but a tiny
fraction of that and queue time usually only takes a small part of total
time too (but may spike on high load).

Shift the buckets down to be able to
give insight into all relevant cases.
In particular this allows to determine whether high averages
are the result of generally high processing times or just a few
outliers lifting the whole average up (e.g. slow network fetches).

Exact numbers are biased towards my setup for lack of other comparison
data, but at least the order of magnitude should be ok everywhere.
2025-08-24 00:00:00 +00:00
Oneric
be2e014c60 Merge pull request 'Allow HTTP2 for outgoing connections and untangle the adapter opt mess' (#969) from Oneric/akkoma:untangle_adapter_opts into develop
Reviewed-on: https://akkoma.dev/AkkomaGang/akkoma/pulls/969
2025-08-23 15:54:43 +00:00
Oneric
acc05ca02f http: avoid failures connecting to HTTP2 servers supporting server push 2025-08-23 00:00:00 +00:00