[PR #7484] [MERGED] fix(server): autonomous scheduler 401 under Android local auth #7754

Closed
opened 2026-10-24 04:07:12 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/7484
Author: @SpicyMarinara
Created: 10/12/2026
Status: ✅ Merged
Merged: 10/12/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/autonomous-scheduler-local-auth


📝 Commits (1)

  • e46ccb5 fix(server): let the autonomous scheduler pass Android local auth

📊 Changes

4 files changed (+41 additions, -2 deletions)

View changed files

📝 packages/server/src/middleware/android-local-auth.ts (+12 -1)
📝 packages/server/src/services/conversation/server-autonomous-scheduler.service.ts (+4 -0)
📝 scripts/regressions/android-local-auth.regression.ts (+7 -0)
📝 scripts/regressions/autonomous-scheduler-gate.regression.ts (+18 -1)

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Closes #7475

Why this change

  • On Android installs set up by the Marinara app (Termux plus the APK), autonomous Conversation messages never arrived while the user was away. The server log showed [autonomous-scheduler] Eligibility check failed for chat … with status 401 about once a minute.
  • The server-side scheduler asks the server's own routes (/api/conversation/autonomous/check, then /api/generate) through app.inject(). Those requests come from 127.0.0.1. On an APK-managed install, Android local auth deliberately refuses 127.0.0.1 unless the request has the app's session cookie or the install secret, so other apps on the phone can't use the server. The scheduler sent neither, so every check was refused.
  • Messages only appeared when the user came back. Opening the chat made the browser-side checker run, and that one has the session cookie.

What changed

  • Nothing stops working. Manual Termux, desktop, Docker and LAN setups don't set MARINARA_ANDROID_SECRET, so they behave as before.
  • On APK-managed Android installs, the server-side autonomous scheduler now sends the install's local secret on its own eligibility check and generate calls. This is the same header the mari CLI already uses. Characters can check in again while you are away.
  • Local auth itself is unchanged. It accepts no new credential and trusts nothing new, and a bare request from 127.0.0.1 is still refused. The secret goes only into app.inject(), which runs inside the server process, so it never goes over a socket. The generate route does not forward incoming headers to providers.
  • New helper androidLocalAuthInjectHeaders() in packages/server/src/middleware/android-local-auth.ts. It returns {} when the Android secret is unset or invalid.
  • Regressions: autonomous-scheduler-gate now runs the real scheduler with Android local auth on, and its fake inject applies the same check androidLocalAuthHook runs. The existing "every chat gets checked" and "saved message marks unread" assertions therefore also prove that the check and the generate call get through. With the header removed, the test fails with every chat with autonomous messages gets checked in turn. android-local-auth now also checks that a real Fastify inject carrying the helper's headers gets past the real hook.

Separate: empty "New Chat" Conversation chats (not fixed here)

The reporter also saw empty Conversation chats appear on their own. These don't share the 401's cause. The scheduler only reads chats and calls the check and generate routes, and nothing on the server creates an empty Conversation chat. Every client path that creates one is a click: Home's Conversation shortcut, the sidebar +, the omnibar "New conversation", and the connection gate. In English all of them name the chat "New Conversation". The most likely source is Home's Conversation shortcut tile. It looks like a way to go to CONVO, but it creates a new chat and opens the setup wizard, and the empty chat stays if you back out of the wizard. The reporter said they were moving between Home and CONVO, which fits. If maintainers agree, that should be its own issue: either label the tile as "new" or drop a chat that was never set up when the wizard is closed.

Separate: package background refreshes get the same 401 (not fixed here, #7500)

Package routes called through runInternalRoute, such as Noodle's and Slurp's scheduled refreshes, hit the same 401 on APK-managed installs. The cause is the same app.inject() from 127.0.0.1, but the fix is a different design choice: either give the install secret to the package's route, or let local auth accept the package's internal-route token. That is beyond what #7475 asked for, so it is tracked in #7500. This PR does not change package routes.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Commands run by the agent:

  • node ./scripts/run-regressions.mjs --filter scripts/regressions/autonomous-scheduler-gate.regression.ts: passed. With the scheduler's header temporarily removed, it fails with every chat with autonomous messages gets checked in turn.
  • pnpm regression:android-local-auth:run: passed.
  • pnpm check on e46ccb5: passed (exit 0). The only lint output is an existing react-hooks/exhaustive-deps warning in client code this PR doesn't touch.
  • node ./scripts/run-regressions.mjs --filter autonomous (check-storage, individual-cadence, scheduler-gate), --filter multiplayer-autonomy-security, --filter startup-inject-gate and --filter android-local-auth: all passed.
  • Review round on e46ccb5 (no code changes): pnpm check exit 0 again, with the same single existing client warning. --filter autonomous 3/3, multiplayer-autonomy-security 1/1, startup-inject-gate 1/1 and android-local-auth 1/1 all passed. Local CodeRabbit (coderabbit review --agent --committed --base-commit 9fd6e09) did not run: the account's included reviews were used up (rate limit, about 36 minutes to the next one). The GitHub CodeRabbit review of e46ccb5 reported no actionable comments. The reviewer's package-route finding is tracked in #7500.

Manual verification notes

Manual verification needed (requires an APK-managed Termux install):

  • Install this build on Android with the Marinara app. Open a single-character Conversation chat, turn on Autonomous Messages, and leave scheduled messaging off.
  • Press Home to leave the app and keep the server running. For at least 3 minutes, watch the Termux log: no Eligibility check failed … status 401 line should appear.
  • Wait about 25 minutes, then reopen the app. Check that a check-in arrived while you were away and the chat shows it as unread.
  • From a Termux shell, run curl -i -X POST http://127.0.0.1:<port>/api/conversation/autonomous/check -H 'content-type: application/json' -d '{"chatId":"x"}'. It must still return 401, because local auth is not weakened.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

No docs changes: the Conversation guides already say characters can check in while you are away. This fix makes Android behave as they describe. CHANGELOG.md is not edited, per the 2026-10-12 policy.

UI evidence (if applicable)

None. Server-only change.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/7484 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 10/12/2026 **Status:** ✅ Merged **Merged:** 10/12/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/autonomous-scheduler-local-auth` --- ### 📝 Commits (1) - [`e46ccb5`](https://github.com/Pasta-Devs/Marinara-Engine/commit/e46ccb5c46b8ce0d3d4e0e3410852152008c8e54) fix(server): let the autonomous scheduler pass Android local auth ### 📊 Changes **4 files changed** (+41 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/middleware/android-local-auth.ts` (+12 -1) 📝 `packages/server/src/services/conversation/server-autonomous-scheduler.service.ts` (+4 -0) 📝 `scripts/regressions/android-local-auth.regression.ts` (+7 -0) 📝 `scripts/regressions/autonomous-scheduler-gate.regression.ts` (+18 -1) </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. <!-- See CONTRIBUTING.md § Branches. --> ## Linked issue Closes #7475 ## Why this change - On Android installs set up by the Marinara app (Termux plus the APK), autonomous Conversation messages never arrived while the user was away. The server log showed `[autonomous-scheduler] Eligibility check failed for chat … with status 401` about once a minute. - The server-side scheduler asks the server's own routes (`/api/conversation/autonomous/check`, then `/api/generate`) through `app.inject()`. Those requests come from `127.0.0.1`. On an APK-managed install, Android local auth deliberately refuses `127.0.0.1` unless the request has the app's session cookie or the install secret, so other apps on the phone can't use the server. The scheduler sent neither, so every check was refused. - Messages only appeared when the user came back. Opening the chat made the browser-side checker run, and that one has the session cookie. ## What changed - **Nothing stops working.** Manual Termux, desktop, Docker and LAN setups don't set `MARINARA_ANDROID_SECRET`, so they behave as before. - On APK-managed Android installs, the server-side autonomous scheduler now sends the install's local secret on its own eligibility check and generate calls. This is the same header the `mari` CLI already uses. Characters can check in again while you are away. - Local auth itself is unchanged. It accepts no new credential and trusts nothing new, and a bare request from `127.0.0.1` is still refused. The secret goes only into `app.inject()`, which runs inside the server process, so it never goes over a socket. The generate route does not forward incoming headers to providers. - New helper `androidLocalAuthInjectHeaders()` in `packages/server/src/middleware/android-local-auth.ts`. It returns `{}` when the Android secret is unset or invalid. - Regressions: `autonomous-scheduler-gate` now runs the real scheduler with Android local auth on, and its fake `inject` applies the same check `androidLocalAuthHook` runs. The existing "every chat gets checked" and "saved message marks unread" assertions therefore also prove that the check and the generate call get through. With the header removed, the test fails with `every chat with autonomous messages gets checked in turn`. `android-local-auth` now also checks that a real Fastify `inject` carrying the helper's headers gets past the real hook. ### Separate: empty "New Chat" Conversation chats (not fixed here) The reporter also saw empty Conversation chats appear on their own. These don't share the 401's cause. The scheduler only reads chats and calls the check and generate routes, and nothing on the server creates an empty Conversation chat. Every client path that creates one is a click: Home's **Conversation** shortcut, the sidebar **+**, the omnibar "New conversation", and the connection gate. In English all of them name the chat "New Conversation". The most likely source is Home's **Conversation** shortcut tile. It looks like a way to go to CONVO, but it creates a new chat and opens the setup wizard, and the empty chat stays if you back out of the wizard. The reporter said they were moving between Home and CONVO, which fits. If maintainers agree, that should be its own issue: either label the tile as "new" or drop a chat that was never set up when the wizard is closed. ### Separate: package background refreshes get the same 401 (not fixed here, #7500) Package routes called through `runInternalRoute`, such as Noodle's and Slurp's scheduled refreshes, hit the same 401 on APK-managed installs. The cause is the same `app.inject()` from `127.0.0.1`, but the fix is a different design choice: either give the install secret to the package's route, or let local auth accept the package's internal-route token. That is beyond what #7475 asked for, so it is tracked in #7500. This PR does not change package routes. ## Validation - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` Commands run by the agent: - `node ./scripts/run-regressions.mjs --filter scripts/regressions/autonomous-scheduler-gate.regression.ts`: passed. With the scheduler's header temporarily removed, it fails with `every chat with autonomous messages gets checked in turn`. - `pnpm regression:android-local-auth:run`: passed. - `pnpm check` on `e46ccb5`: passed (exit 0). The only lint output is an existing `react-hooks/exhaustive-deps` warning in client code this PR doesn't touch. - `node ./scripts/run-regressions.mjs --filter autonomous` (check-storage, individual-cadence, scheduler-gate), `--filter multiplayer-autonomy-security`, `--filter startup-inject-gate` and `--filter android-local-auth`: all passed. - Review round on `e46ccb5` (no code changes): `pnpm check` exit 0 again, with the same single existing client warning. `--filter autonomous` 3/3, `multiplayer-autonomy-security` 1/1, `startup-inject-gate` 1/1 and `android-local-auth` 1/1 all passed. Local CodeRabbit (`coderabbit review --agent --committed --base-commit 9fd6e09`) did not run: the account's included reviews were used up (rate limit, about 36 minutes to the next one). The GitHub CodeRabbit review of `e46ccb5` reported no actionable comments. The reviewer's package-route finding is tracked in #7500. ### Manual verification notes Manual verification needed (requires an APK-managed Termux install): - [ ] Install this build on Android with the Marinara app. Open a single-character Conversation chat, turn on **Autonomous Messages**, and leave scheduled messaging off. - [ ] Press Home to leave the app and keep the server running. For at least 3 minutes, watch the Termux log: no `Eligibility check failed … status 401` line should appear. - [ ] Wait about 25 minutes, then reopen the app. Check that a check-in arrived while you were away and the chat shows it as unread. - [ ] From a Termux shell, run `curl -i -X POST http://127.0.0.1:<port>/api/conversation/autonomous/check -H 'content-type: application/json' -d '{"chatId":"x"}'`. It must still return 401, because local auth is not weakened. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) No docs changes: the Conversation guides already say characters can check in while you are away. This fix makes Android behave as they describe. `CHANGELOG.md` is not edited, per the 2026-10-12 policy. ## UI evidence (if applicable) None. Server-only change. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-24 04:07:12 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#7754
No description provided.