Skip to content

feat: SOCKS5 outbound + Claude instructions cache stabilize - #1

Open
Warexpor wants to merge 5 commits into
devfrom
cursor/feat-claude-instructions-cache-stabilize-0d69
Open

feat: SOCKS5 outbound + Claude instructions cache stabilize#1
Warexpor wants to merge 5 commits into
devfrom
cursor/feat-claude-instructions-cache-stabilize-0d69

Conversation

@Warexpor

@Warexpor Warexpor commented Sep 8, 2026

Copy link
Copy Markdown
Owner

Summary

This branch is for Warexpor/opencodex only. It is not the upstream PR to lidge-jun/opencodex; that discussion is next.

Upstream sync. Fork dev was ~1560 commits behind lidge-jun/opencodex dev. It has been fast-forwarded to current upstream dev. This PR is rebased onto that tip.

SOCKS5 outbound. feat/outbound-socks5 was far behind current integration, so the work is re-applied onto today's dev rather than a raw rebase. Semantics preserved:

  • ocx start --socks5 [host:port] (default socks5://127.0.0.1:10808) writes config.proxy and mirrors it to ALL_PROXY.
  • --socks5-off clears only a saved SOCKS5 config.proxy.
  • HTTP(S) config.proxy still fills HTTP_PROXY/HTTPS_PROXY when unset.
  • SOCKS5 URLs use a dependency-free tunnel (src/lib/socks5-fetch.ts) with NO_PROXY, auth, streaming, and abort support. Codex WS falls back to SSE while SOCKS5 is configured (Clash mixed-port HTTP_PROXY cannot CONNECT a SOCKS listener).

Claude prompt-cache stabilize. Claude Code Anthropic→Responses translation puts system text into top-level instructions. Claude Code appends growing <total_tokens>…</total_tokens> footers (and occasional TaskCreate nudges) into that system text each turn, so instructions churns and Muse/Go prefix cache collapses even when tools stay stable. This change strips those dynamics from instructions and appends the latest notice as a trailing Responses input user message so the model still sees current budget without poisoning the cached prefix. tools and prompt_cache_key logic are unchanged.

Measured in a controlled suite on Muse Spark via Go: Claude hit-rate ~0.17 → ~0.86 after this stabilize. No extra tables.

Go session header. Fork main carried a second x-opencode-session helper. Current dev already does this via resolveOpenCodeGoTransport (opaque ocx_ ids, canonical HTTPS Go destination, omit when Claude has no usable identity). The duplicate path matched http://opencode.ai/zen/go/v1 and always filled a header, which failed Cross-platform CI. It is dropped; the existing dev affinity path is unchanged.

Verification

After dropping the duplicate Go session helper (all pass):

  • bun test tests/adapters/routed-agent-messages.test.ts — pass (includes http://opencode.ai/zen/go/v1 Go-like destination)
  • bun test tests/providers/opencode-go-session-header.test.ts — pass (Claude omit-affinity cases included)
  • bun test tests/ci-workflows/repo-hygiene.test.ts tests/test-layout.test.ts tests/test-layout-tooling.test.ts — pass (no duplicate basenames; layout membership agrees)
  • bun test tests/cli/start-args.test.ts tests/server/socks5-fetch.test.ts tests/server/proxy-env.test.ts — pass
  • bun test tests/claude-integration/claude-inbound-cache-stabilize.test.ts tests/claude-integration/claude-inbound.test.ts — pass
  • bun test tests/responses/responses-fetch-helpers-boundary.test.ts — pass
  • bun test tests/responses/ws-upstream.test.ts -t "uses HTTP SSE when SOCKS5 outbound transport is configured" — pass
  • bun run typecheck — pass
  • bun run privacy:scan — pass

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults.
Open in Web Open in Cursor 

@github-actions github-actions Bot added the enhancement New feature or request label Sep 8, 2026
@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown

Deterministic PR hygiene checks passed.

@github-actions github-actions Bot changed the title feat: SOCKS5 outbound + Claude instructions cache stabilize [WRONG BRANCH] feat: SOCKS5 outbound + Claude instructions cache stabilize Sep 8, 2026
@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown

✅ READY

  • all PR quality gates passed.

Hygiene

Deterministic PR hygiene checks passed.

@Warexpor
Warexpor marked this pull request as ready for review September 8, 2026 16:22
@github-actions
github-actions Bot marked this pull request as draft September 8, 2026 16:23
Warexpor and others added 4 commits September 8, 2026 16:24
OpenCode Go rejects requests without a stable session header; derive one from thread identity when present and attach it on Anthropic/Chat/Responses adapters.
Port Warexpor's SOCKS5 work from feat/outbound-socks5 onto upstream-synced
main. Clash mixed-port HTTP_PROXY cannot CONNECT a SOCKS listener, so
`ocx start --socks5` persists socks5:// into config.proxy and ALL_PROXY
and routes HTTP(S) through a dependency-free SOCKS5 tunnel.

Preserves current HTTP(S) proxy, NO_PROXY, and Mihomo fake-IP pinning
behavior; Codex WS falls back to SSE when SOCKS5 is configured.

Co-authored-by: Warexpor <warexpor@gmail.com>
Claude Code appends growing <total_tokens> footers (and occasional
TaskCreate nudges) into system text that becomes Responses instructions.
That churn collapses Muse/Go prefix cache even when tools stay stable.

Strip those dynamics from instructions and append the latest notice as a
trailing Responses input user message so the model still sees current
budget without poisoning the cached prefix. prompt_cache_key and tools
are unchanged.

Co-authored-by: Warexpor <warexpor@gmail.com>
The x-opencode-session commit left tests/opencode-go-session.test.ts at
the tests/ root, which the layout guard treats as a migrated-domain
straggler. Move it next to the existing header coverage.

Co-authored-by: Warexpor <warexpor@gmail.com>
@cursor
cursor Bot force-pushed the cursor/feat-claude-instructions-cache-stabilize-0d69 branch from b1f43b2 to 6325b4b Compare September 8, 2026 16:25
@cursor cursor Bot changed the title [WRONG BRANCH] feat: SOCKS5 outbound + Claude instructions cache stabilize feat: SOCKS5 outbound + Claude instructions cache stabilize Sep 8, 2026
@cursor
cursor Bot changed the base branch from main to dev September 8, 2026 16:25
@github-actions
github-actions Bot marked this pull request as ready for review September 8, 2026 16:25
Upstream dev already attaches x-opencode-session via
resolveOpenCodeGoTransport (opaque ocx_ ids, HTTPS canonical
destination, omit when Claude has no usable identity). The fork
main helper matched http://opencode.ai/zen/go/v1 and always
filled a header from session-id / first-user text, which broke
routed-agent-messages and OpenCode Go session affinity tests.

Co-authored-by: Warexpor <warexpor@gmail.com>
Warexpor added a commit that referenced this pull request Sep 8, 2026
Local-test land on fork main (same tip as PR #1).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants