Skip to content

Unify state persistence across orchestrator and controllers #9206

@tomivirkki

Description

@tomivirkki

Summary

Persisting an AI session and restoring it later (e.g. on the user's next login) requires the developer to coordinate two unrelated APIs:

  • AIOrchestrator.getHistory() and AIOrchestrator.Builder.withHistory(history, attachments) — for chat history and attachments.
  • ChartAIController.getState() / restoreState(ChartState) and GridAIController.getState() / restoreState(GridState) — for the visible chart/grid state.

To save a session a developer has to:

  1. Read the chat history from the orchestrator.
  2. Read the state from each controller separately.
  3. Persist all of them.

To restore on a later session, the dance reverses: pass withHistory(...) to the orchestrator builder, and call restoreState(...) on each controller individually. State-change wiring (addStateChangeListener) is also per-controller, so a "save everything when something changes" workflow has to fan out across N hooks.

Why it's worth addressing

  • Discoverability. A developer looking at AIOrchestrator doesn't see that controllers also carry persistable state. It's easy to ship a "we persist the chat" implementation and forget the chart/grid state entirely.
  • Coordination. The orchestrator already knows about its registered controllers. Keeping them as separate persistence surfaces pushes coordination work to every consumer.

Proposal

Discuss extending AIController with state capabilities (e.g. opaque getState() / restoreState(...) typed via the interface) and surfacing the aggregate through the orchestrator — for example:

  • AIOrchestrator.getSessionState() returning a snapshot that bundles chat history + per-controller state.
  • A corresponding Builder.withSessionState(...) (or equivalent restore method) that pushes the bundle back into the orchestrator and its controllers.

The per-controller state APIs can stay as escape hatches, but the orchestrator becomes the one place you go for "save and reload the session."

Metadata

Metadata

Assignees

No one assigned

    Labels

    refactorInternal improvement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions