Skip to content

perf(session): reduce startup and historical session overhead#760

Open
limityan wants to merge 2 commits into
GCWing:mainfrom
limityan:yanzhn/web-ui-startup-m3
Open

perf(session): reduce startup and historical session overhead#760
limityan wants to merge 2 commits into
GCWing:mainfrom
limityan:yanzhn/web-ui-startup-m3

Conversation

@limityan
Copy link
Copy Markdown
Collaborator

@limityan limityan commented May 17, 2026

Summary

  • Adds a lightweight historical-session restore path so first opening an existing session can paint persisted chat turns without eagerly restoring the full runtime context.
  • Keeps compatibility fallbacks for older desktop/remote endpoints: restore_session_view falls back to restore_session_with_turns, then to the legacy restore_session + load_session_turns sequence; get_configs falls back to per-key get_config.
  • Reduces normal dialog-turn save overhead by updating session metadata incrementally, with a per-session metadata update lock and full-scan fallback for inconsistent storage.
  • Defers snapshot refresh work while historical session data is metadata-only/hydrating or backend context restore is still pending, and dedupes several startup/background initialization paths.

Behavior

  • Historical session open now prioritizes visible UI readiness: persisted turns are loaded and rendered first, and backend coordinator context is restored before the next action that requires it.
  • Visible tool result payloads are preserved for UI/history display; assistant-only tool result text is trimmed from the session-view response to reduce first-load payload size.
  • First-turn sessions that cannot restore backend metadata still keep the old recreate fallback, while multi-turn historical sessions continue to fail loudly instead of silently losing context.
  • Remote scenarios keep passing connection/workspace context through the service APIs, and unsupported restore-command caching is scoped by remote identity so an older remote endpoint does not disable the optimized path for local or newer endpoints in the same runtime.

Performance Benefits

  • Startup AI config reload is batched from multiple IPC calls into one get_configs call on supported builds.
  • First historical-session open avoids duplicate turn loading and eager runtime snapshot restoration on the common path.
  • Dialog-turn save metadata refresh changes from scanning all turn files to reading only the current turn's previous persisted file on the normal path.
  • Snapshot refresh avoids cold-start contention while a historical chat is not ready or still has pending backend context restore.
  • Startup/session diagnostics are thresholded or capped; session response size estimation is bounded at 2MB to avoid tracing itself becoming a hot-path cost on very large sessions.

Risks / Watch Points

  • The deferred historical-session context state adds a pending-restore transition; if multi-turn context restoration fails, sending or context-dependent actions still surface an error rather than silently creating a partial session.
  • Incremental metadata updates rely on serialized per-session metadata writes; tests cover concurrent updates, and storage inconsistency still falls back to a full metadata scan.
  • New diagnostics are thresholded/debug-oriented, but debug sessions should still watch log volume around very large sessions.
  • Mixed old/new desktop or remote endpoints rely on fallback paths, so the compatibility behavior should be kept covered while these endpoints roll forward.

Independent Audit Adjustments

  • Reduced frontend session response trace estimation from 32MB to 2MB to avoid adding measurable first-open CPU work for ultra-long sessions.
  • Extended snapshot refresh gating to contextRestoreState=pending, avoiding snapshot manager initialization while historical context is intentionally deferred.
  • Scoped unsupported restore-command memoization by remote identity to avoid an old remote endpoint degrading local/newer endpoints in the same app runtime.

Verification

  • git diff --check upstream/main..HEAD
  • rustfmt --edition 2021 --check src/crates/core/src/agentic/persistence/manager.rs
  • pnpm run type-check:web
  • pnpm run lint:web
  • pnpm exec vitest run src/flow_chat/services/flow-chat-manager/SessionModule.test.ts
  • pnpm exec vitest run src/infrastructure/api/service-api/ApiClient.test.ts src/tools/snapshot_system/hooks/snapshotRefreshPolicy.test.ts src/flow_chat/store/FlowChatStore.test.ts
  • pnpm exec vitest run --maxWorkers=1
  • cargo test -p bitfun-core save_dialog_turn_updates_metadata_without_scanning_unrelated_turn_files -- --nocapture
  • cargo test -p bitfun-core concurrent_dialog_turn_saves_keep_metadata_counts_consistent -- --nocapture
  • cargo check -p bitfun-desktop

Load historical session views with smaller UI payloads, defer stale snapshot refreshes until session history is ready, and aggregate startup/session diagnostics without logging normal optional-config misses.

Also keeps remote workspace identity in the measured paths so startup and session hydration traces stay actionable without adding extra frontend/backend round trips.
@limityan limityan force-pushed the yanzhn/web-ui-startup-m3 branch from a746a00 to cf7cb08 Compare May 17, 2026 08:34
Batch startup config reads with legacy fallbacks to reduce cold-start IPC overhead.

Update dialog-turn metadata incrementally on the normal save path while serializing per-session metadata writes and retaining full-scan fallback for inconsistent storage.

Defer snapshot refresh work while historical session context restore is pending, bound session response trace estimation, and preserve compatibility fallbacks across mixed remote identities.
@limityan limityan force-pushed the yanzhn/web-ui-startup-m3 branch from cf7cb08 to 199b176 Compare May 17, 2026 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant