fix(agent): preserve raw Claude session lines#2768
Conversation
This comment has been minimized.
This comment has been minimized.
|
✅ No security or compliance issues detected. Reviewed everything up to 2bfadef. Security Overview
Detected Code Changes
|
|
there is a migration in this but should be non-disruptive |
f15be17 to
2bfadef
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2bfadef7ca
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| def _jsonb_safe_value(value: object) -> object: | ||
| match value: | ||
| case str() as text: | ||
| return text.replace("\x00", "\\u0000") |
There was a problem hiding this comment.
Preserve NUL session bytes for resume
When a Claude JSONL line contains \u0000, _session_line_from_json decodes it to an actual NUL, and this fallback changes it to the six-character string \\u0000 before storing it. AgentSessionService.load_session_history later reconstructs the resume JSONL from entry.content with orjson.dumps(content), so affected sessions resume with a literal backslash-u sequence instead of the original NUL value. For tool outputs or message text containing NULs, persistence now succeeds but the stored session is no longer an exact Claude session line, which undermines the raw-resume fix this change is meant to provide.
Useful? React with 👍 / 👎.
Summary
Tests
uv run pytest tests/unit/test_agent_session_messages.pyuv run ruff check tests/unit/test_agent_session_messages.py tracecat/agent/executor/loopback.py tracecat/agent/session/service.py tracecat/db/models.py alembic/versions/0e4c0a2b7f91_add_raw_agent_session_line.pyuv run ruff format --check tests/unit/test_agent_session_messages.py tracecat/agent/executor/loopback.py tracecat/agent/session/service.py tracecat/db/models.py alembic/versions/0e4c0a2b7f91_add_raw_agent_session_line.pyuv run basedpyright tests/unit/test_agent_session_messages.py tracecat/agent/executor/loopback.py tracecat/agent/session/service.py tracecat/db/models.py alembic/versions/0e4c0a2b7f91_add_raw_agent_session_line.py