[GH-ISSUE #1576] [Feature]: Lazy-load the background autonomous generation pipeline outside the startup chunk #814

Closed
opened 2026-10-21 05:21:27 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @Xelvanis on GitHub (May 29, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/1576

What problem does this solve?

The AppShell-level background autonomous poller currently imports generation/runtime modules at startup even though background generation only runs after the poller finds an eligible inactive conversation chat.

src/features/modes/conversation/hooks/autonomous/use-background-autonomous.ts imports these at module load:

  • startGeneration from src/engine/generation/start-generation.ts
  • autonomous chat services from src/engine/modes/chat/autonomous/autonomous.service.ts
  • llmApi, storageApi, and integrationGateway
  • catalog/chat query helpers via broad barrels

Rollup metadata for the startup entry includes generation modules such as start-generation.ts, prompt-assembly.ts, agent-runner.ts, agent-executor.ts, and game prompt helpers. That keeps the main entry large before any background autonomous generation is actually needed.

Proposed behavior

Keep the polling hook small at startup and dynamically import a focused background autonomous runtime only when generation is about to run.

The startup hook should be able to:

  • schedule and cancel polling;
  • inspect the minimal chat metadata needed to decide whether a background generation may be needed;
  • lazy-load the generation runner only after an eligible inactive conversation passes the preflight checks.

The lazy runtime can own startGeneration, provider/runtime adapters, prompt assembly, notification side effects, and query invalidation after generation completes.

Expected owner or impact area

  • App shell, navigation, startup, or providers
  • Catalog resources: chats, characters, personas, lorebooks, presets, connections, agents, gallery, or knowledge
  • Chat mode
  • Roleplay mode
  • Game mode
  • Shared mode UI
  • Runtime systems: generation, world-state, visuals, tracker, or haptics
  • Professor Mari or shell tools
  • React-free engine behavior, contracts, agents, or capability ports
  • Shared API wrapper or remote runtime routing
  • Tauri/Rust storage, assets, LLM, integrations, security, imports, or HTTP runtime
  • Docs, contributor workflow, or templates

Refactor branch considerations

Keep engine code React-free. UI code should pass the existing storage/LLM/integration ports or shared API wrappers into the lazy runtime rather than importing Tauri or remote-runtime internals directly.

Acceptance checks:

  • pnpm build passes.
  • The startup entry no longer includes src/engine/generation/start-generation.ts, src/engine/generation/prompt-assembly.ts, or src/engine/agents-runtime/executor/agent-executor.ts solely because the background autonomous poller is mounted.
  • Background autonomous messages still generate for inactive eligible conversation chats.
  • Notification sound, unread badge, floating avatar notification, browser notification, toast, and query invalidation still behave as before after a successful background generation.
  • Failure paths remain best-effort without fake success or silent contract changes.

Alternatives considered

Disabling the poller or moving all autonomous logic out of AppShell would reduce startup size but risks changing product behavior. The goal is to keep behavior and defer only the heavy generation runtime.

Additional context

This is one implementation slice under #1532.

Template check

Please uncheck the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @Xelvanis on GitHub (May 29, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/1576 ## What problem does this solve? The AppShell-level background autonomous poller currently imports generation/runtime modules at startup even though background generation only runs after the poller finds an eligible inactive conversation chat. `src/features/modes/conversation/hooks/autonomous/use-background-autonomous.ts` imports these at module load: - `startGeneration` from `src/engine/generation/start-generation.ts` - autonomous chat services from `src/engine/modes/chat/autonomous/autonomous.service.ts` - `llmApi`, `storageApi`, and `integrationGateway` - catalog/chat query helpers via broad barrels Rollup metadata for the startup entry includes generation modules such as `start-generation.ts`, `prompt-assembly.ts`, `agent-runner.ts`, `agent-executor.ts`, and game prompt helpers. That keeps the main entry large before any background autonomous generation is actually needed. ## Proposed behavior Keep the polling hook small at startup and dynamically import a focused background autonomous runtime only when generation is about to run. The startup hook should be able to: - schedule and cancel polling; - inspect the minimal chat metadata needed to decide whether a background generation may be needed; - lazy-load the generation runner only after an eligible inactive conversation passes the preflight checks. The lazy runtime can own `startGeneration`, provider/runtime adapters, prompt assembly, notification side effects, and query invalidation after generation completes. ## Expected owner or impact area - [x] App shell, navigation, startup, or providers - [ ] Catalog resources: chats, characters, personas, lorebooks, presets, connections, agents, gallery, or knowledge - [x] Chat mode - [ ] Roleplay mode - [ ] Game mode - [ ] Shared mode UI - [x] Runtime systems: generation, world-state, visuals, tracker, or haptics - [ ] Professor Mari or shell tools - [x] React-free engine behavior, contracts, agents, or capability ports - [x] Shared API wrapper or remote runtime routing - [ ] Tauri/Rust storage, assets, LLM, integrations, security, imports, or HTTP runtime - [ ] Docs, contributor workflow, or templates ## Refactor branch considerations Keep engine code React-free. UI code should pass the existing storage/LLM/integration ports or shared API wrappers into the lazy runtime rather than importing Tauri or remote-runtime internals directly. Acceptance checks: - `pnpm build` passes. - The startup entry no longer includes `src/engine/generation/start-generation.ts`, `src/engine/generation/prompt-assembly.ts`, or `src/engine/agents-runtime/executor/agent-executor.ts` solely because the background autonomous poller is mounted. - Background autonomous messages still generate for inactive eligible conversation chats. - Notification sound, unread badge, floating avatar notification, browser notification, toast, and query invalidation still behave as before after a successful background generation. - Failure paths remain best-effort without fake success or silent contract changes. ## Alternatives considered Disabling the poller or moving all autonomous logic out of AppShell would reduce startup size but risks changing product behavior. The goal is to keep behavior and defer only the heavy generation runtime. ## Additional context This is one implementation slice under #1532. ## Template check Please uncheck the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
Author
Owner

@cha1latte commented on GitHub (May 29, 2026):

Triage note: labeling this as normal-scope because it lazy-loads autonomous generation only after the background poller finds eligible work, preserving behavior while reducing startup cost.

A good next step is to implement behind the existing background-autonomous entrypoints and verify idle startup no longer imports generation.

<!-- gh-comment-id:4578272620 --> @cha1latte commented on GitHub (May 29, 2026): Triage note: labeling this as `normal-scope` because it lazy-loads autonomous generation only after the background poller finds eligible work, preserving behavior while reducing startup cost. A good next step is to implement behind the existing background-autonomous entrypoints and verify idle startup no longer imports generation.
Author
Owner

@cha1latte commented on GitHub (May 31, 2026):

Completed by #1711; background autonomous generation now lazy-loads startGeneration only when an eligible inactive conversation triggers

<!-- gh-comment-id:4587988867 --> @cha1latte commented on GitHub (May 31, 2026): Completed by #1711; background autonomous generation now lazy-loads startGeneration only when an eligible inactive conversation triggers
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#814
No description provided.