Repository navigation
perf(dashboard): skip the folder-project thread hop when no folder sets one - #13994
Conversation
|
Intent: Make "New chat" inside a sidebar folder cost the same as an unfiled new chat by removing the two default-executor hops that do nothing for a fresh, message-less slot in a folder without a project. |
GPT 5.6 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
Design Review (Fable 5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Description says the peer test "now gives its folder a [DESIGN-REVIEWED] 56df85e |
First Principles Review (Fable 5, fork) — 🟡 CONCERNSPremise-level review of First-Principles-Verdict: CONCERNS The rewritten Not justified as shipped
What this change shipsInventory (6 items) — 4 justifiedIntent: make "New chat" (and agent switch) inside a project-less folder stop waiting on a saturated worker pool — a FIX (issue #13993, measured 161→81 ms).
[FIRST-PRINCIPLES-REVIEWED] 56df85e |
Opus 5 Review (fork) — ✅ no blocking findingsReviewed |
1b6aa65 to
5b026b6
Compare
|
|
|
|
Rebased onto current |
5b026b6 to
2851c1c
Compare
…ts one Creating a chat inside a sidebar folder, and switching agents in one, sent _resolve_folder_project_dir to a worker thread even when no folder in the chain declares a project_dir. That hop queues on the shared default executor before the response, so on a busy gateway a folder create was slower than an unfiled one for no result. Split the resolver into an on-loop chain walk (_folder_declared_project) and the directory validation, and add resolve_folder_project_dir_off_loop, which hops to a thread only for a declared project. Both runtime callers use it. The create handler's forced history save stays: for an owner-dashboard create it is what writes folder_id, tags and title to the new metadata line.
2851c1c to
56df85e
Compare
Problem / Motivation
"New chat" inside a sidebar folder is slower than "New chat" at the top level. On a busy gateway the folder create waits for a worker thread to look up a folder project, even when no folder in the chain sets one.
Why it matters
Starting a chat in a folder is how people keep work organized, so this path runs constantly. In the executor-saturated repro below, a folder create took 161 ms and an unfiled create took 41 ms. This PR removes the wait that produced nothing, which brings the folder create to 81 ms. The rest of the gap is the history save that records the new chat's folder, which has to happen.
What changed (motivation → approach → change)
A new chat inside a folder with no project directory no longer queues on the shared default executor to find that out. The same applies to switching agents in such a folder.
_resolve_folder_project_dirindashboard/chat_folders.pyis now two steps._folder_declared_projectwalks the folder chain as plain dicts, which is safe on the event loop._validate_project_dirthen checks the directory on disk. The newresolve_folder_project_dir_off_loopruns the walk on the loop and sends only the validation to a worker thread, and only when a folder in the chain declares aproject_dir. Both runtime callers use it:api_chat_slot_createandapi_chat_slot_agentindashboard/chat_handlers.py. There is still one chain walk, so cycle handling, missing ids and which folder wins are unchanged.The forced history save in the create handler is unchanged. For an owner-dashboard create,
_record_explicit_agent_selectionhas already written the new session's metadata line by then, and this save is what addsfolder_id, the folder's tags and the title to it. Without it, a restart before the first message would restore the tab unfiled.Backwards compatibility
Compatible: request and response shapes are unchanged. Project inheritance and
folder_project_invalidbehave as before for folders that declare a project.Tests
test/test_chat_slot_create_folder.py:TestFreshFolderCreateStaysOffTheExecutorchecks that a create in a folder with no project never reaches the validator. It also checks that a folder with a project is still validated, and that validation runs on a worker thread only when a project is declared.TestOwnerFolderCreatePersistsTheFilingdrives the real create handler as the dashboard owner and assertsfolder_idon the metadata line. It fails if the forced save is skipped.test/test_remote_crew_execution.py::test_an_invalid_folder_project_never_reaches_the_peernow gives its folder aproject_dir, so its faked validation error is still reached.Manual verification
I timed the real handler under aiohttp
TestClient, 20 creates per row. The default executor was limited to 4 workers, with a feeder keeping them busy on 40 ms jobs.mainmedianOn an idle pool both paths take about 2 ms before and after.
Related Issues
Fixes #13993
Pattern harvest
Rule candidate: review-prompt
Pattern: an
await asyncio.to_threadorrun_in_executorcall on a request path whose work is a guaranteed no-op for the common input. Check the cheap on-loop condition first, and keep one implementation of that condition.Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)