[PR #6564] [MERGED] fix(storage): prevent agent history joins from stalling the server #7229

Closed
opened 2026-10-23 04:17:43 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/6564
Author: @SpicyMarinara
Created: 9/23/2026
Status: ✅ Merged
Merged: 9/23/2026
Merged by: @SpicyMarinara

Base: staging ← Head: codex/6562-agent-join-stall


📝 Commits (2)

  • 0e4297c docs: record agent history stall fix for #6562
  • 4ba242b fix(storage): index agent history joins instead of scanning every row pair

📊 Changes

3 files changed (+273 additions, -2 deletions)

View changed files

📝 CHANGELOG.md (+2 -0)
📝 packages/server/src/db/file-backed-store.ts (+62 -2)
➕ scripts/regressions/store-join-index.regression.ts (+209 -0)

📄 Description

Linked issue

Closes #6562

Why this change

With many chats loaded, retrieving an agent's previous output compared every resident agent run with every resident message on the server's main thread. The reporter observed minutes-long stalls that also blocked health and abort requests. The same 5,000-run / 20,000-message query took 19,563 ms locally before this fix and 13 ms afterward.

What changed

  • Adapt @luma-inibitor's proposed equality-join lookup. Build the joined table's lookup once and evaluate the full condition only on matching candidates.
  • Preserve duplicate matches, insertion order, sorting/pagination, and existing condition semantics. Non-equality, OR-only, and repeated-table joins retain the scan path.
  • Add a regression spanning 20 chats, including the actual previous-output storage method and its chat, agent, chronology, and active-swipe filters.

The fix is in the shared storage query path used by all six Engine joins. No schema, migration, persistent index, dependency, or UI changes. Original contribution is credited in the commit.

Validation

Completed on head 4ba242b41aff: all 38 current GitHub checks and CodeRabbit passed, including the full Node suite and desktop/mobile browser matrix.

  • pnpm install and pnpm check passed.
  • New join regression passed; the original performance fixture fails before the production fix (19,563 ms vs the 5,000 ms ceiling).
  • Real /api/generate route with a local mock provider, 20,000 messages and 5,000 runs across 20 chats: agent received the correct previous output; generation finished in 310 ms; all 11 simultaneous health requests succeeded, maximum 62 ms. This measures local routing/query work, not external model latency.
  • Production container built and ran; /api/health returned ok and the matching commit. The first build was interrupted by local disk exhaustion; it completed after removing disposable build artifacts/cache.
  • Local and hosted CodeRabbit reviews completed with zero actionable findings.
  • The first WebKit 1/4 run timed out near the end of the mocked Advanced Memory UI scenario while taking screenshots (65 seconds across 11 captures). Its interrupted cleanup left a duplicate fixture character and caused the following picker assertion to fail. Both scenarios passed twice locally on unchanged code (4/4); the affected hosted shard passed unchanged on retry (104 passed, 26 skipped).
  • Hosted platform checks passed. The Intel Mac startup fixture initially timed out while importing server modules (18,856 ms before app construction); rerunning only that job on the unchanged commit passed.
  • Full local Node regression lane: 357/359 passed on the first run. Its decision-sidecar preflight test assumes a supported Linux runtime and reports unsupported on this macOS host; that code and test are unchanged. The unrelated CLI readback test failed once while parsing generated IDs and passed unchanged on a targeted retry. Hosted Linux Node regressions passed all 359/359 files, including these tests and the new join regression (20 ms for the multi-chat query).

Human checklist (left unchecked):

  • 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

Manual verification notes

Manually verify on the reporter's Termux device that agent generation remains responsive after opening many chats. The original device and private chat data were not available; the reported query and data scale were reproduced with synthetic data. No UI changed.

Docs and release impact

Changelog entry added. No configuration, release-version, storage-format, or translated-guide changes.


🔄 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/6564 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 9/23/2026 **Status:** ✅ Merged **Merged:** 9/23/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `codex/6562-agent-join-stall` --- ### 📝 Commits (2) - [`0e4297c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/0e4297c487a6d9c30e05e7513fb9733614bf9265) docs: record agent history stall fix for #6562 - [`4ba242b`](https://github.com/Pasta-Devs/Marinara-Engine/commit/4ba242b41aff6b36e600d985bc5df0b6c69e17f8) fix(storage): index agent history joins instead of scanning every row pair ### 📊 Changes **3 files changed** (+273 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+2 -0) 📝 `packages/server/src/db/file-backed-store.ts` (+62 -2) ➕ `scripts/regressions/store-join-index.regression.ts` (+209 -0) </details> ### 📄 Description ## Linked issue Closes #6562 ## Why this change With many chats loaded, retrieving an agent's previous output compared every resident agent run with every resident message on the server's main thread. The reporter observed minutes-long stalls that also blocked health and abort requests. The same 5,000-run / 20,000-message query took 19,563 ms locally before this fix and 13 ms afterward. ## What changed - Adapt @luma-inibitor's [proposed equality-join lookup](https://github.com/luma-inibitor/Marinara-Engine/commit/c8623720f). Build the joined table's lookup once and evaluate the full condition only on matching candidates. - Preserve duplicate matches, insertion order, sorting/pagination, and existing condition semantics. Non-equality, OR-only, and repeated-table joins retain the scan path. - Add a regression spanning 20 chats, including the actual previous-output storage method and its chat, agent, chronology, and active-swipe filters. The fix is in the shared storage query path used by all six Engine joins. No schema, migration, persistent index, dependency, or UI changes. Original contribution is credited in the commit. ## Validation Completed on head `4ba242b41aff`: all 38 current GitHub checks and CodeRabbit passed, including the full Node suite and desktop/mobile browser matrix. - `pnpm install` and `pnpm check` passed. - New join regression passed; the original performance fixture fails before the production fix (19,563 ms vs the 5,000 ms ceiling). - Real `/api/generate` route with a local mock provider, 20,000 messages and 5,000 runs across 20 chats: agent received the correct previous output; generation finished in 310 ms; all 11 simultaneous health requests succeeded, maximum 62 ms. This measures local routing/query work, not external model latency. - Production container built and ran; `/api/health` returned `ok` and the matching commit. The first build was interrupted by local disk exhaustion; it completed after removing disposable build artifacts/cache. - Local and hosted CodeRabbit reviews completed with zero actionable findings. - The first WebKit 1/4 run timed out near the end of the mocked Advanced Memory UI scenario while taking screenshots (65 seconds across 11 captures). Its interrupted cleanup left a duplicate fixture character and caused the following picker assertion to fail. Both scenarios passed twice locally on unchanged code (4/4); the affected hosted shard passed unchanged on retry (104 passed, 26 skipped). - Hosted platform checks passed. The Intel Mac startup fixture initially timed out while importing server modules (18,856 ms before app construction); rerunning only that job on the unchanged commit passed. - Full local Node regression lane: 357/359 passed on the first run. Its decision-sidecar preflight test assumes a supported Linux runtime and reports `unsupported` on this macOS host; that code and test are unchanged. The unrelated CLI readback test failed once while parsing generated IDs and passed unchanged on a targeted retry. Hosted Linux Node regressions passed all 359/359 files, including these tests and the new join regression (20 ms for the multi-chat query). Human checklist (left unchecked): - [ ] `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` ### Manual verification notes Manually verify on the reporter's Termux device that agent generation remains responsive after opening many chats. The original device and private chat data were not available; the reported query and data scale were reproduced with synthetic data. No UI changed. ## Docs and release impact Changelog entry added. No configuration, release-version, storage-format, or translated-guide changes. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:17:43 +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#7229
No description provided.