Forum teuk.org

🧠🔐 Mediabot v3 — The Headmaster Locks the Pensieve

in Mediabot · started by TeuK · 1w ago

TeuK · 1w ago

Development chronicle — mb631 · Administrator-only AI summaries and a truthful UTF-8 regression guard

This round is deliberately focused.

ai summary can read and reformulate a large amount of channel history. That makes it useful, but it also makes it closer to a moderation tool than an ordinary public IRC toy.

Mediabot now treats it accordingly: AI summaries require Administrator access everywhere the feature can be invoked.

The same round also fixes a date-dependent false positive in the UTF-8 regression suite and strengthens the permission test so it exercises the real partyline gate rather than merely recognizing source code.

No database schema change was required.


🔐 ai summary is now Administrator-only

The restriction applies to every supported entry point:

m ai summary ...

in a channel,

/msg bot ai summary ...

in private,

and:

.ai summary ...

from the partyline.

The public and private IRC forms already share the same command implementation, so they also share the same permission gate.


🚪 The gate comes before the summary work

For IRC commands, the Administrator check happens before summary-specific argument parsing, help handling or CHANNEL_LOG access.

Conceptually:

ai summary ...
      |
      v
Administrator?
      |
      +-- no  --> reject
      |
      +-- yes
             |
             v
        parse request
             |
             v
       read CHANNEL_LOG
             |
             v
        build summary

An unauthorized caller therefore does not trigger the expensive part of the feature.

Even:

m ai summary help

goes through the same gate.

The restricted subcommand does not document itself to a caller who cannot use it.


🪄 The rest of ai remains unchanged

This is a targeted permission change.

Other AI subcommands such as:

forget
models
stats
reset
history
pin

are not accidentally placed behind the new summary restriction.

The regression test explicitly checks that these neighbouring routes still exist outside the summary gate.

That matters because moving a permission check one level too high would silently change the contract of the whole ai command family.


🏰 Partyline permissions use the opposite scale

The partyline has an important historical convention:

Owner          = 0
Master         = 1
Administrator  = 2
...

Lower numbers mean stronger privileges.

So:

Administrator or better

is expressed as:

level <= 2

rather than >= 2.

The reason is documented directly beside the check so a future cleanup does not “fix” it in the wrong direction.


🧪 The partyline gate is tested at runtime

The final pre-commit review strengthened test 813.

It no longer relies only on finding something that looks like:

level <= 2

inside Partyline.pm.

The test now exercises the actual command path:

ordinary user
      |
      v
.ai summary
      |
      +--> Permission denied

Administrator
      |
      v
.ai summary
      |
      +--> passes the permission gate

That distinction is important.

A source-code pattern can remain present while the real execution path stops using it.

A runtime test proves considerably more.


✨ A mojibake guard was mistaking French for corruption

The same development pass uncovered a surprisingly subtle flaky test.

The UTF-8 guard treated a standalone:

â

as evidence of double encoding.

But â is a perfectly legitimate French character.

Words such as:

âmes
bâtis
tâche

can naturally occur in Mediabot’s horoscope text.

Because the horoscope output is deterministic by date, the test could therefore:

pass on one day
fail on another day

while the IRC output itself was completely valid.

That is exactly the kind of flaky regression test that slowly destroys confidence in a test suite.


🎯 The guard now looks for actual mojibake signatures

The repaired test targets patterns that really indicate UTF-8 corruption, such as the characteristic sequences produced by double encoding.

It no longer treats every circumflex as suspicious.

Just as importantly, two explicit regression assertions prove both sides:

valid French circumflex
        |
        +--> accepted

real double-encoded text
        |
        +--> rejected

So the fix does not merely weaken the guard until it stops complaining.

It makes the guard more precise.


🧹 One numbering correction before publication

During review, this round was initially called mb630.

But mb630 was already used by the previous committed development round for the dispatch-test truth fix.

The public history therefore keeps one unambiguous sequence:

mb629  leaderboard access/layout
mb630  truthful dispatch regression test
mb631  Administrator-only AI summary

The associated regression test remains number:

813

because that test number was still free.

Clean numbering sounds mundane, but it makes changelogs, bug reports and targeted test filters much easier to trust months later.


🧪 Regression coverage

The final mb631 pass touches both new and older guards:

630  AI summary public-lines/help compatibility
791  AI summary language compatibility
804  UTF-8 wire encoding and mojibake detection
809  full-period summary reading
813  Administrator gate across IRC and partyline

Test 813 now protects:

  • Administrator requirement in the IRC path;
  • rejection before summary-specific processing;
  • guarded summary help;
  • inverse partyline privilege scale;
  • real partyline denial at runtime;
  • real Administrator passage through the gate;
  • neighbouring ai subcommands remaining unrestricted;
  • public help text reflecting the new access level.

🏰 Final parchment

The Pensieve was useful enough that everyone could see why they wanted access to it.

That was also the reason to lock the door.

Mediabot can now read a long channel history, select what mattered and reformulate it through an AI model — but only a trusted operator can ask it to do so.

And while the Headmaster was changing the lock, the castle inspector learned another lesson:

a French accent is not evidence of dark magic.

The door is stricter.

The UTF-8 test is smarter.

And the rest of the spellbook stays exactly where it was.

You must be logged in to reply.