Skip to content

fix: refresh stale staging clients and keep Termux awake - #4958

Merged
SpicyMarinara merged 4 commits into
stagingfrom
agent/assigned-issues-4956-4957
Aug 12, 2026
Merged

SpicyMarinara merged 4 commits into
stagingfrom
agent/assigned-issues-4956-4957

Conversation

@SpicyMarinara

@SpicyMarinara SpicyMarinara commented Aug 12, 2026 •

Copy link
Copy Markdown
Collaborator

Linked issues

Closes #4957
Closes #4956

Why this change

NovelAI default parameters already survive the current save, navigation, and import paths, but staging commits keep the same release version. A browser still running an older same-version bundle therefore could not detect that the server had moved to a newer commit and could keep exhibiting the pre-fix behavior.

Android may also suspend a backgrounded Termux process unless its wake lock is active, which makes the local Marinara server appear frozen until Termux is foregrounded again.

What changed

  • Embed the client build commit and compare it with /api/health so same-version staging updates clear stale browser runtime caches and reload once.
  • Preserve version-only compatibility for servers that do not expose build metadata.
  • Acquire a Termux wake lock immediately before starting the server and release it on launcher exit.
  • Add browser regressions covering NovelAI defaults after Save/persona navigation and connection JSON import.
  • Add focused runtime-build and launcher contract regressions.
  • Document both user-facing fixes under CHANGELOG.md Unreleased.

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

Automated evidence

  • pnpm check
  • bash -n start-termux.sh
  • pnpm --filter @marinara-engine/server exec tsx ../../scripts/regressions/assigned-issue-sweep.regression.ts
  • node scripts/regressions/launcher-format-guard.regression.mjs
  • pnpm exec playwright test -c playwright.config.ts e2e/core-flows.e2e.ts --project=desktop-chromium --grep 'NovelAI generation defaults survive' (2 passed)
  • Production build inspection confirmed the client bundle and server build metadata contain the same 12-character commit.

Manual verification still required

  • Manually verify a browser left open across two same-version staging commits reloads to the new build without looping.
  • Manually verify NovelAI settings persist after Save, persona navigation, reopening, export, and import in LibreWolf.
  • Manually verify a Termux-hosted client remains responsive while Android backgrounds Termux, and that stopping the launcher releases the wake lock.

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] <paths> follow-up issue opened
  • Version/release files updated

No user-facing documentation page changed; CHANGELOG.md contains the release-note entries. No version metadata changed.

Summary by CodeRabbit

  • Bug Fixes

    • Same-version browser clients now refresh when the server build changes, reducing stale-session issues.
    • Termux-hosted servers keep Android awake while running and release the wake lock cleanly on shutdown.
    • Servers without build metadata remain compatible with version recovery.
  • Tests

    • Added coverage for NovelAI seed persistence and imported connection defaults.
    • Added regression checks for build mismatch handling and Termux wake-lock behavior.

@github-actions github-actions Bot added the bugfix Bug fix label Aug 12, 2026
@coderabbitai

coderabbitai Bot commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: f528a44f-7c9c-441e-bad5-107d9fedb37e

📥 Commits

Reviewing files that changed from the base of the PR and between 33eb03b and 7c0e2a3.

📒 Files selected for processing (1)
  • e2e/core-flows.e2e.ts

📝 Walkthrough

Walkthrough

The changes add build-aware client refresh checks, Termux Android wake-lock management, and desktop end-to-end tests for NovelAI seed persistence. The changelog documents the refresh and wake-lock behavior.

Changes

Runtime build compatibility

Layer / File(s) Summary
Build metadata resolution
packages/client/src/build-env.d.ts, packages/client/src/lib/runtime-build.ts, packages/client/vite.config.ts
The client receives a normalized build commit from environment variables or Git. Runtime helpers format and compare build identifiers.
Health compatibility and recovery
packages/client/src/App.tsx, scripts/regressions/assigned-issue-sweep.regression.ts
Health responses accept an optional build value. Recovery detects differing same-version builds and preserves version-only compatibility when build metadata is absent. Regression assertions cover these cases.

Termux wake-lock lifecycle

Layer / File(s) Summary
Wake-lock acquisition and cleanup
start-termux.sh, scripts/regressions/launcher-format-guard.regression.mjs, CHANGELOG.md
The launcher acquires and releases an Android wake lock when supported. It runs Node without exec so cleanup traps execute. Source guards and changelog entries cover the lifecycle.

NovelAI persistence validation

Layer / File(s) Summary
NovelAI connection persistence tests
e2e/core-flows.e2e.ts
Desktop-only end-to-end tests verify saved seed values across navigation and imported connection defaults.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

Suggested labels: android

Suggested reviewers: thetopham

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the two primary changes: stale staging client refresh and Termux wake-lock support.
Description check ✅ Passed The description includes linked issues, rationale, changes, automated validation, remaining manual checks, and release impact.
Linked Issues check ✅ Passed The changes address NovelAI persistence coverage and stale-client recovery [#4957], plus Termux background responsiveness through wake-lock management [#4956].
Out of Scope Changes check ✅ Passed The changelog, regression tests, runtime-build logic, and launcher changes directly support the objectives in [#4957] and [#4956].
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch agent/assigned-issues-4956-4957

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@SpicyMarinara SpicyMarinara changed the title fix: resolve NovelAI persistence and Termux responsiveness regressions fix: refresh stale staging clients and keep Termux awake Aug 12, 2026
@SpicyMarinara SpicyMarinara self-assigned this Aug 12, 2026
@SpicyMarinara
SpicyMarinara marked this pull request as ready for review August 12, 2026 18:04

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@e2e/core-flows.e2e.ts`:
- Around line 2006-2018: Extend the test after locating importedConnectionId to
open that imported connection in the connection editor, then assert the NovelAI
Seed spinbutton displays value 73. Keep the existing API defaultParameters
assertion and use the editor’s accessible spinbutton query to verify hydration
into the UI.
- Around line 1887-1902: Move the connection and persona creation requests
inside the existing try block in the test flow, and declare nullable
connection/persona IDs before it. Assign each ID only after its POST succeeds,
then update the finally cleanup to delete whichever created IDs are non-null so
partial setup failures cannot leave records behind.

In `@packages/client/vite.config.ts`:
- Around line 21-24: Update the environment commit selection in
normalizeBuildCommit so blank or whitespace-only higher-priority variables are
skipped before choosing a fallback. Evaluate MARINARA_GIT_COMMIT, GITHUB_SHA,
and BUILD_COMMIT in priority order, selecting the first nonblank value and
preserving the existing normalization and return behavior.

In `@scripts/regressions/launcher-format-guard.regression.mjs`:
- Around line 73-85: Update the wake-lock ordering assertion around
termuxLauncherSource to locate the actual acquisition command, matching the “if
termux-wake-lock ...” invocation rather than the availability-check token.
Compare that match’s position with the lastIndexOf("node dist/index.js") so the
regression fails when acquisition occurs after server startup; preserve the
existing presence and release checks.

In `@start-termux.sh`:
- Around line 563-577: Update the Termux wake-lock setup so trap
release_termux_wake_lock is registered before invoking termux-wake-lock. Keep
TERMUX_WAKE_LOCK_ACQUIRED initialized to 0 so the EXIT trap does not attempt an
unlock when acquisition fails, and set it to 1 only after successful
acquisition.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 8750f0aa-59d4-4a8f-9a0e-b29ec5b58ede

📥 Commits

Reviewing files that changed from the base of the PR and between 906651f and 62612ab.

📒 Files selected for processing (9)
  • CHANGELOG.md
  • e2e/core-flows.e2e.ts
  • packages/client/src/App.tsx
  • packages/client/src/build-env.d.ts
  • packages/client/src/lib/runtime-build.ts
  • packages/client/vite.config.ts
  • scripts/regressions/assigned-issue-sweep.regression.ts
  • scripts/regressions/launcher-format-guard.regression.mjs
  • start-termux.sh

Comment thread e2e/core-flows.e2e.ts Outdated
Comment thread e2e/core-flows.e2e.ts
Comment thread packages/client/vite.config.ts Outdated
Comment thread scripts/regressions/launcher-format-guard.regression.mjs
Comment thread start-termux.sh Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@e2e/core-flows.e2e.ts`:
- Line 1925: Add export-path coverage in the test around the connection fetch:
export the saved connection before cleanup and assert that the exported
defaultParameters.imageGeneration.seed equals 50, while preserving the existing
storage and editor hydration assertions.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: dda0b492-559d-4bd9-9969-6ab13043504d

📥 Commits

Reviewing files that changed from the base of the PR and between 62612ab and 33eb03b.

📒 Files selected for processing (4)
  • e2e/core-flows.e2e.ts
  • packages/client/vite.config.ts
  • scripts/regressions/launcher-format-guard.regression.mjs
  • start-termux.sh

Comment thread e2e/core-flows.e2e.ts
@SpicyMarinara
SpicyMarinara merged commit 0f9abe4 into staging Aug 12, 2026
9 checks passed
@SpicyMarinara
SpicyMarinara deleted the agent/assigned-issues-4956-4957 branch August 12, 2026 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant