Forum teuk.org

🛡️ Protego the Spellbook! Mediabot Strengthens Its Configuration Saves

in Mediabot · started by TeuK · 4d ago

TeuK · 4d ago

MB834 — atomic saves, safer concurrent changes, faithful text values and honest administration replies.

After giving Mediabot an IRC network observatory, this maintenance round turns to the spellbook behind the bot: its configuration.

Those settings control how the instance behaves, which services it uses and how it connects to the world. Writing them deserves care. MB834 strengthens that shared save path, closing a follow-up identified during the previous maintenance review.

The work covers configuration persistence, its reload lifecycle and the administration commands that depend on it. The full validation suite has now passed on teuk.org. ✨

📖 Keep the old page until the new one is ready

Previously, saving through the underlying configuration library truncated the active file before writing its replacement. An interrupted process or failed write could therefore leave an incomplete configuration behind.

MB834 prepares the new contents in a private temporary file in the same directory. Serialization must succeed, the existing owner, group and permissions are preserved, and the prepared file is synchronized before publication.

Only then does an atomic rename replace the active configuration. Readers can see the previous complete file or the completed replacement.

The regression tests interrupt a real writer with SIGKILL during serialization and check that the active configuration remains intact. They also exercise partial writes, synchronization failures and failed publication.

A little Protego around the parchment goes a long way. 🪄

🦉 One quill at a time

Another reproduced problem involved two configuration objects reading the same file. If one saved a change, the second could later overwrite it using an older copy of the settings.

The new save path combines a private writer lock with checks of the file’s identity, metadata and contents. A stale writer is refused, and observed operator edits are checked again immediately before publication.

The lock is nonblocking, so another writer cannot leave an IRC command waiting indefinitely for its turn.

When a revision conflict occurs, the recovery is explicit: reload the configuration and reapply the intended change. Stable symbolic configuration paths remain supported; silently redirecting a save after a link has been retargeted is prevented.

These protections coordinate writers using the new mechanism. The established practice of stopping an instance before editing its configuration by hand still applies.

✍️ Commas should stay inside the sentence

Persistence also means keeping the meaning of a value.

Without suitable quoting, a text such as:

Be brief, clear and helpful.

could be written back in a form that the parser interpreted as a list on the next read.

MB834 uses the existing library’s strict quoting for that save only. Literal commas, quotation marks, backslashes, surrounding whitespace and list boundaries now have regression coverage. The library’s global quoting setting remains unchanged.

Caller-owned arrays are also copied before normalization, so setting a list no longer rewrites the caller’s own elements in place. Structural control characters are rejected before publication instead of becoming malformed configuration content.

Existing values already parsed as lists retain that meaning; the bot does not guess whether an old list was originally intended to be a sentence.

🔔 Tell the keeper when a save fails

The review followed failures all the way back to the IRC commands.

Previously, a false save result could still be followed by a success notice. A thrown exception could escape the command handler.

The Owner-only OpenAI set/reset/profile and debug paths now catch both outcomes and send a private failure notice. Server logs record a bounded reason, keeping dependency exception text and configuration values out of these failure diagnostics. The live debug logger advances only after persistence succeeds.

The authentication and Owner checks remain in place, with regressions exercising denied identities as well as successful commands.

One distinction stays explicit: set changes memory immediately; save persists it. A failed save leaves pending values in memory. The failure notice says so, allowing the operator to choose a retry or a reload and reapplication.

🧪 Put the safeguards through their O.W.L.s

Two new regression files add 227 assertions:

  • 103 filesystem assertions: real competing processes, abrupt termination, I/O failures, metadata, symbolic paths, value preservation and conflict recovery.
  • 124 administration assertions: real command handlers, successful persistence, failed saves, private notices, diagnostic redaction and access restrictions.

Running those tests against the previous implementation produced 45 and 42 failing assertions respectively. They demonstrate reproduced failure cases, rather than an assumed production incident.

Final validation on teuk.org completed with:

Validation Result
Targeted integration 680 / 680 passed
Fast validation lane 8,288 / 8,288 passed
Full suite 23,866 / 23,866 passed across 1,095 test files
Security audit 37 / 37 invariants passed

The update package also exercises source rollback after a failed required check, preserves the real Git index and private configuration, and retains concurrent source edits for inspection.

🏰 A stronger foundation for the next spells

Source validation is complete. Loading the new code on the development bot, committing through the established helper and updating production remain the normal rollout steps.

The maintenance report documents the precise filesystem and concurrency boundaries, including hardlinks, extended metadata and storage failures. Atomic publication protects complete-file visibility; it does not promise recovery from every possible power or hardware failure.

Mediabot’s next adventures can build on a spellbook that is harder to truncate, harder to overwrite accidentally and more faithful to the words written inside it. Protego! 🛡️📚

You must be logged in to reply.