Feature plan: Step 1 · Step 2 · Step 3 · Step 4

Audio files: Step 4 implementation summary

Planning commits verified on plans/audio-files: Step 1 (61cdba4), Step 2 (a8bb6cd), Step 3 (bca05f1), all pushed.

Storage changes: none.

Stage 1 - reference, inspection, storage and the flag

  • Changes:

    • New src/ForumRewrite/Audio/AudioReference.php: the Audio-v1: line (hash, mp3/m4a, bytes, milliseconds, optional title), at most 8 MiB and three minutes, one per post, canonical encoding, and the shared refusal message "Export as MP3 or M4A, three minutes or less."

    • New AudioInspector.php: reads type and length from the bytes, never the name. MP3: walks every Layer III frame after an optional ID3 tag and skips the encoder's info frame, so constant and variable bitrate measure the same. M4A: the movie header's length, with an AAC sound track required and video refused. A length it can't read is refused, not guessed.

    • New AudioStore.php: hash-named files outside Git and the web folder (FORUM_AUDIO_ROOT, default <repo>-audio), 0600, verified against the signed reference, with its own cap of 512 MiB and 512 files.

    • New flag FORUM_AUDIO_CONTENT_ENABLED ("Audio attachments", Authoring group, off by default, site-mutable).

    • Small fixtures in tests/fixtures/audio/ (two-second tones; the largest is 8 KB). Over-length and oversize files are built inside the test.

  • Deviation: the upload permission is reused in Stage 2, where the write path checks it, rather than wrapped in a new class here.

  • Verification:

    • Passed: new AudioAttachmentTest (5 tests). It covers the reference round trip and bad values; type and length for CBR MP3, VBR MP3 and M4A; a renamed M4A detected by content; refusal of WAV, MP4 video, ALAC M4A, a 3:01 MP3, an M4A whose header says four minutes, a 9 MB file and plain text; store put, verify, permissions, mismatch refusal, removal and the path check; and the flag's defaults.

    • Passed: FeatureFlagEvaluatorTest (new flag added to its expected list), FeatureFlagChangePageTest, FeatureFlagsBehaviorTest and LocalAppSmokeTest. FeatureFlagsBehaviorTest first failed because the new flag sat between Image attachments and the flags that depend on it; it now follows them in the Authoring list.

    • Not run: the full suite.

— Claude · 2026-12-04 UTC

Stage 2 - posting with an audio file

  • Changes:

    • LocalWriteService: unsigned thread and reply writes refuse an Audio-v1: line or an audio field, as they do for images. Preparing a thread or reply checks the flag and that the signer is approved. createPreparedPost() takes an optional audio file, checks its bytes against the signed reference before anything is written, saves it after the commit, and stays safe to retry after a lost response, the same as images.

    • WritePostAndIdentityApiController: accepts an audio upload beside image. The type comes from the bytes, never the browser's label. The over-limit message now names both caps.

    • Removal (SourceLabelRemoval): deleting a post also deletes its audio file unless another file still mentions its hash, reported as removed_audio.

    • FORUM_AUDIO_ROOT is a deployment setting (private config schema, template example, private directory exclusions), like FORUM_IMAGE_ROOT.

    • get_profile adds Audio-Upload-Allowed, and llms.txt mentions audio and that quill.py has no audio option yet.

  • Verification:

    • Passed: new WriteApiSmokeTest::testAudioSignedPublicationRejectsBadFilesAndRetriesSafely (unsigned refusal, mismatched bytes leave no record, missing file, flag off, success and identical retry, stored bytes match, an unbound file refused, Audio-Upload-Allowed: yes).

    • Passed: AudioAttachmentTest, DeleteRecordCommandTest, DeleteThreadCommandTest, LlmsTxtRendererTest, LocalAppSmokeTest, ThreadTitleWithdrawalAndConsumersTest, all of WriteApiSmokeTest and PrivateConfigCommandTest (449 tests).

    • Not run: the full suite.

— Claude · 2026-12-04 UTC

Stage 3 - serving the file

  • Changes:

    • New src/ForumRewrite/Http/AudioController.php at /audio/<sha256>.<mp3|m4a>, after the instance access gate and only while the flag is on. It re-reads the stored file and checks its hash and type against the address before serving.

    • Byte ranges (Accept-Ranges, 206 with Content-Range, 416 when out of range), because iPhone Safari won't play or seek audio without them. Several ranges in one request get the whole file.

    • ?download=1 sends it as an attachment, named from ?name= cleaned to letters, digits, spaces, dots, dashes and underscores. Otherwise it is inline.

    • The same year-long private caching as images; error answers are never kept.

    • Application.php routes /audio/ beside /images/ and counts it as an application route. public/.htaccess was read: no rule serves /audio/ statically.

  • Verification:

    • Passed: new AudioServingTest (range parsing, download names, whole file, Safari's two-byte probe, a middle range, a suffix range, an unsatisfiable range, the download answer, unknown hash, bad name, wrong extension, flag off).

    • Passed: AudioAttachmentTest, ApiRouteCatalogTest, ImageServingTest, LocalAppSmokeTest (187 tests).

    • Not testable in CLI: response headers and status codes; checked by reading. The browser check in Stage 7 plays and seeks for real.

    • Not run: the full suite.

— Claude · 2026-12-04 UTC

Stage 4 - "Attach audio" in the composer

  • Changes:

    • New templates/partials/audio_compose_fields.php: the hidden file input (audio/mpeg, audio/mp4, .mp3, .m4a), the chosen file's name, length and size, a remove ×, and a status line.

    • composer.php: "Attach audio" in the ··· menu beside Attach image, disabled with its reason under (i) until the key is confirmed allowed. Without scripts it stays disabled: "Attaching audio needs JavaScript."

    • New public/assets/audio_upload.js (loaded only while the flag is on). It checks the key through get_profile (Audio-Upload-Allowed), then checks the picked file on the device: type from its first bytes, at most 8 MB, and at most three minutes (an M4A's length from its header, as the server reads it; an MP3's from the browser). A bad file gets "Export as MP3 or M4A, three minutes or less." and nothing is signed.

    • browser_signing.js: the signed attachment path now carries audio, alone or with an image. It adds the Audio-v1: line (hash, type, bytes, milliseconds), signs, and sends the file as audio. Anonymous posting, a queued inline reply and Save to Outbox each refuse audio with a plain message, and clearing the draft clears the audio.

    • body carries data-audio-content-state, and cached static pages are re-rendered when audio is switched on or off, as for images.

  • Deviation: Step 3 mentioned a plain file field without scripts. Audio is checked and signed in the browser, as images are, so without scripts the item stays disabled with its reason, the same as Attach image.

  • Verification:

    • Passed: new tests/browser/audio_upload_check.mjs in Chromium at 390×844: allowed key gets the item; a guest and a key without permission see why; an M4A and an MP3 show "0:02 · N KiB"; WAV, a text file named .mp3 and an M4A whose header says four minutes are refused with the message; remove clears it.

    • Passed: tests/browser/image_upload_eligibility.mjs (unchanged image behavior).

    • Passed: smoke set plus ImageContentTest, LazyComposeSigningTest, OfflineOutboxComposeTest, ComposeAttemptReplayTest, AudioAttachmentTest, AudioServingTest (540 tests).

    • The full sign-and-upload path from a real page is checked in Stage 7.

    • Not run: the full suite.

— Claude · 2026-12-04 UTC

Stage 5 - the play bar in threads and on /tracks/

  • Changes:

    • MediaEmbedRenderer::renderAudio(): an attached recording renders as the browser's own <audio controls preload="none"> (so it plays without scripts), a hidden site play bar (play/pause, a seek line, elapsed / total time) and a plain Download link named after the title. The text around the Audio-v1: line renders as before. With the flag off it says "Audio unavailable".

    • New public/assets/post_audio_player.js: swaps the native controls for the play bar, keeps the seek line and time in step, and plays one thing at a time (starting a recording pauses the others and closes an open embed). media_embed_inline_player.js pauses attached audio when an embed opens. It watches for rows added later.

    • ThreadTitle: a post that is only a recording is titled by its title, or "Audio".

    • /tracks/: a row whose opening post has a recording plays it, ahead of any link; uploads count as playable. The reference is read from the stored post body (posts.body), since body_preview holds only the first line. No new storage.

    • Styles in site.css: one line, 44px play button, tabular time.

  • Verification:

    • Passed: AudioAttachmentTest (6 tests, now including the rendered player, the flag-off text and the title).

    • Passed: new tests/browser/post_audio_player.mjs at 390×844: without scripts, native controls and Download links show; with scripts, the bar replaces them, the play button is 44px, play works, starting the second pauses the first, seeking lands near one second, and a second click pauses.

    • Passed: MusicPageTest, MediaEmbedRendererTest, AudioServingTest, LocalAppSmokeTest, ThreadTitleWithdrawalAndConsumersTest (214 tests).

    • An upload row on /tracks/ is checked end to end in Stage 7.

    • Not run: the full suite.

— Claude · 2026-12-04 UTC

Stage 6 - the Friday queue order

  • Changes:

    • MusicPageController::playable(): the queue (slides, Play all count) now plays recordings uploaded in the past 14 days first, then everything else (links and older uploads), both newest shared first, as Ilya set. FRESH_UPLOAD_DAYS = 14. The controller takes an optional clock for tests.

    • A slide for an upload plays its recording on the play bar (music_slides.php).

    • added.txt: a new upload reaches an open queue like a new link. #playnext is unchanged.

    • TagPage::newestShared() also returns root_post_created_at, an existing column. No new storage.

  • Verification:

    • Passed: new MusicPageTest::testQueuePlaysThisFortnightsUploadsFirstThenEverythingNewestFirst. It walks the slides with a 1-day-old link, a 3-day-old upload, a 30-day-old upload, a 60-day-old link and a text post, and expects fresh upload, new link, older upload, old link. It also checks Play all counts 4, the upload row and slide play the recording, added.txt carries the new upload, and with audio off the queue goes back to links only, in today's order.

    • Passed: MusicPageTest, MusicQueueTest, MusicSlidesPageTest, AudioAttachmentTest, LocalAppSmokeTest (194 tests).

    • Not run: the full suite and the music browser scripts (no browser-side change).

— Claude · 2026-12-04 UTC

Stage 7 - end-to-end check and documentation

  • Changes:

    • New tests/browser/audio_end_to_end.mjs with tests/Support/audio_browser_router.php (reusing the image browser fixture's approved key): at 390×844, the composer's ··· menu offers Attach audio, a voice memo (M4A) shows "0:02 · …", the signed post lands on its thread with the play bar, the served file's hash matches the signed reference, a Safari-style bytes=0-1 probe gets 206 with the right Content-Range, and Download answers as an attachment.

    • New concept page docs/concepts/audio_attachment.md; media_embed.md and music_section.md note the shared one-at-a-time rule, uploads on /tracks/ and the queue order.

  • Verification:

    • Passed: audio_end_to_end.mjs, audio_upload_check.mjs, post_audio_player.mjs in Chromium.

    • Concept links checked against the tree.

    • Not run: the full suite, and a real Safari engine (Playwright here has Chromium only).

  • Pending, after deploy (Ilya's iPhone check):

    1. On mitrapclub, turn on Audio attachments in Tools → Feature Flags (Authored content).

    2. On the iPhone, open the board or /tracks/, tap ··· and Attach audio, and pick a short voice memo. Expect its length and size under the box.

    3. Post. The thread shows the play bar. Tap play, drag the line, tap Download.

    4. Try a four-minute recording: expect "Export as MP3 or M4A, three minutes or less." before anything uploads.

    5. On /tracks/slides/, the new upload comes first.

  • Follow-up (Ilya, by voice: "just like images"): a download without a title is named by its hash and type, as images are (<sha256>.m4a), instead of "Audio". A recording that carries a title keeps that name.

— Claude · 2026-12-04 UTC

  • Follow-up after PR review (Ilya asked for it by voice, 2026-12-04):

    • Rebased onto the layered interface branch (plans/layered-interface, PR #558), which conflicted in site.css, TemplateRenderer.php and the plans README; both features kept. Merge #558 first.

    • /audio/<hash>.<ext> no longer re-reads and hashes the whole file on every request. iPhone Safari sends many small range requests while playing and seeking, and each one cost a full read and SHA-256 of up to 8 MB. Serving now checks the name, extension and size only; the bytes were checked when AudioStore::put wrote the file, and stored files are never rewritten. Answers stream in 256 KB pieces instead of one read.

    • Checks: ./v3 test --smoke AudioServingTest AudioAttachmentTest MusicPageTest WriteApiSmokeTest LayerSettingTest PlainSiteTest FeatureFlagEvaluatorTest. Full suite not run.