Skip to content

perf(gateway): select observer model slots in one pass - #136401

Merged
steipete merged 1 commit into
mainfrom
codex/perf4-observer-slots
Sep 2, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/perf4-observer-slots

Conversation

@steipete

@steipete steipete commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

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:

node scripts/run-vitest.mjs src/gateway/session-observer-model-slots.test.ts src/gateway/session-observer.test.ts
node scripts/check-changed.mjs -- src/gateway/session-observer-model-slots.ts src/gateway/session-observer-model-slots.test.ts

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 reviewed ea144356a1e0b52bd303d1db20c3ecc8d53e9a6f; 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 --json lifecycle probe. Build readiness is checked by the refreshed CI run; this does not claim a separately measured inspect-output byte count.

@clawsweeper

clawsweeper Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S maintainer Maintainer-authored PR labels Sep 2, 2026
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 2, 2026
@clawsweeper

clawsweeper Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 2, 2026, 3:42 PM ET / 19:42 UTC.

ClawSweeper review

What this changes

The 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
Reviewed head: 1466c6572804aad8447494440f3b415f8ec1dbe1

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, invariant-preserving internal refactor with targeted behavioral coverage and no actionable review finding.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored internal performance refactor is outside the external-contributor real-behavior-proof gate; its targeted allocation and observer tests are supplemental validation.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored internal performance refactor is outside the external-contributor real-behavior-proof gate; its targeted allocation and observer tests are supplemental validation.
Evidence reviewed 5 items Introduced allocation logic: The exact PR head replaces the baseline filtered-and-sorted candidate collection with a single scan using the same occupied-state predicate, terminal/final-pending exclusion, and activity/session-key comparator.
Owner and caller boundary: The observer owns slot state and supplies a demotion callback that aborts pending work and clears the utility model; the current-state claim path then updates the model reference before scheduling work.
Behavioral coverage: The changed table-driven tests cover both activity and session-key ordering plus terminal and pending-finalization protection; the owner-level observer suite covers retained preamble behavior and revision continuity after demotion.
Findings None None.
Security None None.

How this fits together

Gateway 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]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +2, Tests +10. Total +12 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 19 17 +2
Tests 1 45 35 +10
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 64 52 +12

Review metrics

Metric Value Why it matters
Production vs test LOC production +19/-17 (net +2); tests +45/-35 (net +10) The small production increase absorbs the allocation selection into one pass while the test change distinguishes the preserved ordering and protection cases.

Technical review

Best 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.

Labels

Label justifications:

  • P3: This is a contained internal performance improvement with no changed configuration, persisted state, protocol, or user-visible behavior.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored internal performance refactor is outside the external-contributor real-behavior-proof gate; its targeted allocation and observer tests are supplemental validation.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit dd7f7ad adds src/gateway/session-observer-model-slots.ts:28 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: dd7f7ada7e0e; files: src/gateway/session-observer-model-slots.ts)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed 2026-09-02T15:54:32.363Z sha ea14435 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-02T19:24:26.163Z sha ea14435 :: needs maintainer review before merge. :: none

@steipete
steipete force-pushed the codex/perf4-observer-slots branch from ea14435 to 1466c65 Compare September 2, 2026 19:35
@steipete
steipete merged commit d4eb135 into main Sep 2, 2026
492 of 496 checks passed
@steipete
steipete deleted the codex/perf4-observer-slots branch September 2, 2026 20:25
@steipete

steipete commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant