Skip to content

fix(codex): improve local session import compatibility#995

Open
Himehane wants to merge 1 commit into
tiann:mainfrom
Himehane:fix/import-duplicate-message
Open

fix(codex): improve local session import compatibility#995
Himehane wants to merge 1 commit into
tiann:mainfrom
Himehane:fix/import-duplicate-message

Conversation

@Himehane

@Himehane Himehane commented Jul 7, 2026

Copy link
Copy Markdown

fix(codex): improve local session import compatibility

  • fix duplicated user messages during transcript import
  • fix duplicated assistant messages during transcript import
  • normalize imported messages before deduplication
  • improve compatibility with recent Codex transcript format
  • support session titles from session_index.jsonl
  • preserve fallback behavior for older Codex versions
  • add regression tests for transcript parsing and title resolution

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Findings

  • [Major] Synthetic context filter can drop real imported user prompts — hub/src/web/routes/codexDesktop.ts:296
  • [Major] Adjacent duplicate collapse is not limited to mirrored transcript sources — hub/src/web/routes/codexDesktop.ts:823

Summary

  • Review mode: initial
  • Found two import-parser data-loss risks introduced by the diff. Both affect transcript fidelity during direct Codex import.

Testing

  • Not run (automation); attempted bun test hub/src/web/routes/codexDesktop.test.ts, but bun is not installed in this runner.

HAPI Bot

Comment thread hub/src/web/routes/codexDesktop.ts Outdated
return normalized.startsWith('# AGENTS.md instructions')
|| normalized.includes('<INSTRUCTIONS>')
|| normalized.startsWith('<environment_context>')
|| lower.includes('<environment_context>')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[MAJOR] This now drops any response_item user message that merely contains <environment_context> anywhere in the prompt. response_item is also where real user prompts are imported, so a user asking about or pasting a transcript/XML block with that tag is silently omitted from the imported HAPI session. Keep the filter to standalone injected blocks instead of arbitrary substrings.

Suggested fix:

function shouldIgnoreInjectedResponseUserMessage(text: string): boolean {
    const normalized = text.trim()
    const lower = normalized.toLowerCase()
    const isAgentInstructions = lower.startsWith('# agents.md instructions')
    const isEnvironmentContext = lower.startsWith('<environment_context>')
        && lower.endsWith('</environment_context>')
    return isAgentInstructions || isEnvironmentContext
}

Comment thread hub/src/web/routes/codexDesktop.ts Outdated
continue
}
const previous = entries[entries.length - 1]
if (previous && isAdjacentDuplicateImportedMessage(previous.message, message)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[MAJOR] This duplicate check collapses any adjacent imported user/assistant messages with the same normalized text, even when both came from the same transcript source. That can remove legitimate repeated messages; the mirror bug this PR fixes is specifically an event_msg/response_item duplication, so the drop should require different sources.

Suggested fix:

function isMirroredAdjacentDuplicate(
    previous: CodexImportedMessageEntry | undefined,
    next: CodexImportedMessageEntry
): boolean {
    return Boolean(
        previous
        && previous.source !== next.source
        && isAdjacentDuplicateImportedMessage(previous.message, next.message)
    )
}

// Use isMirroredAdjacentDuplicate(previous, entry) in both adjacent-dedupe branches.

@Himehane Himehane force-pushed the fix/import-duplicate-message branch from 0e2c7be to 899c16c Compare July 7, 2026 11:53

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Findings

  • No issues found.

Questions

  • None.

Summary

  • Review mode: follow-up after new commits
  • Previous HAPI Bot findings from 0e2c7bee2988a57ff640944ce1e6a583e687c8f8 were rechecked against current head 899c16c223334d3d5f1a5e6b29816b29d757d0eb; no current diff findings above 80% confidence.
  • Residual risk: local test automation could not be run in this runner.

Testing

  • Not run (automation); bun --version failed with bun: command not found.
  • git diff --check passed.

HAPI Bot

@Himehane

Himehane commented Jul 7, 2026

Copy link
Copy Markdown
Author

Verified locally.

All tests passed successfully.

  • 134 test files passed
  • 1131 tests passed

Additionally verified the Codex import behavior manually:

  • Duplicate user messages are no longer imported.
  • Duplicate assistant messages are no longer imported.
  • Session titles are correctly loaded from session_index.jsonl.

swear01 pushed a commit to swear01/hapi that referenced this pull request Jul 10, 2026
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