Skip to content

refactor(storage): consolidate external session source parsing #3625

Description

@Astro-Han

Problem

Maka has two user-facing paths over the same Codex and Claude session stores:

  • ForeignSession creates a filtered, untrusted handoff for the current task.
  • ExternalSession imports a full typed transcript as a new Maka Session.

Their outputs should remain different, but each path currently implements its own discovery, source identity, title and cwd selection, bounded reading, and source-specific parsing. The implementations have already drifted: Codex paths use different presentation records, while Claude handoff does not share the lineage resolution used by full import.

Desired outcome

Use one package-private source catalog and native parser per external source, followed by two explicit projections: safe handoff and full Session import.

The consolidation should:

  • select the same source ID, transcript candidate, title, and cwd under the same query policy;
  • use one Codex record authority and one Claude lineage resolver before projection;
  • preserve the handoff security boundary, redaction, and hostile-data envelope;
  • preserve typed full history, externalOrigin, atomic persistence, and replay;
  • cover Codex v0.144 and v0.149, Claude rewind and compaction, duplicate IDs, malformed records, and tool call/result pairing with shared fixtures; and
  • strictly reduce production code and duplicated tests without adding another facade, compatibility bridge, or generic ExternalMessage model.

Coordinate with #1512 and #3520. Preserve #1512's staleness and hostile-path requirements, and reuse #3520's v0.149 fixture and record-selection fix.

Alternatives or workarounds

Keeping the parsers independent preserves the current duplication and allows source interpretation to drift further. Deriving safe handoff from imported StoredMessage[] would also weaken the explicit trust boundary, so the two projections should remain separate after shared source resolution.

AI-assisted analysis: Codex agents traced both consumers, their security boundaries, related pull requests, and checked-in fixtures. A human contributor must review the final design and implementation.

Activity

  1. CxHsin commented on Aug 23, 2026

    @CxHsin
    Contributor

    Hi, I would like to take #3625.

    I reviewed the current ForeignSession handoff and ExternalSession import paths. They independently perform source discovery, transcript selection, metadata extraction, bounded reading, and source-specific parsing, which has already caused their Codex and Claude behavior to diverge.

    My proposed approach is:

    1. Base the work on the latest main, while coordinating with feat(core,storage,cli): evidence pointers and staleness flags for foreign session handoff #1512 and fix(storage): import Codex item_completed messages #3520.
    2. Introduce one package-private source catalog so both paths resolve the same source id, transcript candidate, title, cwd, and query policy.
    3. Keep one native parser per external source:
      • Codex: preserve the event_msg presentation authority and response_item tool authority, including the v0.149 item_completed cases from fix(storage): import Codex item_completed messages #3520.
      • Claude: share lineage resolution for rewinds, compaction boundaries, duplicate records, and malformed records.
    4. Keep the two projections explicit and separate:
      • safe handoff with redaction, hostile-data envelope, tool-output exclusion, staleness checks, and bounded reads;
      • full Maka Session import with typed history, tool call/result pairing, externalOrigin, atomic persistence, and replay.
    5. Add shared fixtures and parity tests, then remove the duplicated production code and tests.

    I will not introduce a generic ExternalMessage model or derive the handoff from imported StoredMessage[], since that would weaken the handoff trust boundary.

    One design point I would like to confirm before implementation is how the shared Claude parser should handle lineage when the handoff is restricted to a bounded tail window. If this direction looks reasonable, I can start with the catalog/parity-test seam and submit the work incrementally.

  2. Astro-Han commented on Aug 23, 2026

    @Astro-Han
    ContributorAuthor

    Assigned! btw the Codex session import failed because codex changed their session structure. Make sure to test the Codex session import route! @CxHsin

  3. added a commit that references this issue on Aug 24, 2026
    a9508a6
  4. added theissue type on Aug 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions