Skip to content

Comments

Claude/explain codebase mlo58wlz5o1uwxwa wiq er#586

Open
yinghuizhou wants to merge 6 commits intoWei-Shaw:mainfrom
yinghuizhou:claude/explain-codebase-mlo58wlz5o1uwxwa-wiqEr
Open

Claude/explain codebase mlo58wlz5o1uwxwa wiq er#586
yinghuizhou wants to merge 6 commits intoWei-Shaw:mainfrom
yinghuizhou:claude/explain-codebase-mlo58wlz5o1uwxwa-wiqEr

Conversation

@yinghuizhou
Copy link

No description provided.

zhouyinghuius-svg and others added 2 commits February 14, 2026 07:56
Automatically checks Wei-Shaw/sub2api daily and creates PR when updates are found.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ection

The OpenAI gateway's handleStreamingAwareError used fmt.Sprintf with %s
to embed errType and message directly into a JSON string. When upstream
error messages contain characters like `"` or `\` (e.g. 'model "gpt-xxx"
not found'), this produces malformed JSON that clients cannot parse.

Fix by using json.Marshal, consistent with the Claude gateway's
handleStreamingAwareError which already does this correctly.

https://claude.ai/code/session_01GzEbgf1NvhMq4mA4M6vQFg
@yinghuizhou
Copy link
Author

merged

Triggers on push to main or manual dispatch. SSHes into the server,
pulls latest code, builds Docker image locally, and restarts the
sub2api service via docker compose.

Requires GitHub Secrets: SERVER_HOST, SERVER_USER, SERVER_SSH_KEY, PROJECT_DIR.

https://claude.ai/code/session_01GzEbgf1NvhMq4mA4M6vQFg
… and auto-rollback

- 4-stage health verification: container status, HTTP health, DB/Redis, API smoke tests
- Automatic rollback on verification failure
- Auto-update mode via cron (--cron flag) for hands-off deployments
- Only deploys when new image is detected (--auto mode)
- Full deployment logging with timestamps
- Manual rollback support (--rollback)
- Status inspection (--status)

https://claude.ai/code/session_01GzEbgf1NvhMq4mA4M6vQFg
Architecture:
- Nginx reverse proxy as user entry point (zero-disconnect reload)
- Blue/Green dual instances behind Nginx
- Traffic only switches AFTER new instance passes all health checks

Deploy flow (users notice nothing):
1. Pull new image
2. Start standby instance (blue→green or green→blue)
3. 4-stage verification on standby (HTTP health, DB/Redis, API smoke, panic check)
4. Pass → Nginx reload to new instance → graceful shutdown old instance
5. Fail → Remove standby, production untouched

Files:
- safe-deploy.sh: Full blue-green orchestration with --init, --auto, --cron, --rollback
- docker-compose.bluegreen.yml: Dual sub2api instances + Nginx + PostgreSQL + Redis
- nginx/nginx.conf: Reverse proxy with SSE/streaming/WebSocket support
- nginx/upstream.conf: Dynamic upstream managed by safe-deploy.sh

https://claude.ai/code/session_01GzEbgf1NvhMq4mA4M6vQFg
Bugs found and fixed during thorough code audit:

1. [CRITICAL] upstream.conf: had "127.0.0.1:8081" instead of Docker hostname
   "sub2api-blue:8080" - Nginx would fail to resolve upstream on Docker network

2. [CRITICAL] do_init(): conditional write `if [ ! -f ]` meant the wrong
   upstream.conf from git would never be overwritten - now forces correct value

3. [HIGH] Nginx depends_on sub2api-blue: hard dependency caused failure when
   green was active and someone ran `docker compose up` - removed dependency,
   upstream.conf alone controls routing

4. [HIGH] nginx.conf Connection header: hardcoded "upgrade" on every request
   broke SSE streaming - now uses `map $http_upgrade` for conditional WebSocket
   upgrade only when client requests it

5. [MEDIUM] switch_nginx(): `docker exec ...; if [ $? -eq 0 ]` unreachable
   under `set -e` - changed to `if docker exec ...; then`

6. [MEDIUM] do_deploy() standby startup: complex `||` fallback chain had
   unpredictable behavior under `set -e` - simplified to explicit if/else
   with profile handling and post-startup running check

Also added: docker exec fallback for health checks when container IP is
unreachable (rootless Docker, non-standard network configs).

https://claude.ai/code/session_01GzEbgf1NvhMq4mA4M6vQFg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants