Skip to content

fix(migrate): import legacy .jsonl sessions alongside .events.jsonl#4221

Closed
heshuimu wants to merge 2 commits into
esengine:main-v2from
heshuimu:fix/import-legacy-jsonl-sessions
Closed

fix(migrate): import legacy .jsonl sessions alongside .events.jsonl#4221
heshuimu wants to merge 2 commits into
esengine:main-v2from
heshuimu:fix/import-legacy-jsonl-sessions

Conversation

@heshuimu

@heshuimu heshuimu commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

The v0.x session migration only processed *.events.jsonl files. .jsonl-only sessions (ACP, desktop, subagent — later TS versions wrote directly in message format) were silently skipped.

Changes:

  • Pass 1 (events): prefer .jsonl sidecar when newer than event log
  • Pass 2 (.jsonl-only): import .jsonl files without events counterpart; skip subagent; .bak recovery
  • Pass 3 (subdirectories): recurse into project-scoped subdirs
  • transformAndCopyJsonl: flatten legacy nested-function tool calls to flat format. This heals the Desktop version displaying the session history where all the tool call names and input from legacy version are lost due to format differences.
  • Desktop: topic migration handles both global and project dirs, runs for all tabs
  • CLI: resolveCLISessionDir uses project dir so /resume shows project history

Tests: 9 new migration tests; all 13 original unchanged. Desktop + CLI tests pass.
Testing is also done against my own data from the legacy TypeScript version.

The only unavoidable defect of the current approach is that ACP-related legacy sessions have no workspace specified in its metadata, so they have to be lumped into the global session.

This aims to resolve #4156 which #3944 did not fully address.
This may have overlaps with #4215 as my change also migrates the subagent sessions of legacy version into the designated directory.

The v0.x import only processed *.events.jsonl files, silently skipping
.jsonl sessions that the TS version later wrote in native message format
(ACP, desktop, subagent, and later-version chat sessions).

- Pass 1 (events): prefer .jsonl sidecar when it's newer than the event log
- Pass 2 (.jsonl-only): import message-format .jsonl files without events
  counterpart, with .jsonl.bak recovery. Subagent sessions are skipped.
- Pass 3 (subdirectories): recurse into project-scoped subdirs
- transformAndCopyJsonl: flatten legacy nested-function tool calls to the
  flat name/arguments format the Go version expects
- Desktop: topic migration now handles both global and project session dirs,
  assigning correct scope. Runs for all tabs.
- CLI: resolveCLISessionDir uses the project session dir when cwd maps to
  a project, so /resume shows project history.

9 new tests; all 13 original migration tests unchanged.
@github-actions github-actions Bot added v2 Go rewrite (1.x) — main-v2 branch, active development desktop Wails desktop app (desktop/**) tui Terminal UI / CLI (internal/cli, internal/control) agent Core agent loop (internal/agent, internal/control) labels Jun 12, 2026
@esengine

Copy link
Copy Markdown
Owner

Thanks for this — the three-pass approach (events / .jsonl-only / subdirs) plus the nested-function tool-call flattening is exactly what the .jsonl-only sessions needed, and testing it against your own legacy data is appreciated.

I picked up two follow-ups in #4260 so it lands cleanly and reaches everyone it should:

  • The early return in migrateLegacySessions bailed on the routed marker before the new v3-jsonl marker was checked, so users whose events pass already completed in a prior version (routed marker already stamped) never ran Pass 2/3 — the very upgraders the new marker was meant to serve. Gated the return on both markers; Pass 1 is idempotent via its dest checks. Added a regression test for that path.
  • Dropped the unused copyFile — golangci-lint's unused linter would have failed CI on it.

#4260 builds on your commit with credit and closes this one. Nicely done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent Core agent loop (internal/agent, internal/control) desktop Wails desktop app (desktop/**) tui Terminal UI / CLI (internal/cli, internal/control) v2 Go rewrite (1.x) — main-v2 branch, active development

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: 无法将0.53.0聊天记录迁移至1.6.0 Cannot migrate chat history from 0.53.0 to 1.6.0

3 participants