Repository navigation
fix(gateway): batch worker placement session evidence - #124372
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 16, 2026, 7:18 AM ET / 11:18 UTC. ClawSweeper reviewWhat this changesThis PR batches Gateway worker-placement session evidence during each retirement sweep, avoiding repeated session-store discovery and SQLite reads while retaining fail-closed orphan cleanup. Regression provenancePossible regression — probable (reproduction; reviewed change). No predecessor PR is attributed. Merge readinessKeep open for maintainer review: current main still invokes the scalar resolver once per placement, while this branch creates one snapshot-scoped batch resolver and preserves the current/absent/unknown retirement contract. No discrete patch defect was found, but the session-state and availability-sensitive refactor is behind main and merits an exact-merge-head refresh before landing. Priority: P1 Review scores
Verification
How this fits togetherGateway worker-placement retirement compares durable worker placements with authoritative session-store evidence before retiring orphaned environments. Placement records enter the reconciliation sweep; tri-state session evidence determines whether the worker environment is retained or safely retired. flowchart LR
A[Durable worker placements] --> B[Retirement reconciliation snapshot]
B --> C[Session-store target resolution]
C --> D[Batch SQLite session evidence]
D --> E{Evidence outcome}
E -->|Absent| F[Retire orphan placement]
E -->|Current or unknown| G[Retain placement]
F --> H[Worker environment cleanup]
Decision needed
Why: The remaining choice is acceptance of a substantial but evidence-backed change on a destructive worker/session lifecycle path, which is intentionally marked for maintainer handling. Before merge
Agent review detailsSecurityNone. PR surfaceSource +238, Tests +313. Total +551 across 13 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Rebase and land the single snapshot-scoped resolver once exact-head checks reconfirm tri-state retirement behavior; its added owner-boundary code replaces the scalar per-placement work, and no smaller net-neutral absorption is evident. Do we have a high-confidence way to reproduce the issue? Yes — current main visibly performs target resolution and identity lookup for every placement, and the PR provides exact-head live measurements of that sweep under a large durable-placement history. Is this the best way to solve the issue? Yes — preparing one resolver per reconciliation snapshot keeps the authoritative tri-state decision at the session-store owner rather than adding a downstream cache or changing retirement policy. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 0c546979b2ac. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (10 earlier review cycles; latest 8 shown)
|
5f4b848 to
69a3338
Compare
69a3338 to
080f491
Compare
080f491 to
7d398b9
Compare
7d398b9 to
7742842
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
Land-ready verificationExact head:
Known proof gaps: none. Backend-only change; no visual surface. |
|
Merged via squash.
|
* perf(gateway): batch worker placement session evidence * test(gateway): tolerate elapsed workspace timeout * fix(gateway): preserve unknown placement evidence * fix(sessions): validate batched placement evidence * fix(gateway): preserve incognito placement evidence * fix(sessions): bound configured target discovery * fix(gateway): canonicalize batched placement evidence
* perf(gateway): batch worker placement session evidence * test(gateway): tolerate elapsed workspace timeout * fix(gateway): preserve unknown placement evidence * fix(sessions): validate batched placement evidence * fix(gateway): preserve incognito placement evidence * fix(sessions): bound configured target discovery * fix(gateway): canonicalize batched placement evidence
What Problem This Solves
After #124453 removed repeated target identity discovery, Molty still ran near 148% CPU and timed out WebSocket/RPC handshakes. Its 60-second worker-placement retirement sweep resolves evidence for 537 durable placements; the pre-fix live signature was 1,065 statx calls over 2 seconds, including repeated configured and retired/manual agent store probes.
Why This Change Was Made
PR #123785 (
3c5e2ff2964f, authored and merged by @steipete) correctly added fail-closed orphan placement retirement, but the sweep called complete target resolution and synchronous SQLite evidence lookup once per placement. This change snapshots the placement list; canonicalizes persisted placement keys and owners; resolves ordinary target availability once per distinct agent; routes incognito keys independently to their process-held key-selected store; batches exact session-key/current-session-id evidence per physical SQLite store in bounded 400-value queries; validates each relevant serialized row once with the scalar path's canonical parser; then reuses preparedcurrent/absent/unknownresults throughout reconciliation.The owner repair keeps configured-agent existing-target lookup on its bounded canonical/default-root paths instead of launching full-roster discovery once per placement owner. It preserves both upgrade contracts from the scalar path: canonical replacement-owner keys are probed before batching, while an exact row still owned by a deleted legacy agent is probed alongside the canonical owner with
current > unknown > absentprecedence. This also preserves the safety contract that an unreadable default-root candidate must keep media history from being reaped even when the configured canonical store is healthy. Genuine missing stores remain absent; unreadable, ambiguous, invalid, stale-projection, schema-incompatible, or indeterminate stores remain unknown. The old per-placement evidence path is removed.User Impact
Gateways with large worker-placement histories no longer spend each reconciliation interval rediscovering and reopening the same stores. Orphan cleanup stays intact across ordinary, incognito, canonicalized, and legacy-owner sessions; inaccessible/corrupt stores fail closed; and RPC/channel work remains responsive during the sweep.
Evidence
node scripts/run-vitest.mjs src/gateway/server-worker-placement-session-evidence.test.ts src/gateway/worker-environments/placement-session-retirement.test.ts src/config/sessions/session-accessor.readonly.test.ts src/config/sessions/targets.test.ts src/gateway/managed-image-attachments.test.ts— 5 files, 153 tests passed.node scripts/run-vitest.mjs src/gateway/server-worker-placement-startup.test.ts src/gateway/session-utils.test.ts— 2 files, 163 tests passed.node scripts/run-vitest.mjs src/gateway/managed-image-attachments.test.ts src/gateway/server-methods/sessions-search.test.ts src/gateway/server.sessions.list-store-materialization.test.ts src/gateway/session-sharing-store-cache.test.ts src/cron/session-reaper.test.ts— 5 files, 143 tests passed.agent:main:maininstead of canonicalagent:ops:main, and returnsabsentfor a listed deleted-main placement whose exact row is still current. The final tests prove both the canonical probe and deleted-owner fallback.OPENCLAW_CHECK_CHANGED_REMOTE_CHILD=1 node scripts/check-changed.mjs -- src/config/sessions/targets.ts src/config/sessions/targets.test.ts src/gateway/server-worker-placement-session-evidence.ts src/gateway/server-worker-placement-session-evidence.test.tspassed format, deadcode, core/test tsgo, changed-file lint, native schema/database guards, and import cycles. An earlier Daytona run passed every lane before its script-export Knip process was SIGKILLed; the local fallback completed that lane successfully.{ available:false, reason:"read-failed" }returnsunknown; genuine missing ordinary DB returnsabsent.entry_valid=1with mismatched serialized identity returnsunknownfor exact/fallback while unrelated same-store valid evidence remainscurrent.currentand a deleted incognito placement isabsent; ordinary discovery receives no incognito probe.73bd4f2cc7af5d7a26437bda2c2d04574e417177: 30-second CPU 23.7% (pre-fix 148.3%), RSS 997 MiB (pre-fix 2.77 GiB), and 120 readlinks over a full 70-second reconciliation window (pre-owner-fix head 22,310/70s; original pre-fix 19,620/8s). HTTP across 20 samples was p50 3.4 ms, p95 19.8 ms, max 45.4 ms. Deep RPC returned the exact73bd4f2cc7afbuild, health was non-degraded, Discord/Reef/Slack were connected with no errors, and no placement/evidence/serialized/canonical errors appeared after restart.lastStatus: ok,lastDeliveryStatus: delivered,consecutiveErrors: 0, next run2026-08-16T17:30:00Z.<= 777 msdeadline invariant.