Skip to content

fix(gateway): prevent public chat 503s after startup - #167604

Merged
steipete merged 1 commit into
mainfrom
ci/fix3-palette-http-status
Oct 9, 2026
Merged

steipete merged 1 commit into
mainfrom
ci/fix3-palette-http-status

Conversation

@steipete

@steipete steipete commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes public chat links returning HTTP 503 after a successful Gateway startup instead of the normal not-found/login response.

User Impact

Public chat requests can read session state after startup completes. Interrupted startup still cancels and joins its Tailscale cleanup. No configuration, schema, or stored-state migration is involved.

Why This Change Was Made

An adjacent-commit bisect identifies 7d18cafe121a (#167514): server construction began running inside the startup work scope, which the CLI closes after successful boot. Resident HTTP resources inherited that already-aborted scope, so later reads returned “This conversation is temporarily unavailable.”

Construct resident resources outside the temporary work scope while preserving the startup operation's returned promise, explicit cancellation signal, and SDK-host context. The existing browser assertions remain unchanged.

Evidence

  • Linux clean builds: the unchanged real-Gateway command-palette test passes on parent c881d464aafe (50.50s), fails with 503 on 7d18cafe121a, and passes with this fix (48.65s Vitest; 99s including preparation). The reported good/bad heads and fresh main independently reproduce the same boundary.
  • Gateway startup/Tailscale owners: 4 files, 41 tests passed. Tailscale interruption, route ownership, and parent-loss owners: 5 files, 45 tests passed, preserving cleanup-once and joined-drain assertions.
  • Original 16-file real-Gateway shard: 20 tests passed; the API-key file refused artifact publication because the initial proof checkout contained an uncommitted production patch. Its unchanged test subsequently passed on clean commit 66c4c328ea0b after a real build (100s build, 80s test command); the runtime receipt records that exact head and inputsClean=true. No assertion or publication guard was changed.
  • Formatting, type-aware Oxlint, boundary lint, production types, all 27 selected test-type graphs, plugin boundaries, and the remaining changed-check/architecture guards passed.
  • Two aggregate checks remain red for failures reproduced identically on clean base 608134ea54c3: Madge reports the existing prepared-model-catalog-fingerprints/worker cycle; Knip reports four existing unused exports. Every unreached tail check was run separately and passed. No ignores or suppressions were added.
  • P2 autoreview: no actionable findings.

The Knip findings are bindCliQuestionAnswerAuthority, prepareSessionEventTargetForHost, readSessionEntryCreationTransition, and RESTART_CONTINUATION_CONTEXT_PREFIX; the last two also appear in the all-exports scan.

This is a Gateway lifecycle fix; UI appearance is unchanged. The existing headless browser flow supplies the HTTP and login-handoff regression proof. Full Gateway configurations were not rerun; proof covers the affected owners and the original real-Gateway shard.

Construct resident Gateway resources outside the transient startup work
scope. The CLI closes that scope after successful boot; HTTP listeners
must not inherit its aborted signal on later session reads.

Keep the startup promise tracked and the explicit cancellation signal,
Tailscale cleanup, and SDK-host context intact. This repairs the lifetime
regression introduced by 7d18caf (#167514).

The unchanged real-Gateway command-palette flow reproduces the 503 on the
producer and passes with this change. Interrupted-start and Tailscale
ownership tests retain their existing assertions. P2 review is clean.
@clawsweeper

clawsweeper Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: XS labels Oct 9, 2026
@steipete
steipete marked this pull request as ready for review October 9, 2026 04:27
@steipete
steipete enabled auto-merge (squash) October 9, 2026 04:30
@clawsweeper

clawsweeper Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Constructs resident Gateway resources outside the temporary startup work scope while preserving explicit startup cancellation and cleanup.

Example: Open /chat/main after Gateway startup

  • Before: The request returns HTTP 503 with “This conversation is temporarily unavailable. Please retry.”
  • After: The unchanged browser flow receives the expected HTTP 404 and completes the login handoff.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with matching reported shipped-entry-point regression proof and no actionable findings.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The fully read body reports an unchanged browser flow against a built, isolated Linux Gateway: /chat/main fails with 503 before the repair and returns the expected 404 with successful login handoff afterward. Source confirms that this exercises the affected resident HTTP/session-read lifetime; supplemental interruption tests cover retained cancellation cleanup. No stored-data contract changes.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Chat links display a temporary-unavailable error even after the Gateway starts successfully.
Reason: This restores an established HTTP flow with a small repair at the startup owner. Prior area history and the stated cancellation intent support preserving startup cleanup while separating resident lifetimes.

Regression provenance

Regression provenance — verified: source commit 7d18cafe121a by Peter Steinberger; canonical PR #167514 (blame-to-merge-commit).

Merge readiness

✅ Ready for maintainer review

This PR repairs a current-main startup-lifetime regression with a focused change and matching real-Gateway regression evidence. No actionable patch defect was found.

Priority: P1
Reviewed head: 66c4c328ea0b83be1d977b01526f28b65c0e1deb

Before merge

None.

Findings

None.

Agent review details

How this fits together

The Gateway starts HTTP listeners and session readers that remain active after boot completes. Its temporary startup scope joins boot work, while resident resources and normal shutdown have separate lifetimes.

flowchart TD
  A[Gateway CLI startup] --> B[Temporary startup scope]
  B --> C[Tracked startup promise]
  C --> D[Resident Gateway construction]
  B --> E[Explicit cancellation signal]
  E --> F[Tailscale startup cleanup]
  D --> G[HTTP listeners and session readers]
  G --> H[Chat response after boot]
Loading

Technical review

Best possible solution:

Keep resident Gateway resources under their normal runtime lifetime while startup owns its returned promise and explicit cancellation cleanup.

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

Yes: the unchanged real-Gateway browser flow provides a concrete reproduction path, and source explains how successful boot aborts the scope inherited by later session reads. The reviewer did not execute that path.

Is this the best way to solve the issue?

Yes: detaching resident construction at the startup owner fixes the lifetime mismatch without weakening session-read checks or duplicating HTTP-specific recovery.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 62355575c041.

Provenance checked

  • src/gateway/server-start.ts startup-operation construction keeps the original intent (7d18caf: Retain cancellation and cleanup ownership for interrupted Tailscale startup until the full Gateway close handle is published.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Focused lifetime repair: The introduced diff exits only the async work-scope carriers around server construction; the startup callback still returns its promise and forwards the explicit cancellation signal. (src/gateway/server-start.ts:24, 66c4c328ea0b)
  • Cancellation mechanism: The CLI closes startup operations after receiving the server handle. Closing aborts the temporary scope; session readiness reads reject an inherited aborted signal. The existing detach helper clears work ownership without clearing the separate SDK-host context. (src/cli/gateway-cli/run-loop.ts:1238, 66c4c328ea0b)
  • Current main still needs the repair: The touched file is unchanged between the merge base and fetched main. The verified test merge has the pinned main and PR head as its two parents and introduces only this repair. (src/gateway/server-start.ts:23, 62355575c041)
  • Real-Gateway regression evidence: The fully read PR body reports clean Linux builds where the unchanged command-palette browser flow passes on the earlier parent, fails with HTTP 503 after the startup-scope change, and passes with this repair. The inspected test starts an isolated Gateway, navigates to /chat/main, asserts HTTP 404, and completes session entry. These are contributor-reported observations; this read-only review did not execute them. (ui/src/e2e/command-palette-search.real-gateway.e2e.test.ts:378, 66c4c328ea0b)
  • Preserved interrupted-start intent: fix(gateway): stop the Tailscale serve process when a start is interrupted #167514 introduced tracked startup construction to stop and join owned Tailscale exposure when boot is interrupted. This PR retains its explicit signal, abort listener, cleanup join, and startup promise tracking. (src/gateway/server-start.ts:80, 7d18cafe121a)
  • Area history: The feature-history search identifies the startup-operation change, and recent file history plus shortlog repeatedly connect Peter Steinberger to Gateway startup and resource-lifetime maintenance. (src/gateway/server-start.ts:29, 7d18cafe121a)

Likely related people:

  • Peter Steinberger: Raw commit 7d18caf adds src/gateway/server-start.ts:25 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 7d18cafe121a; files: src/gateway/server-start.ts)

PR surface

Source +4. Total +4 across 1 file. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 5 1 +4
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 1 5 1 +4

Labels

Label changes:

  • add P1: The reported current-main regression makes chat links return HTTP 503 after otherwise successful Gateway startup.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P1: The reported current-main regression makes chat links return HTTP 503 after otherwise successful Gateway startup.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only; repair and merge need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

Reviewed October 9, 2026, 12:32 AM ET / 04:32 UTC.

@steipete
steipete merged commit 14b9d90 into main Oct 9, 2026
183 checks passed
@steipete
steipete deleted the ci/fix3-palette-http-status branch October 9, 2026 04:36
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 10, 2026
Construct resident Gateway resources outside the transient startup work
scope. The CLI closes that scope after successful boot; HTTP listeners
must not inherit its aborted signal on later session reads.

Keep the startup promise tracked and the explicit cancellation signal,
Tailscale cleanup, and SDK-host context intact. This repairs the lifetime
regression introduced by cc82cda (openclaw#167514).

The unchanged real-Gateway command-palette flow reproduces the 503 on the
producer and passes with this change. Interrupted-start and Tailscale
ownership tests retain their existing assertions. P2 review is clean.
RomneyDa pushed a commit that referenced this pull request Oct 14, 2026
…upted (#167514)

A Gateway restarted during startup could leave the root tailscale serve it launched through sudo -n holding HTTPS 443: the route-owner worker signaled the sudo-owned group without privilege, and startup only published Tailscale cleanup after readiness, so every later start refused with exit 78 until the process was killed by hand. The worker now stops its owned process group through sudo -n and reports a stop failure with the exact command; startup cancellation reaches backend readiness, the route claim and hostname lookup, and stops the serve it started. Unproven foreign routes are still never touched; the refusal now names how to find and stop the claimant. Closes #167436. Reported by @pandysp.
(cherry picked from commit 7d18caf)
Backport adaptation: kept the release's manual startup-timeout promise (adding the abort listener and stop-failed handling there instead of raceWithTimeout) and its hostname catch, and folded in the runOutsideAsyncWorkScope follow-up from 14b9d90 (#167604) so resident listeners do not inherit the closed startup scope.
RomneyDa pushed a commit that referenced this pull request Oct 14, 2026
Construct resident Gateway resources outside the transient startup work
scope. The CLI closes that scope after successful boot; HTTP listeners
must not inherit its aborted signal on later session reads.

Keep the startup promise tracked and the explicit cancellation signal,
Tailscale cleanup, and SDK-host context intact. This repairs the lifetime
regression introduced by 7d18caf (#167514).

The unchanged real-Gateway command-palette flow reproduces the 503 on the
producer and passes with this change. Interrupted-start and Tailscale
ownership tests retain their existing assertions. P2 review is clean.

(cherry picked from commit 14b9d90)
RomneyDa added a commit that referenced this pull request Oct 15, 2026
…when Serve is denied (#171819)

* fix(gateway): stop the Tailscale serve process when a start is interrupted (#167514)

A Gateway restarted during startup could leave the root tailscale serve it launched through sudo -n holding HTTPS 443: the route-owner worker signaled the sudo-owned group without privilege, and startup only published Tailscale cleanup after readiness, so every later start refused with exit 78 until the process was killed by hand. The worker now stops its owned process group through sudo -n and reports a stop failure with the exact command; startup cancellation reaches backend readiness, the route claim and hostname lookup, and stops the serve it started. Unproven foreign routes are still never touched; the refusal now names how to find and stop the claimant. Closes #167436. Reported by @pandysp.

Backport adaptation: 2026.9.33 has no raceWithTimeout, so startTailscaleRouteOwner keeps its manual startupTimer promise and gains the stop-failed branch plus an abort listener that settles startup with the signal reason and is removed on settle. The 9.33 racePromiseWithAbortSignal takes no reason mapper, so the hostname race catches its abort-only rejection and rethrows the signal reason through throwIfAborted; the 9.33 .catch(() => null) on the hostname lookup is kept. server-start.ts keeps the 9.33 kernel destructure including beginClosePrelude and adds tailscaleStopping/stopStartingTailscale. The claim test keeps the 9.33 it.for authority matrix and adds the cancelled-claim case.

(cherry picked from commit 7d18caf)

* fix(gateway): keep local access when tailnet denies Serve (#171509)

Backport adaptation: 2026.9.33 keeps the manual startupTimer promise instead of raceWithTimeout, so the timer callback sets startupDeadlineExpired before settling and routeClaimError receives mode and that flag from the worker failure handler. The stop-failure check sits on the 9.33 waitWithTimeout helper instead of settlesWithin. The claim test drops main's stopped-daemon test, which was only diff context and depends on backend-stopped handling that 9.33 does not ship.

(cherry picked from commit f122878)

* fix(gateway): reject Tailscale startup with an Error when the claim is interrupted

* fix(gateway): prevent public chat 503s after startup (#167604)

Construct resident Gateway resources outside the transient startup work
scope. The CLI closes that scope after successful boot; HTTP listeners
must not inherit its aborted signal on later session reads.

Keep the startup promise tracked and the explicit cancellation signal,
Tailscale cleanup, and SDK-host context intact. This repairs the lifetime
regression introduced by 7d18caf (#167514).

The unchanged real-Gateway command-palette flow reproduces the 503 on the
producer and passes with this change. Interrupted-start and Tailscale
ownership tests retain their existing assertions. P2 review is clean.

(cherry picked from commit 14b9d90)

---------

Co-authored-by: Peter Steinberger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant