Skip to content

Conversation

@fengtality
Copy link
Contributor

@fengtality fengtality commented Dec 3, 2025

Summary

  • Fix race condition when restarting Gateway server via /restart endpoint
  • Add gateway.sh wrapper script for managing Gateway lifecycle
  • Add PID file tracking (gateway.pid) to prevent duplicate instances
  • Add /status and /stop endpoints for server lifecycle management

Changes

  • app.ts: Add PID file management and graceful shutdown handling
  • server.routes.ts: Add /status and /stop endpoints
  • gateway.sh: New wrapper script with start, stop, restart, status commands
  • .gitignore: Add gateway.pid to ignored files

Test plan

  • Start Gateway with ./gateway.sh start
  • Verify /restart endpoint works without race condition
  • Verify /status returns server info
  • Verify ./gateway.sh stop gracefully stops server
  • Verify duplicate instances are prevented

Fixes #414

fengtality and others added 9 commits December 3, 2025 14:30
Remove detached process spawning from /restart endpoint. Instead:
- Add PID file tracking (gateway.pid) for process management
- Kill any existing gateway process on startup using PID file
- On restart, simply exit - let process managers handle restart
- Clean up PID file on graceful shutdown

This matches the simpler approach used in gateway v2.2.0 and prevents
orphan processes that were being created by the old spawn mechanism.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Add a shell script wrapper that manages the Gateway server lifecycle:
- `./gateway.sh start [--dev]` - Start Gateway with auto-restart on config changes
- `./gateway.sh stop` - Stop Gateway and wrapper
- `./gateway.sh restart` - Request restart via API
- `./gateway.sh status` - Show running status

The wrapper process monitors exit codes:
- Exit code 0: Restart requested (wrapper restarts Gateway)
- Exit code 1: Shutdown requested (wrapper stops)

This enables seamless restarts when clients update config values,
as the wrapper automatically restarts Gateway after it exits.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Change start script from direct node invocation to gateway.sh
- Add --passphrase argument support to gateway.sh
- Users can now use: pnpm start --passphrase=<pass> [--dev]
- Wrapper provides auto-restart on config changes

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add /status endpoint with version, uptime, mode, pid
- Add /stop endpoint to shut down without restart
- Move server routes to src/server/server.routes.ts for Swagger visibility
- Update gateway.sh to run in foreground (logs visible in terminal)
- Add pnpm stop and pnpm status commands

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Remove helius and infura namespace references from root.yml since the
rpc-provider-schema.json and rpc/ directory were previously removed.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add AlphaRouterService for smart order routing across V2/V3 pools
- Update quoteSwap to use AlphaRouter instead of UniversalRouterQuote
- Pass slippagePct parameter through to AlphaRouter
- Upgrade @uniswap/smart-order-router to v4.22.38

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@fengtality fengtality added this to the dev-2.12 milestone Dec 4, 2025
fengtality and others added 7 commits December 3, 2025 17:34
- Add maximumSplits config option to pancakeswap.yml
- Pass maxHops and maxSplits from config to SmartRouter.getBestTrade()
- Update Uniswap quoteSwap test to use AlphaRouterQuoteResult mock format

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
…Router

For EXACT_OUTPUT trades, the AlphaRouter's route() method expects the
quoteCurrency to be the input token (what we pay), not the output token.
The previous code always passed tokenOut, which caused "Invariant failed:
ADDRESSES" errors when getting BUY quotes because the V4 pool provider
tried to compare a token with itself.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
…tions

- handleTransactionExecution now returns null for pending transactions
  instead of a fake receipt with status:0 (which means reverted in ethers)
- handleExecuteQuoteTransactionConfirmation now accepts txHash parameter
  to return the transaction hash for pending transactions
- Fixed status code mapping to match Hummingbot's TransactionStatus:
  - CONFIRMED = 1
  - PENDING = 0
  - FAILED = -1
- Track txHash immediately after sending transaction in executeQuote

Previously, pending transactions were incorrectly marked as failed because
the fake receipt had status:0, which in Ethereum means the transaction
reverted on-chain.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Move detailed AlphaRouter and quoteSwap logs from info to debug level,
keeping only essential messages at info for cleaner production logs.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Base automatically changed from refactor/http-errors to development December 9, 2025 12:55
@fengtality fengtality marked this pull request as ready for review December 9, 2025 18:31
@rapcmia rapcmia moved this to Under Review in Pull Request Board Dec 15, 2025
@rapcmia rapcmia moved this from Under Review to Backlog in Pull Request Board Dec 15, 2025
@rapcmia rapcmia moved this from Backlog to Under Review in Pull Request Board Dec 16, 2025
@rapcmia
Copy link
Contributor

rapcmia commented Dec 16, 2025

Commit 8b8b3e9

  • Setup with hummingbot dev branch
  • When starting gateway instance, observe added logs related to PID
    2025-12-16 03:22:48 | info |    PID file written: /home/yawnyunehh/hummingbot/gateway/567/gateway.pid (PID: 2338562)   │
    

Start with ./gateway.sh start

  • secure mode ✅
    image
  • dev mode ✅
    image
  • Start with two instance of gateway, returns gateway wrapper is already active ✅
    image
    • Prevents two gateway instances running, returns that gateway already active ✅
    • Test compare with development branch, old gateway crashed
  • Start with invalid passphrase, script continue to execute upon restart ❌
    image
    • Gateway fails to initialized then restarts, repeat itself until user to cancel/stop the script

Run ./gateway.sh stop

  • secure mode ✅
    image
  • dev mode ✅
    image
  • When the stop endpoint is called while the Gateway is inactive, the response returns “No active gateway.” ✅
image

Verify /restart endpoint works


Run ./gateway.sh status

  • secure mode ✅
    image
    • I assume this is expected since endpoints are served on HTTPS instead of HTTP
  • dev mode ✅
    image
  • Without active gateway
    image

Pending tests:

  • Check docker build gateway with hummingbot
  • Check gateway changes with hummingbot-api + condor

rapcmia
rapcmia previously approved these changes Dec 17, 2025
@rapcmia rapcmia moved this from Under Review to Backlog in Pull Request Board Dec 17, 2025
@rapcmia rapcmia dismissed their stale review December 17, 2025 14:50

Dev team will need time to review and redesign the fix

@rapcmia rapcmia moved this from Backlog to In Discussion in Pull Request Board Dec 22, 2025
fengtality and others added 2 commits December 23, 2025 11:40
- Add intermediate token lists for each network (BSC, mainnet, arbitrum, base)
- Refactor pool discovery to search for pools through intermediate tokens
- Enable multi-hop routes like LINK -> WBNB -> DAI
- maximumHops and maximumSplits config options now work correctly
- Fixes "No routes found" error for token pairs without direct pools

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Fix extractRoutePath to use route.path array which contains all tokens
  including intermediates (e.g., LINK -> WBNB -> DAI)
- Add percentage display for split routes (e.g., "50% via LINK -> WBNB -> DAI")
- Change route join separator from ' -> ' to ', ' for multiple split routes
- Add tests to verify routePath format includes percentage and token path

Before: "LINK -> DAI -> LINK -> DAI -> LINK -> DAI" (wrong)
After: "100% via LINK -> WBNB -> DAI" (correct)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@rapcmia rapcmia removed this from the v2.12 milestone Jan 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Discussion

Development

Successfully merging this pull request may close these issues.

4 participants