Refactor error handling, logging, and model management in server - #2
Open
jaydennleemc wants to merge 16 commits into
Open
Refactor error handling, logging, and model management in server#2jaydennleemc wants to merge 16 commits into
jaydennleemc wants to merge 16 commits into
Conversation
…es, and load models from JSON
- Add logging options for color and detail in configuration - Implement detailed logging for API interactions - Introduce session cleanup for stale sessions - Refactor logging functions for consistency - Update API routes to utilize new logging methods
- client.mjs: Zen API HTTP request builders (renamed from zen.mjs) - to-openai.mjs / to-anthropic.mjs: directional format converters (split from converters.mjs) - pipe-openai.mjs / pipe-anthropic.mjs: response pipe per protocol (split from pipes.mjs) - utils.mjs: add shared checkFirstChunkError, eliminate duplication - to-openai.mjs: extract contentText helper, DRY text extraction - pipe-anthropic.mjs: add NO_CACHE const for usage - app.mjs: remove unused asyncHandler export
…ents - Add auto-retry (3 attempts, exponential backoff) on rate-limit errors for both streaming and synchronous paths - Fix stream-mode chunks array memory leak in pipe-openai.mjs - Fix content_block_stop protocol violation in pipe-anthropic.mjs - Fix session Map memory leak by adding periodic stale-entry cleanup - Refactor anthropicToOpenAI to reduce nesting depth - Use constant-time comparison for API key validation - Clean up global error handler to avoid res.end() after headers sent - Sync models table in README with models.json
Retry free-tier 429s with session rotation, backoff jitter, and client-abort stop; harden Express 5 body/listen handling; lock deps with npm ci and harden production compose (read-only rootfs, cap_drop, loopback bind).
Inject an empty reasoning_content field on assistant history messages so opencode.ai's Zen/Console provider accepts multi-turn continuations on thinking-mode models (fixes 'The reasoning_content in the thinking mode must be passed back to the API'). Map Anthropic thinking blocks to reasoning_content in the OpenAI converter.
The proxy logged "CLIENT GONE, aborting retries" immediately and returned without a response because Node fires req 'close' and sets req.destroyed as soon as the request body is fully consumed, even while the client is still connected and waiting. Detect real client disconnects from the response side (res 'close' before the response is sent) and rely on req.aborted for genuine early aborts, rather than req 'close' / req.destroyed. Fixes hangs on all three paths: /v1/chat/completions (sync + stream) and /v1/messages (sync).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces comprehensive Docker support and modernizes the project structure for the OpenCode Free Proxy. It adds production- and development-ready Dockerfiles and Compose files, a GitHub Actions workflow for automated image publishing, and modularizes the server codebase. Documentation has been expanded with a new
AGENTS.mdand updates toREADME.mdto reflect these changes and clarify usage. The top changes are grouped below:Dockerization and Deployment:
Dockerfilewith multi-stage builds, non-root user, and healthcheck for robust containerization.docker-compose.yamlfor secure production deployments (read-only rootfs, dropped capabilities, resource limits) anddocker-compose.dev.yamlfor hot-reload development with bind-mounts. [1] [2].dockerignoreto exclude development files and secrets from Docker builds..github/workflows/docker-publish.yml) to automate Docker image builds and pushes on tag or manual trigger.Project Structure and Codebase Modernization:
src/index.mjs, with Express app creation insrc/app.mjsand route separation. Updatedpackage.jsonscripts to use the new entry point and support testing. [1] [2] [3]src/config/index.mjs,src/logger.mjs,src/auth.mjs). [1] [2] [3]Documentation Updates:
AGENTS.mdwith a concise project overview, quick start, environment variables, file structure, and style guide.README.mdto reflect new commands, models, and Docker/systemd usage. [1] [2] [3]Model Management:
models.jsonwith the current list of supported models, referenced by the server and documentation.These changes collectively make the project easier to deploy, maintain, and extend, with clear separation of concerns and up-to-date documentation.