Forum teuk.org

🦉 Mediabot v3: Five New Charms for Reports, Configuration, AI Replies, YouTube and Hailo — MB357 to MB361

in Mediabot · started by TeuK · 13h ago

TeuK · 13h ago

The latest Mediabot v3 pass did not add a new castle wing or summon a database migration.

Instead, it dealt with the sort of problems that usually hide behind tapestries: one broken report section silencing the next, configuration mistakes being corrected without explanation, AI responses disappearing because the first block was not text, YouTube counters speaking two dialects, and Hailo callbacks attempting to consult a brain that was never successfully awakened.

Claude carried out the MB357–MB360 rounds. The final MB361 review then followed the same rule that has guided the whole series:

Strengthen the existing bot without changing the database schema and without turning a small correction into a dangerous rewrite.

The complete validation is green.


🗞️ MB357 — The Daily Prophet no longer stops printing after one cursed section

Daily and weekly reports were vulnerable to failures that had a much wider effect than they should.

In the daily path, an exception raised while processing one channel could abort the entire loop. Every channel after the faulty one would simply receive no report.

The weekly path already had some channel isolation, but its speakers and karma sections still shared the same protection. A failure in the first section could therefore prevent the second from appearing.

MB357 placed proper containment wards around the process:

  • each daily channel is isolated from the next;
  • speakers and karma are protected independently;
  • an error in one section is logged clearly;
  • the remaining sections and channels continue normally.

The ranking queries were also made deterministic.

When several users had the same score, SQL previously had no stable secondary order. The displayed top three could therefore change between runs, and the user excluded at the limit could be selected arbitrarily.

Ties are now settled alphabetically by nickname.

The Daily Prophet may still report bad news, but one spilled ink bottle no longer burns the entire edition.


🧪 MB358 — Misconfigured integers now leave a visible trace in the cauldron

Mediabot::Conf->get_int() already protected integer settings by applying defaults and safe limits.

The problem was silence.

A value such as:

PARTYLINE_LOGIN_IP_WINDOW_SECONDS=60O

could fall back to its default without telling the administrator that the last character was the letter O.

Likewise, a value outside its permitted range could be clamped silently.

MB358 added useful diagnostics for values that are present but invalid:

  • malformed integers report that the default is being used;
  • values below or above their limits report the applied clamp;
  • missing keys remain silent because using the documented default is normal;
  • repeated reads of the same bad value produce only one diagnostic.

The result is operationally useful without becoming another noisy Howler in the logs.


📜 MB359 — Claude replies are now read from every scroll, not only the first

Anthropic responses may contain several content blocks.

The first block is not guaranteed to be the final text. It may be a thinking block, a tool-use block, or another non-text structure.

The previous parser inspected only the first block. When useful text appeared later, Mediabot could answer with:

Could not read Claude response

even though Claude had actually replied.

MB359 now walks through the complete content array and joins every valid text block.

This preserves the normal single-text response while correctly handling:

  • a thinking block followed by text;
  • a tool-use block followed by text;
  • several separate text blocks;
  • malformed or empty content without crashing.

No useful parchment is discarded simply because it was not placed on top of the pile.


🔭 MB360 — YouTube view counts now use one shared set of runes

Mediabot had two different ways to display the same YouTube view count.

One path showed the raw number:

views 1234567

The other used a compact form:

views 1.2M

MB360 introduced the shared _yt_format_views helper and routed both display paths through it.

The output is now consistent:

  • millions use M;
  • thousands use k;
  • small values remain readable as-is;
  • missing or invalid values use ?.

This is a small visual correction, but it removes duplicated logic and prevents the two YouTube paths from drifting apart again.


🧿 MB361 — Hailo can no longer hex an IRC callback when its brain is unavailable

The Hailo subsystem is allowed to fail during initialisation without preventing the entire bot from starting.

That graceful startup path was useful, but the runtime code did not fully respect it.

Several IRC paths still attempted to call learn() or learn_reply() on an undefined Hailo object:

  • direct replies when the bot nickname was mentioned;
  • random HailoChatter replies;
  • passive learning;
  • the nickname-triggered fallback path.

Depending on the path, this could break the current IRC callback or incorrectly record the problem as a Hailo timeout.

MB361 introduced one shared runtime guard:

  • Hailo is used only when its brain is actually available;
  • unavailable paths are skipped safely;
  • the condition is logged once instead of repeatedly;
  • the timeout counter is no longer blamed for an initialisation failure;
  • normal Hailo behaviour is unchanged when initialisation succeeds.

The HailoChatter ratio was also investigated

The existing comparison initially looked suspicious:

rand(100) >= 97

However, the command deliberately stores:

100 - requested percentage

A requested chatter chance of 3% is therefore stored as 97, making the existing condition correct.

No semantic change was made, and the bot was not accidentally transformed into an endlessly talkative portrait.


⚗️ Validation

The new MB361 regression test passes:

21/21

The targeted MB356–MB361 regression group passes:

118/118

The complete test and syntax validation run on the Mediabot development host is green.

No database structure was modified.

0 new tables
0 altered columns
0 migrations
0 schema changes

🪶 What Claude completed, and what the final review added

Claude completed the four preceding rounds:

  • MB357: report isolation and deterministic ranking ties;
  • MB358: deduplicated diagnostics for invalid integer configuration;
  • MB359: robust parsing of multi-block Anthropic responses;
  • MB360: shared and consistent YouTube view formatting.

The final review added:

  • MB361: safe Hailo runtime guards when initialisation has failed;
  • confirmation that the existing HailoChatter probability calculation is intentional and correct.

Together, the five rounds improve failure containment, operational visibility, AI response reliability, output consistency and IRC runtime resilience.


🕯️ Closing the spellbook

None of these changes are theatrical rewrites.

They are the quiet protections that matter on a bot expected to remain connected for weeks or months:

  • one report failure stays local;
  • bad configuration explains itself;
  • Claude’s full answer is actually read;
  • YouTube speaks consistently;
  • Hailo cannot crash a callback merely because its brain failed to wake.

Mediabot v3 remains recognisably the same bot.

It simply has fewer cursed corners now.

Teuk

You must be logged in to reply.