Skip to content

fix: classify OpenAI developer messages as system context - #18

Merged
royalpinto007 merged 1 commit into
AgentPostmortem:mainfrom
Gambit-Checkmate:fix/classify-developer-context
Sep 14, 2026
Merged

royalpinto007 merged 1 commit into
AgentPostmortem:mainfrom
Gambit-Checkmate:fix/classify-developer-context

Conversation

@Gambit-Checkmate

Copy link
Copy Markdown
Contributor

What & why

Closes #10.

OpenAI chat messages with the developer role currently fall through to the user segment, overstating user context and understating system instructions. Classify them with system instructions while preserving the original role, content, and turn.

Changes

  • Recognize developer alongside the other OpenAI roles during format detection.
  • Emit developer messages in Segment.SYSTEM.
  • Add regression coverage for bare arrays and wrapped message objects, including developer-only detection and developer instructions appearing after an assistant turn.
  • Document the classification in the parser docstring and changelog.

Validation

  • Added the regression tests first: all 4 new cases failed before the parser change.
  • python -X utf8 -m pytest: 61 passed, both with .[dev] and with .[dev,tiktoken] installed (Python 3.12 on Windows).
  • ruff check .: passed.
  • ruff format --check src/ctxlens/parsers/openai_chat.py tests/test_parsers.py: passed.
  • git diff --check: passed.

The UTF-8 flag is needed on this Windows host because the existing HTML-output test calls read_text() without an encoding; with the host's default GBK encoding, that test raises a decoding error. No unrelated encoding behavior was changed.

AI assistance was used to implement and validate this change.

Checklist

  • Focused change with a clear description
  • Ran format / lint / tests (see README)
  • Updated docs or CHANGELOG if relevant
  • Linked any related issue (e.g. Closes #123)

@royalpinto007
royalpinto007 merged commit dae9665 into AgentPostmortem:main Sep 14, 2026
3 checks passed
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.

OpenAI developer-role messages misclassified as user

2 participants