Skip to content

refactor(gateway): make reload restart transactional - #114368

Merged
steipete merged 1 commit into
mainfrom
codex/reload-transaction-v2
Jul 27, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/reload-transaction-v2

Conversation

@steipete

Copy link
Copy Markdown
Contributor
Additional instructions

MUST: Keep Allow edits from maintainers enabled for this PR so maintainers
can help update the branch when needed.

What Problem This Solves

Gateway reload restart state was spread across parallel nullable operation and accepted-target fields, making lifecycle, retry, deferral, and restart debt harder to reason about as one transaction. The split reload layout already had the right module owners but lacked a single discriminated transaction state.

Why This Change Was Made

GatewayRestartTransaction now owns restart lifecycle, retry, deferral, and debt. Discriminated unions replace the parallel nullable state, while deferred-work detail formatting is shared without changing log output. The change stays within the existing reload facade, hot/managed modules, active-work tracker, channel restart owner, and restart coordinator.

User Impact

No intended user-visible behavior change. Gateway reload restart bookkeeping is now represented as one explicit transaction, reducing invalid intermediate states and making deferred/retry behavior easier to maintain.

Evidence

  • Structural diff: 335 insertions, 286 deletions across three production files (net +49 non-test LOC), within the approved budget.
  • Reload-first proof: 110 tests passed across three focused files.
  • node scripts/check-changed.mjs passed on Blacksmith Testbox tbx_01kygwv5xwmrse1sxwrgj5jaav.
  • Final autoreview was clean with no findings (confidence 0.96).
  • A broader src/gateway sweep hit timing/E2E failures and leaked handles. The MCP close/drain failure and reload E2E revision failure reproduced identically on a clean origin/main archive, so they were classified as pre-existing rather than branch regressions.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: L maintainer Maintainer-authored PR labels Jul 27, 2026
@steipete steipete self-assigned this Jul 27, 2026
@steipete
steipete marked this pull request as ready for review July 27, 2026 06:24
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Jul 27, 2026
@clawsweeper

clawsweeper Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 27, 2026, 2:29 AM ET / 06:29 UTC.

ClawSweeper review

What this changes

This PR consolidates Gateway reload restart bookkeeping from parallel nullable fields into a discriminated transaction object, with shared deferred-work status formatting.

Merge readiness

⛔ Blocked until real behavior proof from a real setup is added - 5 items remain

Keep this PR open for maintainer review. It is a broad Gateway lifecycle refactor on a protected maintainer-labeled item, and the supplied evidence shows focused tests and checks but no after-fix real Gateway reload/restart run; that proof is needed before treating the behavioral preservation claim as merge-ready.

Priority: P2
Reviewed head: 6b92077b3cc40fbc3121bf00f6208d7682cbb00c
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The refactor has useful focused validation, but the required real behavior evidence for its lifecycle-preservation claim is absent.
Proof confidence 🧂 unranked krab (1/6) Needs real behavior proof before merge: The body reports focused tests and static checks, but no after-fix real Gateway reload/restart run is attached; please add redacted terminal output, runtime logs, or a recording that shows the actual lifecycle result. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The body reports focused tests and static checks, but no after-fix real Gateway reload/restart run is attached; please add redacted terminal output, runtime logs, or a recording that shows the actual lifecycle result. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 3 items Protected review route: The PR carries the maintainer label, which repository policy treats as requiring explicit maintainer handling rather than automated cleanup.
Changed lifecycle surface: The supplied PR diff centralizes reload restart state in GatewayRestartTransaction and threads a shared deferred-work formatter through the active-work and hot-reload modules.
Available validation is supplemental: The PR body reports 110 focused tests, a changed-check run, and autoreview, but it does not include an after-fix live reload/restart transcript, redacted runtime logs, recording, or comparable real behavior proof.
Findings None None.
Security None None.

How this fits together

Gateway reload accepts a new configuration, waits for active work when necessary, and coordinates channel and process restart behavior. This change sits in the restart coordinator between reload planning and the eventual restart/retry/defer outcomes.

flowchart LR
  A[Config reload request] --> B[Reload plan]
  B --> C[Active work tracker]
  C --> D[Restart transaction]
  D --> E{Defer, retry, or restart?}
  E --> F[Channel restart owner]
  E --> G[Gateway restart outcome]
Loading

Decision needed

Question Recommendation
Should this protected Gateway lifecycle refactor merge after maintainers review the transaction transitions and receive a real reload/restart proof trace? Require runtime proof and owner review: Request a redacted real Gateway reload trace that exercises deferral or retry, then review the transaction transitions before merge.

Why: The patch intentionally reorganizes state that governs retry and restart availability, so its correctness depends on behavioral equivalence rather than type and unit-test evidence alone.

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The body reports focused tests and static checks, but no after-fix real Gateway reload/restart run is attached; please add redacted terminal output, runtime logs, or a recording that shows the actual lifecycle result. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Resolve merge risk (P1) - The transaction class changes retry, deferral, accepted-target, and restart-debt state together; focused unit coverage alone does not demonstrate that a real reload preserves the prior defer/retry/restart behavior under active work.
  • Resolve merge risk (P1) - The maintainer label requires an explicit human merge judgment even if the final CI result is green.
  • Complete next step (P2) - A protected lifecycle refactor needs maintainer review and contributor-supplied real behavior proof, not an automated repair branch.
Agent review details

Security

None.

PR surface

Source +49. Total +49 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 3 335 286 +49
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 335 286 +49

Review metrics

None.

Merge-risk options

Maintainer options:

  1. Prove a live reload before merge (recommended)
    Run a real Gateway reload with active work or a deferred restart, then attach redacted terminal output or runtime logs showing the expected restart outcome.
  2. Pause for lifecycle-owner review
    Hold the PR if a representative real reload scenario cannot be run or its equivalence to the prior retry/defer behavior cannot be confirmed.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Attach redacted real Gateway reload evidence covering deferred or retrying work and the final restart outcome.

Technical review

Best possible solution:

Validate one real Gateway reload scenario covering active-work deferral followed by a successful restart, attach a redacted terminal transcript or runtime logs, and have the Gateway owner confirm that the transaction state preserves the intended lifecycle invariants.

Do we have a high-confidence way to reproduce the issue?

Not applicable as a refactor PR: no current user-facing bug is claimed. The missing merge evidence is a real after-fix reload/restart trace rather than reproduction of a reported failure.

Is this the best way to solve the issue?

Unclear. A single transaction is a plausible way to remove invalid parallel state combinations, but it should be accepted only after a Gateway owner confirms the actual retry, deferral, and restart transitions are behaviorally equivalent.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 054495d16dd6.

Labels

Label changes:

  • add P2: This refactor affects Gateway restart and retry behavior, a normal-priority availability-sensitive path with no demonstrated current user regression.
  • add merge-risk: 🚨 availability: The new transaction owns retry, deferral, and restart state, so an incorrect transition could stall or fail Gateway reload/restart behavior after merge.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The body reports focused tests and static checks, but no after-fix real Gateway reload/restart run is attached; please add redacted terminal output, runtime logs, or a recording that shows the actual lifecycle result. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Label justifications:

  • P2: This refactor affects Gateway restart and retry behavior, a normal-priority availability-sensitive path with no demonstrated current user regression.
  • merge-risk: 🚨 availability: The new transaction owns retry, deferral, and restart state, so an incorrect transition could stall or fail Gateway reload/restart behavior after merge.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The body reports focused tests and static checks, but no after-fix real Gateway reload/restart run is attached; please add redacted terminal output, runtime logs, or a recording that shows the actual lifecycle result. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

  • Protected review route: The PR carries the maintainer label, which repository policy treats as requiring explicit maintainer handling rather than automated cleanup. (6b92077b3cc4)
  • Changed lifecycle surface: The supplied PR diff centralizes reload restart state in GatewayRestartTransaction and threads a shared deferred-work formatter through the active-work and hot-reload modules. (src/gateway/server-reload-restart.ts:36, 6b92077b3cc4)
  • Available validation is supplemental: The PR body reports 110 focused tests, a changed-check run, and autoreview, but it does not include an after-fix live reload/restart transcript, redacted runtime logs, recording, or comparable real behavior proof. (6b92077b3cc4)

Likely related people:

  • steipete: The supplied PR metadata identifies steipete as author and assignee for this transaction-lifecycle change; deeper local history inspection was unavailable in this read-only environment. (role: current gateway refactor owner; confidence: low; commits: 6b92077b3cc4; files: src/gateway/server-reload-restart.ts, src/gateway/server-reload-hot.ts, src/gateway/server-reload-active-work.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Attach redacted output from a real Gateway reload that exercises deferred or retrying active work and shows the final restart result.
  • Have the Gateway lifecycle owner confirm the transaction's accepted-target, retry, and deferral transitions before merge.

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.

@steipete

Copy link
Copy Markdown
Contributor Author

Live active-work reload/restart proof

Ran the exact reviewed head 6b92077b3cc40fbc3121bf00f6208d7682cbb00c on Blacksmith Testbox, then built the source and exercised a real Gateway-dispatched agent turn against a delayed local OpenAI-compatible mock.

The state labels below map the production trace to GatewayRestartTransaction transitions at this head. Config A creates a pending request which the managed reload accepts/settles committed. Config B pauses the accepted target; because it retains the restart-owned value, the committed request details survive as debt and are re-armed, which is visible as the second deferral for the original restart reason. After the active run settles, the re-armed request emits SIGUSR1 and the restarted Gateway becomes RPC-ready.

2026-07-27T07:34:53.804Z PROOF-B exact source HEAD 6b92077b3cc40fbc3121bf00f6208d7682cbb00c
2026-07-27T07:34:53.804Z PROOF-B isolated state allocated; gateway port 44009 (default 18789 unused)
2026-07-27T07:35:01.128Z PROOF-B initial gateway RPC ready on port 44009
2026-07-27T07:35:01.129Z PROOF-B dispatching real Gateway agent turn
2026-07-27T07:35:06.502Z PROOF-B mock accepted agent request; holding response for 15000ms
2026-07-27T07:35:06.556Z PROOF-B mock accepted request; real agent turn is active

# request: pending -> committed; restart deferred on live work
2026-07-27T07:35:06.576Z PROOF-B config A written: gateway.controlUi.enabled requires restart (transaction pending -> committed)
2026-07-27T07:35:07.169+00:00 [reload] config change detected; evaluating reload (gateway.controlUi.enabled)
2026-07-27T07:35:07.200+00:00 [reload] config change requires gateway restart (gateway.controlUi.enabled) — deferring until 2 operation(s), 1 embedded run(s), 1 gateway request(s), 1 background task run(s) complete

# candidate pause/reject preserves committed restart debt; acceptance re-arms it
2026-07-27T07:35:07.401Z PROOF-B config B written: no-op UI change retains gateway.controlUi.enabled; committed restart debt must survive candidate pause
2026-07-27T07:35:07.985+00:00 [reload] config change detected; evaluating reload (ui.seamColor)
2026-07-27T07:35:09.035+00:00 [reload] config change requires gateway restart (gateway.controlUi.enabled) — deferring until 2 operation(s), 1 embedded run(s), 1 gateway request(s), 1 background task run(s) complete
2026-07-27T07:35:09.217Z PROOF-B restart debt re-armed: second gateway.controlUi.enabled deferral observed

# active work settles; committed retry emits and restart completes
2026-07-27T07:35:21.502Z PROOF-B mock releasing agent response
2026-07-27T07:35:21.647Z PROOF-B agent turn settled successfully
2026-07-27T07:35:22.068+00:00 [gateway] received SIGUSR1; restarting
2026-07-27T07:35:22.070+00:00 [reload] all operations and replies completed; restarting gateway now
2026-07-27T07:35:24.331Z PROOF-B restarted gateway RPC ready on port 44009
2026-07-27T07:35:24.331Z PROOF-B restart transaction completed; gateway RPC is healthy after restart

The agent call itself returned successfully:

{
  "runId": "b3dc163e-830b-4a14-9b75-78028c058877",
  "status": "ok",
  "text": "PROOF_B_TURN_COMPLETE"
}

No repository artifacts were committed, and this proof did not merge the PR.

@steipete

Copy link
Copy Markdown
Contributor Author

Rank-up move handling before landing:

  • The requested real active-work reload/restart proof is satisfied by the exact-head Testbox trace. A built Gateway accepted a real delayed agent turn, deferred the restart, preserved and re-armed committed restart debt across a second candidate, emitted SIGUSR1 only after active work settled, and returned RPC-ready after restart.
  • The Gateway lifecycle owner decision is accepted for this landing. The transaction's pending, accepted-target, committed-debt, retry, deferral, and completion states match the intended single-owner lifecycle; the repo-native review and prepare gates will still verify the final merge result.

@steipete
steipete merged commit 2bd4858 into main Jul 27, 2026
223 of 232 checks passed
@steipete
steipete deleted the codex/reload-transaction-v2 branch July 27, 2026 09:46
@steipete

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 merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: L status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant