fix: strip chatgpt transcript tags from agent messages#735
fix: strip chatgpt transcript tags from agent messages#735ousamabenyounes wants to merge 2 commits into
Conversation
Greptile SummaryThis PR strips ChatGPT-style transcript tags before messages are appended to the SDK session. The main changes are:
Confidence Score: 4/5The changed message conversion path needs a fix before merging.
strix/core/agents.py Important Files Changed
Prompt To Fix All With AIFix the following 2 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 2
strix/core/agents.py:268-271
**User Prompts Lose Literal Tags**
When a user sends text through the CLI, TUI, or resume instruction path, this line strips `<user>`, `<final>`, `<analysis>`, and the other transcript tags before the sender check. A prompt that asks the agent to inspect XML/HTML or preserve a snippet containing those literal tags is changed before it reaches the SDK session, so the model receives different input than the user provided.
```suggestion
sender = str(message.get("from", "unknown"))
content = str(message.get("content", ""))
if sender == "user":
return cast("TResponseInputItem", {"role": "user", "content": content})
content = _strip_chatgpt_transcript_tags(content)
```
### Issue 2 of 2
strix/core/agents.py:31-34
**Attributed Transcript Tags Survive**
This pattern only removes bare tags such as `<final>` and `</final>`. If an agent message contains the same transcript tags with attributes or self-closing syntax, such as `<final reason="done">` or `<analysis/>`, those tags stay in the session item and can still be resent to an OpenAI-compatible provider that rejects transcript markup.
```suggestion
_CHATGPT_TRANSCRIPT_TAG_RE = re.compile(
rf"</?(?:{'|'.join(_CHATGPT_TRANSCRIPT_TAGS)})(?:\s+[^>]*)?\s*/?>",
flags=re.IGNORECASE,
)
```
Reviews (1): Last reviewed commit: "fix: strip chatgpt transcript tags from ..." | Re-trigger Greptile |
|
Addressed the two Greptile review comments in a23be85.
Verification: Revert proof: with the production fix reverted and the new tests kept, the targeted file fails with 2 failed / 1 passed. |
44e87ca to
daf39a2
Compare
Preserve literal transcript-like tags in user prompts. Strip attributed and self-closing transcript tags from non-user session messages. RED->GREEN: new regression tests fail with the production fix reverted, then pass with 3 passed. Full suite: 145 passed, 2 warnings.
e3d40d8 to
79de7c4
Compare
|
Rebased this branch onto current Verification after rebase: The two full-suite failures are the existing |
Summary
Fix #118
Strip ChatGPT-style transcript tags from messages before appending them to the SDK session, so agent-originated content cannot be resent to OpenAI-compatible providers with rejected tags like
<analysis>,<channel>, or<final>.Follow-up review fixes:
<final reason="done">and<analysis/>from non-user messages.Also annotates the descendant task list in the same module so the touched file passes pyright.
Test verification (RED -> GREEN)
RED with the follow-up production fix reverted, while keeping the new regression tests:
GREEN with the follow-up fix applied:
Full suite:
Additional targeted validation:
Global quality baseline notes, not introduced by this PR: