Skip to content

feat(observability): add conversation archive backend - #653

Merged
Soju06 merged 11 commits into
Soju06:mainfrom
Komzpa:split/519-archive-backend
May 17, 2026
Merged

Soju06 merged 11 commits into
Soju06:mainfrom
Komzpa:split/519-archive-backend

Conversation

@Komzpa

@Komzpa Komzpa commented May 15, 2026

Copy link
Copy Markdown
Collaborator

Draft split from #519.

Purpose:

  • backend archive capture/storage/API for upstream conversation inspection.

Validation:

  • rebased on current main
  • ruff format/check on backend archive/test files
  • pytest tests/unit/test_conversation_archive.py tests/unit/test_proxy_utils.py -k "archive or conversation" (17 passed, 225 deselected)

Relationship:

@Komzpa

Komzpa commented May 15, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e07f4b90d1

ℹ️ 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".

Comment thread app/modules/conversation_archive/api.py Resolved
Comment thread app/core/conversation_archive.py Resolved
@Komzpa
Komzpa marked this pull request as ready for review May 15, 2026 17:03

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e07f4b90d1

ℹ️ 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".

Comment thread app/core/conversation_archive.py Resolved
@Komzpa

Komzpa commented May 16, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@Komzpa

Komzpa commented May 16, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 25b5b01849

ℹ️ 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".

Comment on lines +106 to +110
requested_at_utc = requested_at.astimezone(UTC)
hourly_stem = requested_at_utc.strftime("%Y-%m-%dT%H")
daily_stem = requested_at_utc.strftime("%Y-%m-%d")
candidates = [
directory / f"{hourly_stem}{_GZIP_JSONL_SUFFIX}",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Search more than one hour when filtering by requestedAt

_archive_paths_for_lookup narrows requested_at queries to exactly one hourly filename (plus optional daily legacy files), but archive writes are rotated by current hour. A single request can span an hour boundary, so records emitted after the rollover go into the next file and are silently omitted from /records?requestId=...&requestedAt=..., producing incomplete conversation timelines for long streams.

Useful? React with 👍 / 👎.

@Komzpa Komzpa added the 🤖 codex: needs work [@codex review] raised an issue label May 16, 2026
@Komzpa Komzpa removed the 🤖 codex: needs work [@codex review] raised an issue label May 16, 2026
@Komzpa

Komzpa commented May 16, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1c309f8029

ℹ️ 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".

total = 0
end = offset + limit

for path in sorted(paths, key=lambda item: item.name, reverse=True):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Return records in chronological file order

Iterating paths in reverse filename order makes request-scoped results non-chronological when a single request spans multiple archive files (for example across an hour boundary), because newer-file events are emitted before older-file request payload/events. This breaks conversation replay semantics and can mislead operators in the archive viewer by showing completion/error events before the initiating request.

Useful? React with 👍 / 👎.

@Komzpa Komzpa added the 🤖 codex: needs work [@codex review] raised an issue label May 16, 2026
@Komzpa Komzpa removed the 🤖 codex: needs work [@codex review] raised an issue label May 16, 2026
@Komzpa

Komzpa commented May 16, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: eea790a975

ℹ️ 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".

Comment on lines +131 to +134
payload={
"encoding": "base64",
"data": base64.b64encode(data).decode("ascii"),
},

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Guard binary archiving behind enabled check

archive_bytes() base64-encodes every websocket binary frame before archive_json() checks whether archiving is enabled. Because CODEX_LB_CONVERSATION_ARCHIVE_ENABLED defaults to false, this adds avoidable CPU and memory overhead to normal production traffic (large binary frames are fully copied and encoded even though nothing is written). Add a fast archive_enabled() guard in archive_bytes() (or before building the payload) so disabled mode is truly no-op.

Useful? React with 👍 / 👎.

@Komzpa Komzpa added the 🤖 codex: needs work [@codex review] raised an issue label May 16, 2026
@Komzpa Komzpa removed the 🤖 codex: needs work [@codex review] raised an issue label May 16, 2026
@Komzpa

Komzpa commented May 16, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3c754b4fc4

ℹ️ 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".

Comment thread app/core/conversation_archive.py Outdated
Comment on lines +38 to +39
_WRITE_QUEUE_MAX_RECORDS = 4096
_WRITE_QUEUE: queue.Queue[tuple[Path, dict[str, Any]] | None] = queue.Queue(maxsize=_WRITE_QUEUE_MAX_RECORDS)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Limit archive backlog by bytes, not only record count

The archive buffer is capped at 4096 records, but each record can contain full upstream payloads/events (including large SSE or websocket frames), so the queue can accumulate tens of GB before backpressure kicks in. Under bursty traffic this can exhaust worker memory and crash the process before _enqueue_record falls back to synchronous writes. Please bound the queue by total bytes (or drastically lower the record cap) so memory usage remains predictably bounded.

Useful? React with 👍 / 👎.

@Komzpa Komzpa added the 🤖 codex: needs work [@codex review] raised an issue label May 16, 2026
@Komzpa Komzpa removed the 🤖 codex: needs work [@codex review] raised an issue label May 16, 2026
@Komzpa

Komzpa commented May 16, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

1 similar comment
@Komzpa

Komzpa commented May 16, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d31fc7d968

ℹ️ 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".

Comment on lines +95 to +96
has_more=end < total,
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Expand requestedAt lookup beyond ±1 hour

When requestedAt is provided, lookup is hard-limited to requestedAt-1h, requestedAt, and requestedAt+1h. Any request whose archived events span beyond that window (for example long-running streams) will return an incomplete record set even though matching request_id entries exist in later hourly files. This makes request-detail inspection silently miss data for exactly the sessions that tend to need debugging most.

Useful? React with 👍 / 👎.

Comment on lines +97 to +108


def _archive_paths_for_lookup(*, filename: str | None, requested_at: datetime | None) -> list[Path]:
if filename:
return [_resolve_archive_file(filename)]
directory = _archive_dir()
if requested_at is None:
return list(_iter_archive_paths(directory))

requested_at_utc = requested_at.astimezone(UTC)
hourly_stems = [(requested_at_utc + timedelta(hours=delta)).strftime("%Y-%m-%dT%H") for delta in (-1, 0, 1)]
daily_stem = requested_at_utc.strftime("%Y-%m-%d")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Include adjacent legacy daily files in requestedAt search

The requested-at optimization only adds the daily file for the same UTC date, but legacy archives are day-bucketed. For requests near midnight (or long sessions crossing midnight), matching legacy records can be split across the previous/next day's .jsonl file and will be omitted from results when requestedAt is used, producing partial archive views.

Useful? React with 👍 / 👎.

@Komzpa Komzpa added the 🤖 codex: needs work [@codex review] raised an issue label May 16, 2026
@Komzpa Komzpa removed the 🤖 codex: needs work [@codex review] raised an issue label May 16, 2026
@Komzpa

Komzpa commented May 16, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 869ef216d7

ℹ️ 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".

Comment thread app/core/conversation_archive.py Outdated
Comment on lines +184 to +186
_ensure_writer_thread()
try:
_WRITE_QUEUE.put_nowait((path, record, queued_bytes))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Isolate archive queue failures from request handling

_enqueue_record executes directly on the proxy request path, but it calls _ensure_writer_thread() and put_nowait() without a broad failure guard. If thread startup or queue operations raise runtime errors (for example, thread creation failing under process thread limits), the exception bubbles through archive_json and can fail the active proxy/websocket request even though archiving is optional observability. This should degrade to dropping/logging archive records rather than surfacing a 5xx to clients.

Useful? React with 👍 / 👎.

@Komzpa Komzpa added the 🤖 codex: needs work [@codex review] raised an issue label May 16, 2026
@Komzpa Komzpa removed the 🤖 codex: needs work [@codex review] raised an issue label May 16, 2026
@Komzpa

Komzpa commented May 16, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5b8d4a14ce

ℹ️ 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".

Comment on lines +241 to +243
path.parent.mkdir(parents=True, exist_ok=True)
_recover_corrupt_gzip_archive(path)
_write_gzip_member(path, data)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Restrict archive file permissions to operator-only access

The archive writer creates directories and files using default filesystem modes (mkdir(..., exist_ok=True) and open("ab")) without tightening permissions, so on common umasks (for example 022) archives become world-readable (0755 dirs / 0644 files). Since these records store full request/response payloads, any other local user on the host can read sensitive conversation content unless operators manually harden umask. Please set explicit restrictive modes (e.g., 0700 for the archive dir and 0600 for files) when creating/writing archives.

Useful? React with 👍 / 👎.

@Komzpa Komzpa added the 🤖 codex: needs work [@codex review] raised an issue label May 16, 2026
@Komzpa Komzpa removed the 🤖 codex: needs work [@codex review] raised an issue label May 16, 2026
@Komzpa

Komzpa commented May 16, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

ℹ️ 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".

@Komzpa Komzpa added the 🤖 codex: ok [@codex review] says no issues found. label May 16, 2026
@Soju06
Soju06 merged commit 1473269 into Soju06:main May 17, 2026
18 checks passed
Soju06 added a commit that referenced this pull request May 17, 2026
Release 1.18.0 — v1.17.0 → main, 27 PR.

## Pre-merge verification (release-gate e2e)

- ✅ CI 18/18 (mergeStateStatus CLEAN)
- ✅ baseline release-gate-smoke: 10/10 (`v1.models`, chat non-stream/stream/tool_call, responses non-stream/stream, unknown-msg-key drop, transient codes, dashboard 72-byte, alembic index)
- ✅ per-PR e2e extra: 14/14 (#658 strict tool × chat valid/invalid/type-omitted + responses invalid, #650-652 trim replay markers, #516 prev-resp miss mask, #558 prolite plan, #600 token_expired, #635 device poll, #647 frontend 72B, #594 account selection, #640 alembic head, #653/#654 conv archive, #655/#656 weekly pace)
- ✅ pytest 562 passed / 3 PG-only skip (unit + integration suite)
- ✅ SDK e2e 20/20 (`tests/e2e/test_openai_sdk_compat.py` + `tests/e2e/test_v1_responses_openai_sdk.py`)
- ✅ `scripts/verify_v1_responses_openai_sdk.py` 5/5 against live container with real account
- ✅ ruff check + ruff format --check + uv run ty check — All clean
- ✅ prod parity probe: #637 (unknown-key drop) + #658 (strict tool 400) both confirmed fixed vs prod 1.17.0

## Behavior change to note in announcements

- **#658**: `strict: true` function tool schemas missing `additionalProperties: false` (or other strict-mode requirements) now return a local **400 `invalid_function_parameters`** with `param=tools[N].function.parameters` (chat) / `tools[N].parameters` (responses). Pre-1.18.0 these were silently forwarded upstream; 1.18.0 enforces OpenAI's documented strict-mode contract locally before forwarding.

OpenSpec changes shipped in this release (to be archived after tag publish):
- deactivate-on-token-expired (#600)
- drop-unknown-message-fields (#637)
- mask-single-http-previous-response-miss (#516)
- normalize-v1-responses-openai-sdk-stream (#639)
- start-device-oauth-polling (#635)
- support-prolite-plan-capacity (#558)
- treat-upstream-overloaded-as-retryable (#601)
- validate-password-length (#598)
- validate-strict-function-tool-schema (#658)
vitalNohj pushed a commit to vitalNohj/codex-lb that referenced this pull request Jul 17, 2026
* feat(observability): add conversation archive backend

* fix(observability): drain archive queue on shutdown

* fix(observability): harden archive writer recovery

* fix(archive): harden archive lookup and listing

* style(archive): format archive lookup

* fix(archive): read request records chronologically

* fix(archive): skip binary archive encoding when disabled

* fix(archive): bound writer queue by bytes

* fix(archive): include full request spans in lookups

* fix(archive): drop records when enqueue fails

* fix(archive): restrict archive file permissions
vitalNohj pushed a commit to vitalNohj/codex-lb that referenced this pull request Jul 17, 2026
Release 1.18.0 — v1.17.0 → main, 27 PR.

## Pre-merge verification (release-gate e2e)

- ✅ CI 18/18 (mergeStateStatus CLEAN)
- ✅ baseline release-gate-smoke: 10/10 (`v1.models`, chat non-stream/stream/tool_call, responses non-stream/stream, unknown-msg-key drop, transient codes, dashboard 72-byte, alembic index)
- ✅ per-PR e2e extra: 14/14 (Soju06#658 strict tool × chat valid/invalid/type-omitted + responses invalid, Soju06#650-652 trim replay markers, Soju06#516 prev-resp miss mask, Soju06#558 prolite plan, Soju06#600 token_expired, Soju06#635 device poll, Soju06#647 frontend 72B, Soju06#594 account selection, Soju06#640 alembic head, Soju06#653/Soju06#654 conv archive, Soju06#655/Soju06#656 weekly pace)
- ✅ pytest 562 passed / 3 PG-only skip (unit + integration suite)
- ✅ SDK e2e 20/20 (`tests/e2e/test_openai_sdk_compat.py` + `tests/e2e/test_v1_responses_openai_sdk.py`)
- ✅ `scripts/verify_v1_responses_openai_sdk.py` 5/5 against live container with real account
- ✅ ruff check + ruff format --check + uv run ty check — All clean
- ✅ prod parity probe: Soju06#637 (unknown-key drop) + Soju06#658 (strict tool 400) both confirmed fixed vs prod 1.17.0

## Behavior change to note in announcements

- **Soju06#658**: `strict: true` function tool schemas missing `additionalProperties: false` (or other strict-mode requirements) now return a local **400 `invalid_function_parameters`** with `param=tools[N].function.parameters` (chat) / `tools[N].parameters` (responses). Pre-1.18.0 these were silently forwarded upstream; 1.18.0 enforces OpenAI's documented strict-mode contract locally before forwarding.

OpenSpec changes shipped in this release (to be archived after tag publish):
- deactivate-on-token-expired (Soju06#600)
- drop-unknown-message-fields (Soju06#637)
- mask-single-http-previous-response-miss (Soju06#516)
- normalize-v1-responses-openai-sdk-stream (Soju06#639)
- start-device-oauth-polling (Soju06#635)
- support-prolite-plan-capacity (Soju06#558)
- treat-upstream-overloaded-as-retryable (Soju06#601)
- validate-password-length (Soju06#598)
- validate-strict-function-tool-schema (Soju06#658)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🤖 codex: ok [@codex review] says no issues found.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants