Skip to content

Refactor error handling, logging, and model management in server - #2

Open
jaydennleemc wants to merge 16 commits into
bigdata2211it-web:mainfrom
jaydennleemc:main
Open

Refactor error handling, logging, and model management in server#2
jaydennleemc wants to merge 16 commits into
bigdata2211it-web:mainfrom
jaydennleemc:main

Conversation

@jaydennleemc

Copy link
Copy Markdown

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.md and updates to README.md to reflect these changes and clarify usage. The top changes are grouped below:

Dockerization and Deployment:

  • Added a production-ready Dockerfile with multi-stage builds, non-root user, and healthcheck for robust containerization.
  • Introduced docker-compose.yaml for secure production deployments (read-only rootfs, dropped capabilities, resource limits) and docker-compose.dev.yaml for hot-reload development with bind-mounts. [1] [2]
  • Added .dockerignore to exclude development files and secrets from Docker builds.
  • Implemented a GitHub Actions workflow (.github/workflows/docker-publish.yml) to automate Docker image builds and pushes on tag or manual trigger.

Project Structure and Codebase Modernization:

  • Modularized the server: entry point moved to src/index.mjs, with Express app creation in src/app.mjs and route separation. Updated package.json scripts to use the new entry point and support testing. [1] [2] [3]
  • Added robust configuration, logging, and authentication helpers (src/config/index.mjs, src/logger.mjs, src/auth.mjs). [1] [2] [3]

Documentation Updates:

  • Added AGENTS.md with a concise project overview, quick start, environment variables, file structure, and style guide.
  • Updated README.md to reflect new commands, models, and Docker/systemd usage. [1] [2] [3]

Model Management:

  • Added models.json with 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.

Jayden Lee and others added 15 commits July 22, 2026 10:38
- 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
- Version now read from package.json (0.1.1)
- Remove cleanup timer and dead sessionCount from session.mjs
- DRY zero cache tokens in converters.mjs
- Move response parsers from logger.mjs to pipes.mjs
- Add GitHub Action workflow for Docker Hub publish (tag-driven)
- 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).
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.

1 participant