Skip to content

Studio: advertise the chat-title repair guards on the thread lists instead of fetching /openapi.json - #15685

Merged
danielhanchen merged 4 commits into
mainfrom
perf/chat-guard-flag
Oct 28, 2026
Merged

danielhanchen merged 4 commits into
mainfrom
perf/chat-guard-flag

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

The legacy chat-title repair only writes when the backend enforces the expectedTitle and expectedOpeningMessageId guards on PATCH /api/chat/threads/{id}. To find that out, the frontend fetched the whole /openapi.json once per page session and looked for the two fields on ChatThreadPatch. That document is 1.15 MB, and building it the first time takes the backend about 3.3 s of CPU. This PR has the thread list responses the sidebar already loads say the same thing in one boolean, and keeps the schema probe for backends that do not send it.

What changes

  • Backend, routes/chat_history.py: THREAD_PATCH_GUARDS is computed from ChatThreadPatch.model_fields, the same model the schema probe reads, so the two answers cannot differ. It is sent as threadPatchGuards on GET /api/chat/threads and POST /api/chat/sidebar/rows. No other field or status code changes.
  • Frontend, chat-api.ts: listChatThreads and fetchSidebarRows note the flag when the response carries a boolean. repair-legacy-chat-titles.ts uses it when present and otherwise runs the unchanged /openapi.json probe, including its rule that a failed fetch is not cached.
  • Version mixes:
    • New frontend, new backend: the flag is true, the same verdict the schema gives, so the repair runs exactly as before, minus the schema fetch.
    • New frontend, older backend (for example a Desktop shell talking to an older server): no flag, so the schema probe runs as today. The same happens when the threads came only from the local legacy store.
    • Older frontend, new backend: the extra field is ignored and /openapi.json still declares both guard fields.
  • The per-session caching of the answer is unchanged. The repair is always started from one of the two list responses, so the flag is known before the repair asks for it.

Results

main.app.openapi() on this branch: 1,151,343 bytes compact JSON, 3.28 s for the first build on this host. With the flag present, the repair no longer requests it. Nothing else in the frontend fetches /openapi.json.

Tests

  • New studio/backend/tests/test_chat_thread_patch_guards_flag.py (4): both list responses carry threadPatchGuards: true, the flag equals what the schema probe reads, and the flag follows ChatThreadPatch. All 4 fail on main and pass here.
  • studio/frontend/tests/openapi-support.test.ts, 5 new cases: flag read and malformed input, an advertised flag never calls the probe, a missing flag runs the probe and returns its answer unchanged, flag and schema agree. On main the file fails to import the new helpers; here 11 of 11 pass.
  • Backend neighbours (test_chat_history_routes.py, test_chat_history_storage.py, test_chat_sidebar_rows.py, test_chat_thread_settings.py, test_rag_thread_document_cleanup.py, multi_account/test_routing_invariance.py, test_keyless_api_access_adversarial.py): same failing test IDs as main. The 21 failures in test_rag_thread_document_cleanup.py happen on main too, because this host has no sqlite-vec.
  • Full frontend node --test run: the failing test names are the same as on main except openapi-support.test.ts, which now passes. The other failures are files that need node_modules, which this checkout does not have, on both sides.

Not covered

  • Not watched in a real browser or Desktop session. That /openapi.json is no longer requested follows from the call sites above, but no network panel was checked.
  • No TypeScript typecheck or production build in this checkout.

Verification

  • Real browser, two isolated Studio installs (merge base vs this branch), /chat reload with seeded threads: /openapi.json requests 1 -> 0; GET /api/chat/threads returns threadPatchGuards: true on this branch and omits it on the base. Chat endpoint request counts are otherwise identical; the only other moved counts are timer polls (/api/inference/status, /api/hub/*) inside the fixed settle window. No visible UI change.
  • Follow-up commit: the repo-root seam check tests/studio/test_legacy_chat_title_repair.py asserted the old probe text and failed here; it now also asserts the advertised flag decides first (passes here, fails against the base source). Five frontend tests that load chat-api.ts through loadWithStubs needed a stub for the new ../utils/openapi-support import (28 failures before, 0 after).
  • Full frontend node --test: 14260 pass / 0 fail here, 14255 / 0 on the base. Backend chat tests and every repo-root test reading these files: same results as the base.
  • Studio regression switchboard (auth, settings, crawl, upstream_ci, inference_settings, compaction): no functional regression; the remaining failures fail on the base too.

The legacy chat-title repair fetched the whole /openapi.json (~1 MB, and a multi-second cold build on the server) once per session to learn whether ChatThreadPatch has expectedTitle and expectedOpeningMessageId. The thread list and sidebar rows responses the repair already starts from now carry threadPatchGuards, derived from the same model. The frontend uses it when present and falls back to the schema probe for older backends; /openapi.json is unchanged for older frontends.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-28T11:00:41.440007Z
We couldn’t complete this review. Comment @codex review to try again.
c37929b Draft marked ready
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 8cd9da8e40

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

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 39500c6415

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

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: c37929b0b7

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

@danielhanchen
danielhanchen marked this pull request as ready for review October 28, 2026 11:00
@danielhanchen
danielhanchen merged commit ae41442 into main Oct 28, 2026
18 of 74 checks passed
@danielhanchen
danielhanchen deleted the perf/chat-guard-flag branch October 28, 2026 11:00
danielhanchen added a commit that referenced this pull request Oct 28, 2026
## Summary

`(Python 3.13, a-f)` fails on main and on every PR based on it (seen on
the #15693 and #15761 staging runs) with two stale tests. Both product
changes are intentional; the tests had not caught up.

**1.
`test_account_chat_settings.py::test_list_export_and_delete_stay_in_the_account`**

```
assert {'threads': [...Guards': True} == {'threads': []}
  Left contains 1 more item: {'threadPatchGuards': True}
```

#15685 advertises the chat-title repair guards on the thread lists
(`threadPatchGuards` on the `/chat/threads` reply). This test checks
that another account's thread stays invisible, but compared the whole
reply to `{"threads": []}`. It now asserts the thread list itself is
empty, which is the privacy claim.

**2.
`test_checkpoint_compaction.py::test_the_reachability_probe_closes_the_connection_it_opens`**

```
assert _open_archive_handles() <= before + 1
E   assert 4 <= (0 + 1)
```

#15719 keeps one WAL keeper connection per `rag.db` for the life of the
process (`storage/rag_db._ensure_wal_keeper`), holding `rag.db` plus its
`-wal` and `-shm` sidecars. The first probe in a fresh process creates
it, so the test counted the keeper's descriptors as a leak. It also
failed when run alone, not only under xdist.

The test now probes once to warm the keeper up, takes its baseline after
that, and requires no growth at all over 50 probes. That is stricter
than the old `before + 1`, and it is the leak the test exists for: one
leaked probe connection per call.

## Testing

- Both tests fail on main (`75555ccb54`) and pass with this change;
`test_account_chat_settings.py` 93 passed.
- Sabotage: replacing the `conn.close()` in
`conversation_archive.reachable()` with a no-op makes the probe test
fail with `assert 23 <= 5`.
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