Repository navigation
Feat/sqlite conversations - #408
kingsoftheweb wants to merge 22 commits into
Conversation
… bookmarks Signed-off-by: Bashmohandes Mazen <kingsofthewebofficial@gmail.com>
Signed-off-by: Bashmohandes Mazen <kingsofthewebofficial@gmail.com>
Signed-off-by: Bashmohandes Mazen <kingsofthewebofficial@gmail.com>
Signed-off-by: Bashmohandes Mazen <kingsofthewebofficial@gmail.com>
Signed-off-by: Bashmohandes Mazen <kingsofthewebofficial@gmail.com>
There was a problem hiding this comment.
🟡 Changes recommended
Deployment rollback can restart the service after an interrupted import, allowing chat writes to invalidate the saved source manifest and block migration resumption; the service must remain stopped on migration failure.
1 open issue
What changed in this PR
This PR moves conversation storage toward authoritative SQLite, addressing #262’s concerns about large JSONL histories, search, forks, and rewinds. It also renames provider contracts and integrations to harness terminology.
Changes:
- Adds SQLite storage foundations, migration commands, deployment compatibility checks, and offline maintenance support.
- Connects saved-history search, branch operations, and portable history delivery to application services and frontend APIs.
- Updates provider imports, tests, documentation, and release tooling for the harness package layout.
| File | Description |
|---|---|
| vendors/README.md | Updates the version-manifest link. |
| infra/qa/deploy-local.sh | Adds migration and rollback compatibility checks. |
| infra/qa/deploy-app.sh | Adds migration and rollback compatibility checks. |
| frontend/src/ui/chat/ChatThread.tsx | Removes the loaded-history restriction from find UI props. |
| frontend/src/models/chat.ts | Adds history version metadata to sync events. |
| frontend/src/config/routes.ts | Adds the chat search route. |
| frontend/src/app/containers/ChatContainer.tsx | Supplies chat identity to find functionality. |
| frontend/src/api/chatApi.ts | Exposes transcript search. |
| frontend/src/api/chat/chatTranscriptApi.ts | Defines search results and requests. |
| frontend/src/api/chat/chatTranscriptApi.test.ts | Tests saved-history search requests. |
| docs/dev/installable-applications/25-application-agent-runtime.md | Updates the integration package reference. |
| docs/dev/chat-transcript-index/README.md | Marks the disposable-index design as historical. |
| docs/dev/chat-transcript-index/02-read-write-and-recovery.md | Warns against deleting authoritative SQLite storage. |
| docs/dev/chat-transcript-index/01-ownership-and-startup.md | Directs readers to current storage documentation. |
| docs/dev/agents/README.md | Updates the integration package reference. |
| docs/dev/agents/07-adding-an-agent.md | Updates provider implementation links. |
| docs/dev/agents/06-features-and-platform-consumers.md | Updates contract and integration references. |
| docs/dev/agents/05-provisioning-and-updates.md | Updates provisioning and protected-path references. |
| docs/dev/agents/04-authentication-and-access.md | Updates provider authentication paths. |
| docs/dev/agents/03-capabilities-cache-and-refresh.md | Updates capability implementation links. |
| docs/dev/agents/01-module-contract-and-registration.md | Updates harness contract links. |
| docs/01-overview/00-philosophy.md | Updates provisioning and execution references. |
| backend/internal/transport/ws/chat_socket.go | Uses harness interaction types. |
| backend/internal/transport/ws/chat_attribution_test.go | Updates the runner stub’s interaction type. |
| backend/internal/transport/ws/account_permissions_test.go | Uses harness provider identities. |
| backend/internal/transport/http/handlers/chat_handler.go | Adds search handling and validation error mapping. |
| backend/internal/transport/http/handlers/agent_quota_handler.go | Uses harness provider identities. |
| backend/internal/transport/http/handlers/agent_capabilities_handler.go | Uses harness capability types. |
| backend/internal/transport/http/handlers/agent_capabilities_handler_test.go | Updates capability fixtures and assertions. |
| backend/internal/transport/http/handlers/account_permissions_test.go | Updates provider permission fixtures. |
| backend/internal/stores/sqlitechat/transcript_projection_encoding.go | Defines transcript item grouping and UTF-8 truncation. |
| backend/internal/stores/sqlitechat/schema.go | Defines authoritative events, branches, and indexes. |
| backend/internal/stores/sqlitechat/lock.go | Adds exclusive conversation-store ownership. |
| backend/internal/stores/fileauth/store.go | Uses harness identities in authentication persistence. |
| backend/internal/stores/fileauth/store_test.go | Updates authentication persistence tests. |
| backend/internal/stores/fileagentquota/store_test.go | Updates quota persistence fixtures. |
| backend/internal/stores/chatmigration/status.go | Reads migration status without opening the runtime store. |
| backend/internal/service/usersettings/service.go | Uses harness provider normalization. |
| backend/internal/service/usersettings/model.go | Uses harness preference types and validation. |
| backend/internal/service/usage/service.go | Uses harness usage parsing. |
| backend/internal/service/usage/rebuild.go | Uses harness usage normalization. |
| backend/internal/service/skills/service.go | Uses harness identities and provisioning. |
| backend/internal/service/skills/model.go | Aliases skill providers to harness identities. |
| backend/internal/service/services.go | Wires search, branches, and conversation runtime support. |
| backend/internal/service/services_test.go | Updates provider and provisioning stubs. |
| backend/internal/service/runhub/persistence_test.go | Tests cancellation after event persistence failure. |
| backend/internal/service/prompt/run_event_relay.go | Uses harness events in the relay. |
| backend/internal/service/prompt/run_event_relay_test.go | Updates relay fixtures to harness types. |
| backend/internal/service/prompt/run_delivery.go | Tracks input acceptance and persisted run outcomes. |
| backend/internal/service/prompt/notification_summary_test.go | Uses the harness registry. |
| backend/internal/service/prompt/interaction_responses.go | Uses harness interaction response channels. |
| backend/internal/service/prompt/interaction_response_test.go | Updates interaction routing fixtures. |
| backend/internal/service/prompt/audit.go | Uses harness provider identities in audit recording. |
| backend/internal/service/prompt/account_access.go | Uses harness identities in account access contracts. |
| backend/internal/service/project_permission_composition_test.go | Updates project permission test types. |
| backend/internal/service/notifying_repositories.go | Adds branch notifications and history-version forwarding. |
| backend/internal/service/container/profiles/catalog.go | Uses harness provisioning profiles. |
| backend/internal/service/container/profiles/catalog_test.go | Updates profile catalog tests. |
| backend/internal/service/container/lifecycle/service.go | Updates the provisioning import. |
| backend/internal/service/container/lifecycle/service_test.go | Updates lifecycle test imports. |
| backend/internal/service/container/image/recipe.go | Uses harness provisioning in image recipes. |
| backend/internal/service/container/image/recipe_test.go | Updates image recipe test imports. |
| backend/internal/service/container/image/ports.go | Updates provisioning contract imports. |
| backend/internal/service/container/image/builder_test.go | Updates image builder test imports. |
| backend/internal/service/container/credentials/service.go | Uses harness credential provisioning types. |
| backend/internal/service/container/credentials/service_test.go | Updates credential service test imports. |
| backend/internal/service/container/cli/provisioner.go | Uses harness CLI provisioning types. |
| backend/internal/service/container/cli/provisioner_test.go | Updates CLI provisioning test imports. |
| backend/internal/service/container/browser/service_test.go | Updates browser service test imports. |
| backend/internal/service/chat/search.go | Defines validated search and branch-fork contracts. |
| backend/internal/service/chat/ports.go | Clarifies authoritative-event ownership in a comment. |
| backend/internal/service/chat/handoffs_test.go | Tests portable-history assembly and identity boundaries. |
| backend/internal/service/chat/branches.go | Defines rewind, history-version, and idle-mutation contracts. |
| backend/internal/service/chat/account_access.go | Uses harness identities for account checks. |
| backend/internal/service/applications/agent_runtime_process_test.go | Extends timeouts for cold application builds. |
| backend/internal/service/agent/quota/service.go | Uses harness quota contracts. |
| backend/internal/service/agent/quota/refresh.go | Uses harness plan-usage readers. |
| backend/internal/service/agent/quota/readings.go | Uses harness quota types and windows. |
| backend/internal/service/agent/quota/ownership_test.go | Updates quota ownership fixtures. |
| backend/internal/service/agent/quota/model.go | Uses harness quota models. |
| backend/internal/service/agent/hostcli/installer.go | Updates the provisioning import. |
| backend/internal/service/agent/hostcli/installer_test.go | Updates installer test imports. |
| backend/internal/service/agent/capability/flight.go | Uses harness capability results. |
| backend/internal/service/agent/capability/flight_test.go | Updates capability cloning fixtures. |
| backend/internal/service/agent/capability/cache.go | Uses harness capability cache types. |
| backend/internal/service/agent/auth/registry.go | Keys authentication bindings by harness identity. |
| backend/internal/service/agent/auth/registry_test.go | Updates authentication registry fixtures. |
| backend/internal/service/agent/auth/permissions.go | Uses harness identities in account authorization. |
| backend/internal/service/agent/auth/binding.go | Uses harness identities in authentication bindings. |
| backend/internal/service/agent/auth/api_key.go | Updates API-key storage and service contracts. |
| backend/internal/service/agent/auth/api_key_authorizer_test.go | Updates API-key authorization fixtures. |
| backend/internal/service/agent/auth/accounts.go | Uses harness identities in account persistence contracts. |
| backend/internal/service/agent/auth/account_service_test.go | Updates account service test stores. |
| backend/internal/service/agent/accountaccess/service_test.go | Updates provider-scoped authorization tests. |
| backend/internal/service/agent/accountaccess/providers_test.go | Updates provider grant fixtures. |
| backend/internal/rbac/architecture_test.go | Updates permitted integration entrypoint paths. |
| backend/internal/model/conversation/history.go | Defines portable conversation history records. |
| backend/internal/integration/harnesses/runtime/process_test.go | Updates the parser stub to harness events. |
| backend/internal/integration/harnesses/runtime/container_command.go | Uses harness workspace and environment contracts. |
| backend/internal/integration/harnesses/runtime/container_command_test.go | Updates container secret fixtures. |
| backend/internal/integration/harnesses/runtime/capability_command.go | Uses harness capability requests. |
| backend/internal/integration/harnesses/runtime/capability_command_test.go | Tests environment override behavior. |
| backend/internal/integration/harnesses/runtime/account_scope.go | Uses harness events for account attribution. |
| backend/internal/integration/harnesses/minimax/runtime_catalog.go | Uses harness model and provisioning types. |
| backend/internal/integration/harnesses/minimax/runtime_catalog_test.go | Covers catalog generation and model rejection. |
| backend/internal/integration/harnesses/minimax/provider.go | Updates provider contracts and integration imports. |
| backend/internal/integration/harnesses/minimax/profile.go | Uses harness provisioning and shared Codex configuration. |
| backend/internal/integration/harnesses/minimax/profile_test.go | Updates profile test imports. |
| backend/internal/integration/harnesses/minimax/plan_usage_test.go | Uses harness quota windows. |
| backend/internal/integration/harnesses/minimax/model_catalog.go | Uses harness model normalization. |
| backend/internal/integration/harnesses/minimax/history.go | Adds portable-history prompt adaptation. |
| backend/internal/integration/harnesses/minimax/factory.go | Registers the provider using harness contracts. |
| backend/internal/integration/harnesses/minimax/factory_test.go | Updates factory identity assertions. |
| backend/internal/integration/harnesses/minimax/command.go | Uses harness run and preparation types. |
| backend/internal/integration/harnesses/minimax/account_authorizer_test.go | Updates account authorization fixtures. |
| backend/internal/integration/harnesses/kimi/profile.go | Uses harness provisioning contracts. |
| backend/internal/integration/harnesses/kimi/profile_test.go | Updates profile test imports. |
| backend/internal/integration/harnesses/kimi/history.go | Adds history adaptation with an argument-size limit. |
| backend/internal/integration/harnesses/kimi/history_test.go | Tests rejection of oversized history input. |
| backend/internal/integration/harnesses/kimi/history_acceptance_test.go | Tests evidence required for input acceptance. |
| backend/internal/integration/harnesses/kimi/factory.go | Registers Kimi through harness contracts. |
| backend/internal/integration/harnesses/kimi/command.go | Uses harness command and preparation types. |
| backend/internal/integration/harnesses/kimi/command_test.go | Updates command fixtures. |
| backend/internal/integration/harnesses/kimi/capabilities.go | Uses harness capability models. |
| backend/internal/integration/harnesses/kimi/capabilities_test.go | Updates capability assertions. |
| backend/internal/integration/harnesses/codexharness/history_acceptance_test.go | Tests turn-start acceptance correlation. |
| backend/internal/integration/harnesses/codexharness/configuration.go | Updates the provisioning import. |
| backend/internal/integration/harnesses/codexharness/app_server_subagents_test.go | Updates subagent event fixtures. |
| backend/internal/integration/harnesses/codexharness/app_server_protocol.go | Uses harness run modes in protocol parameters. |
| backend/internal/integration/harnesses/codexharness/app_server_process.go | Uses harness provider identities. |
| backend/internal/integration/harnesses/codexharness/app_server_answers_test.go | Updates interaction request and response fixtures. |
| backend/internal/integration/harnesses/codex/provider.go | Uses harness provider and runtime contracts. |
| backend/internal/integration/harnesses/codex/profile.go | Updates shared provisioning imports. |
| backend/internal/integration/harnesses/codex/profile_test.go | Updates profile test imports. |
| backend/internal/integration/harnesses/codex/plan_usage_test.go | Updates plan-usage test types. |
| backend/internal/integration/harnesses/codex/history.go | Adds portable-history prompt adaptation. |
| backend/internal/integration/harnesses/codex/factory.go | Registers Codex through harness contracts. |
| backend/internal/integration/harnesses/codex/credentials.go | Updates the credential provisioning import. |
| backend/internal/integration/harnesses/codex/command.go | Uses harness run and preparation types. |
| backend/internal/integration/harnesses/codex/capability_debug.go | Updates capability request and runtime imports. |
| backend/internal/integration/harnesses/codex/capability_app_server.go | Uses harness capability requests. |
| backend/internal/integration/harnesses/codex/capabilities_test.go | Updates capability mode assertions. |
| backend/internal/integration/harnesses/codex/auth.go | Uses the harness provider identity. |
| backend/internal/integration/harnesses/codex/accounts_test.go | Updates account store test contracts. |
| backend/internal/integration/harnesses/codex/account_run.go | Uses harness run and provisioning types. |
| backend/internal/integration/harnesses/codex/account_authorizer_test.go | Supplies an explicit test authorization stub. |
| backend/internal/integration/harnesses/claude/quota.go | Uses harness quota models and windows. |
| backend/internal/integration/harnesses/claude/profile.go | Uses harness provisioning contracts. |
| backend/internal/integration/harnesses/claude/profile_test.go | Updates profile test imports. |
| backend/internal/integration/harnesses/claude/plan_usage_test.go | Updates plan-usage fixtures and provider lookup. |
| backend/internal/integration/harnesses/claude/history.go | Adds portable-history prompt adaptation. |
| backend/internal/integration/harnesses/claude/factory.go | Registers Claude through harness contracts. |
| backend/internal/integration/harnesses/claude/effort_catalog.go | Uses harness capability options and requests. |
| backend/internal/integration/harnesses/claude/capability_parser.go | Uses harness capability normalization. |
| backend/internal/integration/harnesses/claude/auth.go | Uses the harness provider identity. |
| backend/internal/integration/harnesses/claude/assets/mcp.json | Provides browser MCP configuration in the new layout. |
| backend/internal/integration/harnesses/claude/accounts_test.go | Updates account store test contracts. |
| backend/internal/integration/harnesses/claude/account_run.go | Uses harness account-run dependencies. |
| backend/internal/integration/harnesses/claude/account_authorizer_test.go | Supplies an explicit test authorization stub. |
| backend/internal/integration/harnesses/antigravity/utf8_stream.go | Provides incremental UTF-8 stream decoding. |
| backend/internal/integration/harnesses/antigravity/profile.go | Updates imports and documents tracked-run transport. |
| backend/internal/integration/harnesses/antigravity/print_stream.go | Emits harness events from print output. |
| backend/internal/integration/harnesses/antigravity/parser.go | Uses harness parser requests and events. |
| backend/internal/integration/harnesses/antigravity/history.go | Adds portable-history prompt adaptation. |
| backend/internal/integration/harnesses/antigravity/factory.go | Registers Antigravity through harness contracts. |
| backend/internal/integration/harnesses/antigravity/capabilities.go | Uses harness capability models. |
| backend/internal/integration/harnesses/antigravity/capabilities_test.go | Updates capability mode assertions. |
| backend/internal/integration/containers/workspace/skills.go | Updates the provisioning import. |
| backend/internal/integration/containers/workspace/skills_test.go | Updates workspace skill test imports. |
| backend/internal/integration/containers/workspace/instructions.go | Uses harness instruction provisioning. |
| backend/internal/integration/containers/runtimeassets/adapter.go | Updates runtime-asset provisioning imports. |
| backend/internal/integration/containers/runtimeassets/adapter_test.go | Updates runtime-asset test imports. |
| backend/internal/integration/containers/inspection/credentials.go | Uses harness credential provisioning types. |
| backend/internal/integration/containers/inspection/adapter_test.go | Updates inspection test imports. |
| backend/internal/integration/containers/credentials/synchronizer.go | Updates credential synchronization imports. |
| backend/internal/integration/containers/credentials/synchronizer_test.go | Updates synchronization test imports. |
| backend/internal/integration/containers/credentials/files.go | Uses harness credential file contracts. |
| backend/internal/integration/containers/credentials/directory.go | Uses harness credential directory contracts. |
| backend/internal/integration/containers/browser/install.go | Updates browser provisioning imports. |
| backend/internal/integration/containers/browser/install_test.go | Updates browser installer test imports. |
| backend/internal/integration/containers/browser/browser_test.go | Updates browser integration test imports. |
| backend/internal/harness/usage.go | Renames the usage contract package. |
| backend/internal/harness/usage_test.go | Renames the usage test package. |
| backend/internal/harness/runtime_environment.go | Renames the runtime environment package. |
| backend/internal/harness/runtime_environment_test.go | Renames the environment test package. |
| backend/internal/harness/registry.go | Renames the provider registry package. |
| backend/internal/harness/quota.go | Renames the quota contract package. |
| backend/internal/harness/provisioning/versions.go | Embeds and validates shared version pins. |
| backend/internal/harness/provisioning/instructions.go | Renders embedded workspace instructions. |
| backend/internal/harness/provisioning/instructions_test.go | Tests hostname substitution. |
| backend/internal/harness/provisioning/default_skills_test.go | Tests packaged skills and defensive copies. |
| backend/internal/harness/provisioning/assets/skills/remote-application/agents/openai.yaml | Supplies application-skill interface metadata. |
| backend/internal/harness/project.go | Moves project contracts to the harness package. |
| backend/internal/harness/preference_value.go | Renames the preference validation package. |
| backend/internal/harness/parser.go | Renames the parser contract package. |
| backend/internal/harness/model.go | Adds input-acceptance tracking to run requests. |
| backend/internal/harness/identity.go | Renames the provider identity package. |
| backend/internal/harness/identity_test.go | Renames the identity test package. |
| backend/internal/harness/history.go | Defines history adaptation and acceptance evidence. |
| backend/internal/harness/history_test.go | Tests history preservation and prompt separation. |
| backend/internal/harness/execution_policy.go | Renames the execution policy package. |
| backend/internal/harness/capability_model.go | Renames the capability model package. |
| backend/internal/harness/capabilities.go | Renames the capability helper package. |
| backend/internal/harness/capabilities_test.go | Renames the capability test package. |
| backend/internal/config/containers.go | Uses harness provisioning configuration. |
| backend/internal/config/constants/chat.go | Removes the obsolete startup warmup limit. |
| backend/internal/config/agents.go | Imports providers from the harness integration layout. |
| backend/cmd/usage-rebuild/main.go | Rebuilds usage from migration-ready SQLite storage. |
| backend/cmd/upgrade-workspaces/stores.go | Opens only stores needed for workspace maintenance. |
| backend/cmd/upgrade-workspaces/stores_test.go | Tests maintenance isolation from conversation storage. |
| backend/cmd/upgrade-workspaces/main.go | Uses the dedicated workspace store set. |
| backend/cmd/remote/main.go | Closes stores and removes index warmup startup wiring. |
| backend/cmd/remote/cli.go | Adds storage inspection and migration commands. |
| backend/cmd/remote/chat_migration.go | Reports migration progress without conversation content. |
| backend/cmd/remote/chat_index_warmup.go | Removes obsolete index warmup code. |
| .github/workflows/vendor-playwright.yml | Watches the relocated version manifest. |
| .github/scripts/classify-release.sh | Protects relocated harness infrastructure paths. |
| .github/scripts/classify-release-test.sh | Updates protected-path test fixtures. |
| .design-sync/NOTES.md | Updates the documented capability fixture path. |
Review effort: Balanced
| mv -f "$candidate_binary" "$binary" | ||
| if ! remote_migrate_conversations "$binary" "$install_dir/data" "$service_name"; then | ||
| rollback |
Why: keep UTF-8 text accumulation independent of SQLite batch and checkpoint ownership. Checks: SQLite, import, prompt, chat, runhub, and setuprepair focused tests passed on QA; SQL and JSON literal comparisons passed. Signed-off-by: Bashmohandes Mazen <kingsofthewebofficial@gmail.com>
Why: give durable backups, schema verification, legacy discovery, and streamed imports distinct owners while keeping upgrade orchestration explicit. Checks: SQLite schema and legacy import tests passed on QA; moved bodies, partial results, SQL, and error ordering compared against the baseline. Signed-off-by: Bashmohandes Mazen <kingsofthewebofficial@gmail.com>
Why: keep page limits, grouped-item materialization, content authorization, and collaboration preview cursors independently readable. Checks: focused SQLite paging, content, branch, and concurrency tests passed on QA; SQL, JSON, lineage, and cursor boundaries independently compared with baseline. Signed-off-by: Bashmohandes Mazen <kingsofthewebofficial@gmail.com>
Why: separate one provider invocation from prompt preparation and missing-session retry without a mutable closure capture. Checks: prompt, account, setuprepair, chat, and runhub behavior tests passed on QA; request fields, callbacks, error joins, and defer ordering compared against baseline. Signed-off-by: Bashmohandes Mazen <kingsofthewebofficial@gmail.com>
Signed-off-by: Bashmohandes Mazen <kingsofthewebofficial@gmail.com>
Why: use one harness vocabulary and place neutral runtime contracts with the service that owns them; keep provider implementations in integration/harnesses. Checks: focused harness, integration, config, service, transport and RBAC tests passed on QA; release/install/deployment scripts passed; lexical/import/resource audit found no behavior changes or cycles. Full suites and vet continue on isolated QA source. Signed-off-by: Bashmohandes Mazen <kingsofthewebofficial@gmail.com>
Replace misleading projection names with transcript readers and remove the unused filechat store, legacy progress UI, and obsolete guides. Preserve useful storage contracts against SQLite and correct current architecture and migration documentation. Checks: full backend and catalog tests/vet, 648 frontend tests and build, 24 installer tests, deploy/QA script tests, structural comparison and source review. Signed-off-by: Bashmohandes Mazen <kingsofthewebofficial@gmail.com>
Preserve exact native history boundaries and account-home scope while replaying only the retained suffix. Keep source sessions intact and recover fresh only before input acceptance. Hide checkpoint bookkeeping from event replay. Checks: SQLite, migration, prompt, runhub, Claude, Codex, MiniMax and protocol suites passed; Mermaid flows rendered. Full backend, race and build checks are continuing in isolated QA validation.
Ahmedwaleed22
left a comment
There was a problem hiding this comment.
Problem
In chat search needs better handling, we still need to load messages to be able to search..
Proposed Solution
Let the backend endpoint search the full chat and find the message and show a list of found messages then clicking on it loads chunks around it with ability to load more





Abstract
This PR introduces SQLite to replace our remotes global events.jsonl and it fixes #262
This will help with three major problems:
1- Optimizing the loading of conversations through the unified UI
2- "Proper" switching between different harnesses in the same convo.
3- Introducing "Proper" search in the conversations/projects
The biggest challenge was managing the switch between different harnesses in one convo, which could be explained by the following:
Hence, Switching from one harness to another is not really straightforward.
This was solved by introducing a global store layer holding "benchmarks" that points to the start of each new harness.
Remote then handles delivery of the "missing" conversation partials from one harness to another, during switching.
*We do pass the data with a flag given to the agent, that this was generated by another agent.
Storage model
The database holds conversations across projects, with reads scoped by project, chat, and branch. The core model uses three tables:
chats— metadata, active branch, and current native-session mappings/bookmarks.branches— parent relationships, retained-history boundaries, and append/search progress.events— authoritative ordered events with indexed turn and display-item fields.Example for passing from one harness to another
Layers touched
Locations are relative to the repository root. Change types describe this PR's remaining changes compared with
qa.backend/internal/model/conversation/backend/internal/service/chat/,backend/internal/service/prompt/,backend/internal/service/runhub/backend/internal/service/harness/history.go;backend/internal/service/harness/model.gobackend/internal/integration/harnesses/backend/internal/stores/sqlitechat/backend/internal/stores/filechat/backend/internal/stores/chatmigration/,backend/cmd/remote/chat_migration.gobackend/internal/config/constants/chat.go;backend/internal/stores/stores.go;backend/internal/service/services.gobackend/internal/transport/http/handlers/chat_handler.gofrontend/src/api/chat/;frontend/src/api/chatApi.ts;frontend/src/state/hooks/chat/;frontend/src/ui/chat/;frontend/src/models/chat.ts;frontend/src/config/routes.ts;frontend/src/app/containers/ChatContainer.tsxbackend/cmd/remote/;backend/cmd/upgrade-workspaces/;backend/cmd/usage-rebuild/;infra/lib/chat-migration.sh;infra/deploy-app.sh;infra/qa/;infra/steps/04-backend-svc.shfrontend/src/api/chat/chatTranscriptApi.test.ts;infra/tests/chat-migration-test.sh;infra/qa/verify-conversation-migration.pydocs/dev/conversation-storage.md;ARCHITECTURE.md;docs/02-user-guide/;docs/02-workspaces/;docs/03-platform/;docs/dev/agents/docs/dev/chat-transcript-index/Flows
These diagrams describe the SQLite implementation. Remote SQLite is the shared conversation record. Native storage belongs to each harness and contains its own sessions and internal state. History transfers carry portable conversation records from SQLite; Remote does not translate or rewrite one harness's private session files into another harness's format.
1. One harness per conversation
The first prompt starts a native session. Subsequent prompts resume that session when it is safe to do so. After an ordinary successful run, its bookmark is at the saved conversation tail, so the next prompt usually needs no additional historical context.
sequenceDiagram autonumber actor U as User / UI participant R as Remote services participant D as Remote SQLite participant H as Harness adapter / runtime participant N as Harness native storage U->>R: Submit prompt with harness and account R->>D: Read active branch, session ID, and bookmark D-->>R: Safe resume ID or fresh-session decision R->>D: Capture prior-history boundary and mark run pending D-->>R: Required portable history before this prompt R->>D: Append current user prompt D-->>R: Commit succeeds R-->>U: Broadcast saved user message R->>R: Compose historical context plus current prompt R->>D: Record input delivery method R->>H: Start or resume with composed input alt Safe session exists H->>N: Load and continue native session else First run or unsafe session H->>N: Create fresh native session end Note over H,N: Harness owns native writes, compaction, and summarization H-->>R: Input acceptance evidence and native session ID R->>D: Record acceptance without advancing bookmark loop Assistant output, tool activity, and completion H-->>R: Provider event R->>D: Append normalized event and applicable metadata D-->>R: Commit succeeds R-->>U: Broadcast saved event end H-->>R: Run returns alt Accepted, completed successfully, and all events saved R->>D: Mark session ready, advance bookmark, and save native checkpoint when available else Failed, cancelled, or uncertain R->>D: Mark session unsafe without advancing safe bookmark end R-->>U: Run becomes idleIf a stored resume ID is no longer available, Remote retries with a fresh session and the full retained history. It reuses the boundary captured before the current prompt, avoiding duplicate delivery of that prompt as history. Other failures leave saved partial output in SQLite; the next attempt uses a fresh session. If event persistence fails, Remote stops the run, reports the save failure, and does not broadcast the unsaved event or advance the bookmark.
2. Switching harnesses in one conversation
Assume harness A has completed a run. The user now sends a prompt through harness B, then later switches back to A. Each harness/account has an independent session mapping and bookmark on this branch.
sequenceDiagram autonumber actor U as User / UI participant R as Remote services participant D as Remote SQLite participant A as Harness A and native storage participant B as Harness B and native storage Note over D,A: A has a safe session and bookmark from its previous run U->>R: Select B and submit a prompt R->>D: Inspect B mapping, capture current tail, and mark B pending alt B has a safe resumable session D-->>R: B session ID and history after B bookmark else B is new or unsafe D-->>R: Fresh-session decision and full retained history end R->>D: Save current user prompt D-->>R: Commit succeeds R-->>U: Broadcast saved user message R->>R: Label history with original harness/account attribution R->>D: Record B delivery method R->>B: Resume or start fresh with history plus current prompt Note over A,B: A native files remain untouched while B owns its own session lifecycle B-->>R: Input acceptance evidence and B session ID R->>D: Record B acceptance loop B output, tools, and completion B-->>R: Provider event R->>D: Commit event with B attribution R-->>U: Broadcast after commit end B-->>R: Successful run returns R->>D: Mark B ready, advance B bookmark, and save B native checkpoint Note over D,A: A bookmark remains at the end of A's earlier run R-->>U: B run becomes idle U->>R: Switch back to A and submit next prompt R->>D: Inspect A mapping, capture new tail, and mark A pending D-->>R: A resume ID plus history after A bookmark Note over R,D: This includes the intervening B conversation R->>D: Save next user prompt D-->>R: Commit succeeds R-->>U: Broadcast saved user message R->>D: Record A delivery method R->>A: Resume A with missing history plus current prompt A-->>R: Input acceptance evidence R->>D: Record A acceptance loop A output, tools, and completion A-->>R: Provider event R->>D: Commit event with A attribution R-->>U: Broadcast after commit end A-->>R: Successful run returns R->>D: Mark A ready, advance A bookmark, and save A native checkpoint R-->>U: A run becomes idleThe return to A above assumes its session is still safe and available. Otherwise, A starts fresh with the full retained history. Switching accounts follows the same rule because mappings are keyed by both harness and account. Neither switch deletes the other harness's native files or transfers its private reasoning or compaction state. Failure and cancellation follow the same recovery rules as the single-harness flow.
3. Rewinding to an earlier prompt
Rewind retains the conversation before the selected user prompt, excluding that prompt and all subsequent events from the active history. The UI can stop an active run and wait for it to finish before rewinding; the backend rejects rewind while the run is still active.
flowchart TD A["User chooses an earlier prompt to rewind"] --> B{"Run active?"} B -->|Yes| C["Cancel and wait until backend is idle"] B -->|No| D["Apply rewind under the idle-run lock"] C --> D D --> E["SQLite: create child branch retaining the prefix before the selected prompt"] E --> F["Make branch active for the same chat; clear current session mappings; commit"] F -.-> G["Old SQLite events and native source sessions remain intact"] F --> H["UI reloads retained history; user submits edited or new prompt"] H --> I["Find selected harness/account's latest successful checkpoint in retained branch lineage"] I --> J["Capture pre-prompt cutoff, mark run pending, and save current prompt"] J --> K{"Supported safe checkpoint?"} K -->|Yes| L["Harness creates a native fork at the exact checkpoint; keep source account-home scope"] L --> M{"Boundary usable and verified before input?"} M -->|Yes| N["Deliver only retained suffix after checkpoint plus current prompt"] M -->|Unavailable| O["Start fresh with full retained history plus current prompt"] K -->|No| O N --> P["Harness owns new native state; Remote records acceptance and saves output before broadcasting"] O --> P P --> Q{"Accepted and completed with all events saved?"} Q -->|Yes| R["Save new session mapping, advance bookmark, and record native checkpoint"] Q -->|No| S["Leave mapping unsafe; next attempt starts fresh"] R --> T["Run becomes idle"] S --> TThe cutoff is implemented as the sequence prefix before the first saved event at or after the requested timestamp. Transcript reads, expanded content, search, and future handoffs all respect it. A saved native checkpoint is eligible only if its successful completion remains within that prefix.
For Claude, Remote requests
--resume <source> --fork-session --resume-session-at=<assistant UUID>. Codex and MiniMax usethread/forkwithlastTurnId, then verify the fork's latest completed turn beforeturn/start. Rewind therefore continues in a new native branch, preserving the original native session. If the selected point falls between native checkpoints or includes another harness's messages, Remote adds only the retained suffix after the chosen checkpoint as historical context.If there is no safe native checkpoint, or the native operation is unavailable before input starts, Remote reconstructs the retained history in a fresh session. Failed or interrupted execution is not automatically replayed in the same attempt. Workspace files and prior tool effects are unchanged.
4. Forking and continuing independently
Fork creates a new chat whose branch references the source's saved history at a fixed cutoff. The current UI/API forks at the current saved tail. To branch from an earlier prompt while preserving the original conversation, fork first, then rewind the fork before sending the new prompt.
flowchart TD A["User forks the conversation"] --> B["SQLite: capture source branch and its current saved tail"] B --> C["Create new chat and branch referencing that prefix; initialize empty session mappings; commit"] C -.-> D["Source chat, native session, and ongoing run remain unchanged"] C -.-> E["Events are shared by reference; later source output is outside the fork cutoff"] C --> F["UI opens new chat; optionally rewind it before submitting a prompt"] F --> G["Find selected harness/account's latest successful retained native checkpoint"] G --> H["Capture pre-prompt cutoff, mark run pending, and save current prompt in fork"] H --> I{"Supported safe checkpoint?"} I -->|Yes| J["Create native fork at exact checkpoint in its original account-home scope"] J --> K{"Boundary usable and verified before input?"} K -->|Yes| L["Send retained suffix after checkpoint plus current prompt to new native session"] K -->|Unavailable| M["Start fresh with full retained history plus current prompt"] I -->|No| M L --> N["Save acceptance and output on fork branch before broadcasting"] M --> N N --> O{"Accepted and completed with all events saved?"} O -->|Yes| P["Save fork session mapping, advance bookmark, and record native checkpoint"] O -->|No| Q["Leave fork mapping unsafe; next attempt starts fresh"] P --> R["Run becomes idle"] Q --> RNative branching is deferred until the fork's first prompt, so the selected harness/account determines which retained checkpoint to use. The new native session ID is saved for later resumes, together with the original native account-home scope. This lets a new Remote chat find its inherited native storage without confusing its UI/run identity with the source chat.
Forking during an active source run captures events committed at the transaction boundary; it does not wait for completion or include later output. A prior successful native checkpoint can still be used, with the retained suffix supplied as context. Later source execution cannot move the fork's requested native boundary.
For both operations, storage ownership is: