Forum teuk.org

🧙 Mediabot v3 — Dive Into the Pensieve and Summon Forgotten Channel Memories

in Mediabot · started by TeuK · 5d ago

TeuK · 5d ago

Commit: dbfe67a
Version: 3.4dev-20260818_075719

Mediabot has accumulated years of conversations.

With MB664, it finally learns how to deliberately lose itself in them.

Not by scanning the whole library.
Not by throwing ORDER BY RAND() at millions of IRC lines and hoping MariaDB survives.

Instead, Mediabot now has its own little Pensieve.

🪄 New command: memory

From a channel:

m memory

Mediabot selects a real moment from that channel’s history and brings back a compact memory card.

A real dev-runtime result looked like:

📼 Memory from #radiocapsule — 2026-03-03:
91 messages, 9 people, most active: Balibalo.

The important difference is that this is not another alias for onthisday.

onthisday asks:

What happened on this calendar date in previous years?

memory asks:

Take me somewhere in this channel's past.

That makes it much more exploratory — a small trip through years of accumulated IRC history.

🧠 The Sorting Hat rejected ORDER BY RAND()

Random history sounds innocent until the table contains years of messages.

So MB664 deliberately avoids:

ORDER BY RAND()

and avoids unbounded historical scans.

Instead, the selection strategy uses:

indexed temporal seek
        ↓
one historical day
        ↓
bounded aggregation
        ↓
top talker
        ↓
bounded quote candidates

The existing (id_channel, ts) indexing strategy does the heavy lifting.

Once a historical day has been selected, the expensive-looking operations remain confined to that single day rather than the entire lifetime of the channel.

📚 Live history and the Restricted Section

Mediabot already knows that old channel history may live in two places:

CHANNEL_LOG
CHANNEL_LOG_ARCHIVE

MB664 does not invent another archive mechanism.

It reuses the existing channel-history content policy, meaning memory understands the same live/archive world as the rest of Mediabot.

It also inherits the existing:

+OnThisDay

channel switch.

So administrators do not suddenly get another configuration spell to maintain.

+OnThisDay
    → onthisday / otd enabled
    → memory enabled

-OnThisDay
    → historical nostalgia silenced

No new chanset was needed.

⚡ The Pensieve cannot freeze IRC

Historical database queries do not execute directly in the IRC event loop.

memory runs through the existing:

Mediabot::CommandAsync

contract.

That gives the command its own isolated database work while the parent Mediabot process remains responsive.

During runtime testing, this also exposed a useful integration detail.

The first implementation tried to use the normal delayed NOTICE queue from inside the worker. Those timers belonged to the disposable child process and therefore disappeared before they could fire.

MB664 was corrected to emit direct NOTICE intents from the worker, which CommandAsync safely captures and replays from the parent.

The result is both asynchronous and visible to the user.

🧪 Tests before Divination

Two dedicated regression files were added:

845_mb664_channel_memory.t
846_mb664_channel_memory_public.t

They cover the two sides of the feature.

Historical engine

The tests verify that:

history access is bounded
archive-aware gathering is reused
content scope is respected
ORDER BY RAND() is absent
historical selection remains time-based
day aggregation stays bounded
quote candidates stay bounded

Public command

They also verify:

m memory is exported and dispatched
CommandAsync is mandatory
+OnThisDay is reused
help integration exists
the command belongs to the social category
no new +Memory chanset appears
worker output uses replay-safe NOTICEs

Focused MB664 validation:

PASSED : 23/23

The wider async regression:

PASSED : 91/91

And the normal development fast lane remained green:

PASSED : 5187/5187
Runtime: 178s

🧹 No new chamber beneath Hogwarts

MB664 adds:

no database schema change
no migration
no new configuration key
no new chanset
no systemd change
no service change
no new background daemon

It deliberately builds on infrastructure Mediabot already gained during the previous reliability rounds.

That was the point of doing all that architectural work first.

🗺️ From infrastructure back to adventures

The recent Mediabot roadmap spent considerable effort on things users rarely see directly:

Doctor
AsyncWorker
test profiling
test classification
fast validation
safe parallel experiments
migration documentation

Those foundations now start paying dividends.

MB664 is a good example: a feature that reaches deep into years of database history can be added without redesigning persistence, blocking IRC, or creating another framework.

Sometimes the best new spell is the one the castle was already prepared to cast.

And now, whenever someone feels nostalgic:

m memory

Mediabot can simply open the Pensieve.

You must be logged in to reply.