Repository navigation
refactor(gateway): simplify cron and session resource owners - #174111
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3c00e6aa49
ℹ️ 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".
| event = { | ||
| sessionKey: event.sessionKey, | ||
| agentId: event.agentId, | ||
| reason: "updated", | ||
| ...(event.catalogChanged ? { catalogChanged: true } : {}), |
There was a problem hiding this comment.
Drop queued events after their generation is replaced
When a lifecycle event arrives before its row is resident and that key is reset or replaced while withPreparedEventRow awaits, this rewrite discards the event's original incarnation and later publishes sessions.changed from the successor row as updated. Clients can therefore update or admit the successor because of predecessor activity; queued events must capture their generation before awaits and reject replacement, so retain the generation observation and suppress publication on mismatch.
AGENTS.md reference: src/gateway/AGENTS.md:L56-L56
Useful? React with 👍 / 👎.
|
Codex review: needs changes before merge. What this changesThis PR consolidates Gateway cron and session lifecycle ownership and removes redundant generation, observation, and retry bookkeeping. Example: Native ownership changes while listing agent:main:planning.
Review scores
ProductKind: Refactor · Worth it: Yes Merge readiness⛔ Needs changes before merge - 4 items remain Keep open: this maintainer-directed simplification has clear value, but the candidate introduces concrete test failures that need repair. Priority: P2 Before merge
Findings
Tests
Agent review detailsHow this fits togetherGateway resource owners consume persisted cron jobs, session requests, and lifecycle events, then coordinate supervised processes, worker reads, and authorized client publications. flowchart TD
A[Cron schedules and session requests] --> B[Gateway]
B --> C[Cron lifecycle owner]
B --> D[Session projection owner]
C --> E[Process supervisor]
D --> F[History workers]
D --> G[Authorized client events]
Technical reviewBest possible solution: Retain the single-owner design and accepted tradeoffs, repair the affected fixtures, and verify lifecycle upgrade behavior. Do we have a high-confidence way to reproduce the issue? This refactor claims no current-main user defect; exact-head CI failures and their causes were verified against source without running target code. Is this the best way to solve the issue? Consolidating lifecycle decisions in existing owners follows repository guidance, and the recorded tradeoffs do not require another product decision. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 72629e1fdff9. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
PR surfaceSource -584, Tests -183, Docs 0. Total -767 across 53 files. Added test files: 1. View PR surface stats
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 16, 2026, 6:52 AM ET / 10:52 UTC. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8123365d4f
ℹ️ 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".
| !this.desiredRunning || | ||
| this.state !== "starting" | ||
| ) { | ||
| if (!ownsPersistedJob || !this.desiredRunning) { |
There was a problem hiding this comment.
Retain a per-request fence for each stream start
When start A is awaiting persistState, an intervening stop sets desiredRunning false, but a later queued start C sets this shared flag true again before A resumes. A then passes this check and can spawn A's stale command before the queued stop executes; preserve a request-specific generation/token so a newer start cannot reauthorize an older command effect.
AGENTS.md reference: AGENTS.md:L71-L71
Useful? React with 👍 / 👎.
| event = { | ||
| sessionKey: event.sessionKey, | ||
| agentId: event.agentId, | ||
| reason: "updated", | ||
| ...(event.catalogChanged ? { catalogChanged: true } : {}), |
There was a problem hiding this comment.
Preserve swarm notes for nonresident rows
When a swarm-note arrives for a valid session whose row is not resident, this rewrite discards swarmGroupId, kind, and text even if the session identity never changes. These notes are transient Control UI state and are not recoverable from the later row snapshot, so the generic updated event silently loses the active swarm phase or log; retain the note for its original incarnation and suppress it only if that incarnation is replaced.
AGENTS.md reference: src/gateway/AGENTS.md:L59-L61
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 73ae768a85
ℹ️ 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".
| ) { | ||
| return undefined; | ||
| } | ||
| if (params.restoredCronContinuationIdentity && !params.restoredCronContinuation) { |
There was a problem hiding this comment.
Revalidate lifecycle before registering the run owner
When an internal/one-shot request crosses an in-process Gateway restart during an earlier delivery or admission await, this removed guard allows prepareAgentRunDispatch to register a controller and claim a run context using the stale lifecycle generation. Because the restart sweep has already completed, a same-ID retry can then be reported as in_flight until later user-turn preparation detects and cleans up the stale owner; revalidate the generation synchronously after work-admission acquisition and immediately before publishing the controller.
AGENTS.md reference: src/gateway/AGENTS.md:L29-L30
Useful? React with 👍 / 👎.
PR 174111 exact-head inherited failure evidencePR head: 73ae768. Actual failed-job checkout log, fetched through gh run view: GitHub commit API and retained Git object independently resolve that checkout to Baseline: completed scheduled main run 38894297213 at Both exact check-run annotation inventories report these same five failures in
Every case has the identical assertion diff: expected roles Model, Utility Model, The classifier labels the job pre-existing by JOB NAME ONLY, explicitly without Read-only git diff --quiet passed for both named failing test/helper paths from All exact-head check runs were enumerated through gh api --paginate. There are Evidence URLs: |
73ae768 to
990f3f3
Compare
|
Merged via squash.
|
…w#174111) * refactor(gateway): simplify lifecycle resource owners * fix(gateway): preserve cron handoff and current owner fixtures * fix(gateway): select lifecycle event without parameter mutation * test(gateway): format rebased lazy cron fixture
#175461) Fix forward from #175307. The native admission helper recognized a committed registration notice, but its outer callback still checked the retired caller. Refusing that bookkeeping notice left an opened worker without its installed identity and replaced the expected lifecycle refusal with unknown settlement. End authorization for this already-observed COMMIT at the outer callback. Receipt observation still validates and records the exact registration owner; subsequent validation, preparation and command admission keep live authority. Generic failed-report retirement and first-use creation checks are unchanged. Also align the queued-collector fixture with #174111's documented contract: uncaptured lifecycle events publish current updated facts. Select create or updated session publications while retaining every payload, runtime, Stop and authority assertion. A forced initial capture miss reproduced the exact hourly failure with a correctly published Collector B row, and passes after this fix. Current main with #175307 reverted passed both full files (48 tests). Restoring it reproduced both cold-registration failures. The repair passes 148 tests across the execution, restart, reclamation, reply and collector files; one existing Linux-only killed-owner test remains skipped on macOS. Targeted state and Gateway test type graphs, type-aware lint, formatting and P0-P2 review pass. No timeouts, retries, schemas or permission contracts changed.
openclaw#175461) Fix forward from openclaw#175307. The native admission helper recognized a committed registration notice, but its outer callback still checked the retired caller. Refusing that bookkeeping notice left an opened worker without its installed identity and replaced the expected lifecycle refusal with unknown settlement. End authorization for this already-observed COMMIT at the outer callback. Receipt observation still validates and records the exact registration owner; subsequent validation, preparation and command admission keep live authority. Generic failed-report retirement and first-use creation checks are unchanged. Also align the queued-collector fixture with openclaw#174111's documented contract: uncaptured lifecycle events publish current updated facts. Select create or updated session publications while retaining every payload, runtime, Stop and authority assertion. A forced initial capture miss reproduced the exact hourly failure with a correctly published Collector B row, and passes after this fix. Current main with openclaw#175307 reverted passed both full files (48 tests). Restoring it reproduced both cold-registration failures. The repair passes 148 tests across the execution, restart, reclamation, reply and collector files; one existing Linux-only killed-owner test remains skipped on macOS. Targeted state and Gateway test type graphs, type-aware lint, formatting and P0-P2 review pass. No timeouts, retries, schemas or permission contracts changed.
What Problem This Solves
Gateway resource owners repeat private lifecycle, generation and observation
protocols around cron work, session reads and run admission.
User Impact
No feature or public configuration, protocol, SDK or persisted-data migration.
FIFO, current security/effect authority, committed transcript durability, resource
bounds and ordinary-shutdown settlement remain required. The UI change only
imports the existing canonical avatar-path parser; there is no visual change.
Why This Change Was Made
Put cron start/pause/stop and persisted EXIT/STREAM startup sweeps in the existing
canonical owner rather than replaying them through the lazy adapter. Retain the
existing pre-write callback transfer needed to avoid a closed-fence restart wait cycle. Stream
output uses its existing FIFO, actual run and abort signal rather than per-hop
generations, redundant epochs, diagnostic seed caches and custody maps.
Keep session async reads with their existing worker owner and the final live
installation/disclosure checks; remove the second read-custody and descriptive
ownership retry layer. Retire the unknown-event observation registry while
retaining captured identity/revision checks and per-session FIFO. Remove the
special generation-only admission ACK protocol, not real reset/Stop/error replay
or any of the four successful preparation revalidators.
Phase E standalone session memory, its factory, registry, expiry, federation
machinery and tests are untouched. No SQLite schema, retention, permissions,
dependency, suppression, timeout, retry, skip or public-contract change.
Best-effort tradeoffs accepted
pending joins that cancelled operation; restart after its drain. Normal reload
uses a distinct replacement. feat(gateway): add cooperative host suspension #103618 supplies synthetic suspension evidence,
not a cited human actual-use incident requiring recursive successor startup.
sweep rather than relisting five times. The direct route handles its committed
job; a later normal sweep repairs unrelated inventory. feat(cron): stream schedule sources with durable source identity #112387/fix: prevent cron and Workboard lifecycle races #114744 supplied
synthetic interleavings; the one command/source effect check stays.
job snapshot before the final start applies the latest one. Existing FIFO,
actual run identity, cancellation and persisted source effect authority remain.
feat(cron): stream schedule sources with durable source identity #112387 describes induced timing rather than a human actual-use incident.
diagnostic-only activity until a fresh snapshot; persisted totals never
decrease. The diagnostic seed/tombstone machinery had no cited human incident.
invalidation rather than retrying an unchanged list. refactor: prepare conversation ownership off the Gateway thread #168480 is worker migration
and synthetic measurement evidence, not a human descriptive-reload incident.
Execution/transcript/sharing authority remains live at its effect.
uncaptured lifecycle events publish current updated facts without predecessor
label/swarm/capacity overrides. Captured identities, explicit revisions and
recipient authorization stay; no human incident requires the extra registry.
fabricated reset/timeout success. fix(gateway): mark active main sessions before restart shutdown aborts #91357/feat: add session thread management #98510/fix(gateway): stop input effects after caller authority closes #150640 provide synthetic
observation-ACK evidence. Human Windows restart report Managed restart shutdown can abort active main turns without restart-recovery state #91355 is different:
its durable abortedLastRun marker-before-abort is retained, as are genuinely
committed reset/delivery replay, Stop and ordinary shutdown settlement.
Quiet-window execution cadence is NOT best effort: independent review found that
a callback already queued behind async matching could flush a newer batch early.
The final change retains the existing scheduled-job identity and one comparison
at the queued flush effect, plus the complete original execution-cost regression.
Evidence
Production: 25 files, 446 added / 1,017 removed = 571 net lines removed
(24 Gateway files plus the canonical parser import in one UI file).
Tests, fixtures/support, generated and declaration outputs are excluded.
Fresh complete 53-file independent P0-P2 review finished in four passes. Its one
actionable quiet-window finding was fixed as described above; the complete two
stream files then received a fresh scoped-clean P0-P2 review. Complete source and
context hashes were independently verified after the signed commit.
Formatting passed for all 52 changed TypeScript files and the normal commit hook.
The mandatory lint-suppression gate passed all three assertions (424.86 seconds).
The final focused quiet-window invocation reached the runner's unchanged
900,000ms no-output limit without assertions (1,337.15 seconds total); it is
missing runtime proof, not a pass or an attributed product failure. Actual
check-changed attempt passed line-cap for all52 sources, then reported max-lines
suppressions in three unchanged main UI files; remaining stages were interrupted.
Earlier broader focused/type/lint/cycle attempts were deliberately stopped
before the quiet correction and have no complete verdict; they are not passes.
No interrupted command or host-load timeout is called passing or inherited CI.
Exact-head PR CI is the broad proof and required landing gate.
The first exact-head CI run38887793326 found PR-caused defects. They are not
attributed as inherited or waived: the cron handoff cut created a real wait cycle
behind the closed restart fence, so both original transfer hunks and the original
pending-callback regression are restored. The canonical startup/lazy-owner cut
remains. Worker-read fixtures migrate from it.each to it.for for the actual
Vitest TestContext, and from the removed outer custody chain to the real awaited
worker boundary. Event privacy tests inspect actual JSON wire shape while keeping
their current-row and private-field assertions. Required timestamps are supplied
in the lifecycle fixture; the extracted marker-queue proof uses canonical
operation-bound gate waits rather than adding a timeout-race allowance.
The seven-file CI repair received a fresh complete three-pass scoped-clean P0-P2
review (112 complete source/context files); the two final fixture repairs then
received their own fresh scoped-clean P0-P2 review. Runtime/lint/type proof on
the repaired source remains in progress; interrupted attempts are not passes.
The targeted Gateway-server typecheck passed (445.25 seconds), and the fresh
mandatory suppression gate passed all three assertions (245.82 seconds).
Lint identified an unnecessary JSON round-trip in the fixture repair. The final
two-file change keeps raw-payload assertions and checks the wire-only private key
directly in JSON bytes, with no copy or suppression. Its fresh P0-P2 review is
scoped-clean and two-file lint passed (343.56 seconds). Final runtime proof is
still in progress; the previous frozen attempt was stopped to apply this repair.
These CI repairs are pushed as signed commit
8123365. Complete reviewed source hashes
remain unchanged after the normal commit hook. Exact-head CI, not a load-only
local timeout or prior-head result, is the broad landing proof.
Second exact-head run38893296858 at8123365d4fc found two attributable cleanup
misses: lint rejected reassignment of the lifecycle-event parameter, and the
timeout-race ratchet required deleting the now-unused five-site allowance for
the extracted server-session-events test. The broadcaster now selects the
identical normalized event into a const; delete/routing, captured identity,
recipient authorization and disclosure behavior are unchanged. The unrelated
media-facts assertion baseline also shrinks16 to the actual14 reported by CI;
no allowance increases. Other line-cap/env-budget annotations were warnings,
not additional failed owners. Every observed runtime/type leaf passed.
These three-file repairs are signed commit73ae768a8535930fe8483b72617e036284fdcd2f.
Fresh complete scoped-clean P0-P2 review and independent hash verification cover
the exact sources after the normal hook. Format passed (6.44s), lint passed
(321.55s), mandatory suppression passed all three assertions (176.62s), runtime
cycles passed with zero value cycles (399.48s), and timeout-race ratchet passed
(78.39s). The previous focused attempt was stopped after cron assertions to apply
this actual lint fix; it has no full passing verdict. Madge passed with zero
cycles (943.48s), and assertion-ratchet passed (425.27s; 2,632 files and 6,068
sites). Focused event/lifecycle runtime proof passed: two files and 61 tests
(1,389.33s wrapper wall time on the loaded host). These retain FIFO, captured
identity, current-row authorization, lifecycle fields and private wire-shape
assertions. Exact-head CI38896745763 is the broad landing gate.
The completed exact-head run38896745763 passes all attributable runtime, build,
type, lint, ratchet and architecture leaves. Its only failed leaf is
checks-ui-e2e (6/9)(job116959546190): five Models-page layout cases at390/640/768/1100/1440px expect a control list that omits Utility Fallback Model.
The same five cases, exact extra-control diff and stack fail on scheduled main
run38894297213, job116951151556, main1dbc6fb1f327fb861889c8abf8174fbf73052f24
(verified ancestor of origin/main). This is inherited evidence, not a green CI
claim or a Gateway cleanup regression. Aggregate116964674071 is downstream of
that sole leaf. Native inherited-failure admission still must verify exact-head
security, policy, review and source evidence; no CI rerun is requested.
Current conflict-repaired candidate
The current signed head is990f3f3fc5fb725d66fe603bc7da2bce5ad87eba on base
d0d1f4c: 571 net production lines removed,
25 files,446added/1017removed. The actual conflict was main's test-only lazy-cron
fixture consolidation. Its shared fixture/typed mocks and unrelated tests remain;
the complete pending-callback cron-exit handoff suite is byte-identical to main.
Production patches are unchanged. Fresh P0-P2 review was scoped-clean, complete
source/context hashes were externally verified after the signed formatting commit,
and two-fixture type-aware lint passed (73.38s). Post-rebase focused runtime passed
both files and all45tests, including pending-callback handoff (1488.23s wrapper).
Gateway-root graph types, runtime cycles0, Madge cycles0 and all3 mandatory
suppression assertions passed (1635.26s combined). These long local times reflect
the loaded proof host, not a product performance measurement.
All earlier CI failure/repair records above are historical evidence for their
named heads. In particular, the old73ae UI-layout baseline comparison does not
qualify this new head. Exact-head run38925722087 at990f completed successfully:
all selected executable runtime/build/type/lint/ratchet/architecture leaves,
all nine selected UI browser shards, PostgreSQL conformance, security-fast and
aggregate openclaw/ci-gate117065729097 passed. All check-run pages were enumerated;
no failed or cancelled check remains. Applicable security boundary checks passed;
CodeQL concluded neutral. No rerun or inherited-failure exception is needed for
this head. Native review/preparation and verified merge are still required.