Repository navigation
perf(gateway): select observer model slots in one pass - #136401
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed September 2, 2026, 3:42 PM ET / 19:42 UTC. ClawSweeper reviewWhat this changesThe PR replaces repeated temporary-array filtering and sorting in Gateway observer model-slot allocation with a single scan that counts occupied slots and selects the oldest eligible session to demote. Merge readiness✅ Ready for maintainer review Keep open. The refreshed-head refactor preserves the allocation predicate, eviction ordering, protection rules, and demotion callback; current main does not contain it yet. Priority: P3 Review scores
Verification
How this fits togetherGateway session observation assigns a utility model to directly viewed sessions. At capacity, it selects an eligible older session to demote so the requesting session can receive the model slot. flowchart LR
A[Observed sessions] --> B[Utility model claim]
B --> C[Resolve configured model]
C --> D[Scan occupied slots]
D --> E[Select oldest eligible session]
E --> F[Demote if capacity is full]
F --> G[Return model slot]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +2, Tests +10. Total +12 across 2 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Merge the focused single-pass implementation after the normal exact-head CI gate is green; it keeps the existing slot-allocation contract while removing avoidable intermediate collections and sorting. Do we have a high-confidence way to reproduce the issue? Not applicable: this PR optimizes an existing internal allocation path rather than reporting a user-visible bug. Is this the best way to solve the issue? Yes. The scan retains the baseline occupancy predicate, eviction comparator, protection exclusions, and demoted-state readmission behavior at the owner boundary. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 7b0fc05505aa. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
ea14435 to
1466c65
Compare
|
Merged via squash.
|
What Problem This Solves
Claiming a utility-model slot copied every observed session, filtered that array, then filtered and sorted it again to select one eviction candidate. Busy observers paid for those temporary arrays even though the decision needs only a count and one oldest eligible state.
Why This Change Was Made
Select the oldest eligible state and count occupied slots in one pass over the authoritative map. Preserve the existing activity/session-key ordering, terminal and finalization protection, current-state exemption, demoted-state readmission, and exact demotion callback. No cache, lifecycle or configuration change is introduced.
User Impact
The same sessions receive model slots with less temporary array work. Production grows by two lines to express the single-pass count and selection; four temporary arrays and sorting are removed. Existing behavioral tests grow by ten lines to distinguish activity ordering from tied session-key ordering and terminal protection from pending-finalization protection.
Evidence
35 focused observer tests and the full canonical changed gate passed. Managed Codex review found no actionable P0–P2 findings. An actual-source baseline/candidate probe matched 512 seeded scenarios of twelve serial claims, including state removal, protection changes, starvation/readmission and request-generation abort behavior.
The allocation-work probe ran 100 claims over 1,024 observed states, six of which occupied model slots:
{"baseline":{"filterCalls":200,"filterOutputSlots":1200,"sortCalls":100,"sortOutputSlots":600},"candidate":{"filterCalls":0,"filterOutputSlots":0,"sortCalls":0,"sortOutputSlots":0}}The prior full-map spread is also removed. These are operation/element counts, not backing-store bytes, retained heap or RSS measurements. Both source probes exited 0. The owner and full observer-service tests passed together:
The reviewed patch is now on main revision
1e37a56c75289bd887bbb244965d4896b921b625, including the browser-fixture repair from #136402. Refreshed head:1466c6572804aad8447494440f3b415f8ec1dbe1. The touched source bytes and stable patch identity match the previously reviewedea144356a1e0b52bd303d1db20c3ecc8d53e9a6f; previously recorded behavior runs cover that identical owner source, and hosted CI validates the refreshed head.The base already uses the selective
plugins inspect openai --jsonlifecycle probe. Build readiness is checked by the refreshed CI run; this does not claim a separately measured inspect-output byte count.