Skip to content

fix(setup): strip conflicting ANTHROPIC_AUTH_TOKEN - #16

Merged
wangcansunking merged 1 commit into
masterfrom
worktree-auth-token-fix
Jun 29, 2026
Merged

wangcansunking merged 1 commit into
masterfrom
worktree-auth-token-fix

Conversation

@wangcansunking

Copy link
Copy Markdown
Owner

Summary

Note: only fixes the token if it lives in settings.json; a shell-env ANTHROPIC_AUTH_TOKEN must be unset manually.

Test plan

  • new test: applyClaude strips stale AUTH_TOKEN, preserves other keys
  • 422 pass, build clean

🤖 Generated with Claude Code

…ps warning

setup_claude now removes a leftover ANTHROPIC_AUTH_TOKEN from settings.json (we auth via
ANTHROPIC_API_KEY); having both made Claude Code warn "both set · auth may not work".
reset-claude also clears it. Pure settings.json hygiene; shell-env tokens are unaffected.

Co-Authored-By: Claude <noreply@anthropic.com>
@wangcansunking
wangcansunking merged commit 8c47fc5 into master Jun 29, 2026
5 checks passed
@wangcansunking
wangcansunking deleted the worktree-auth-token-fix branch June 29, 2026 05:41
wangcansunking added a commit that referenced this pull request Jun 29, 2026
Merged PRs #11-#16 shipped no changeset, so release.yml skipped every
publish and npm stayed at 0.5.3. Document the rule so it stops recurring.

Co-Authored-By: Claude <noreply@anthropic.com>
@wangcansunking wangcansunking mentioned this pull request Jun 29, 2026
2 of 3 tasks
wangcansunking added a commit that referenced this pull request Jul 2, 2026
…cli-e2e mandate

Add CLI e2e case #16: a browser-harness-style pile of 11 tool_result
screenshots posted to /anthropic/v1/messages against live Copilot. Asserts
(a) the request is well-formed, (b) it never 413s (context editing kept the
body under the gateway entity limit), and (c) Claude still reads the MOST
RECENT screenshot (answers 'green') — proving old screenshots were cleared and
recent ones preserved. This is the black-box repro of the reported 413.
Verified green end-to-end against real Copilot.

Also record the pre-merge gate in CLAUDE.md: run the real cli-e2e against live
Copilot and confirm pass before merging any worktree branch (http-e2e alone is
not sufficient), with the Windows/Git Bash mount command.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
wangcansunking added a commit that referenced this pull request Jul 2, 2026
…ntic sessions (#49)

* feat(context-edit): clear old tool screenshots to fix 413 on long agentic sessions

A browser-harness loop emits one screenshot per step, and the stateless wire
re-sends the whole history every turn, so cumulative base64 grows until Copilot's
gateway rejects the request body at the HTTP layer (413 Request Entity Too Large,
relayed as 502). This is a byte-size limit, distinct from the token limit the
image-downscale fix targets — per-image resize alone can't satisfy it.

The real Anthropic backend handles this server-side via context editing
(clear_tool_uses_20250919): keep the most recent few tool results, replace older
ones with a placeholder. Claude Code relies on it and keeps sending full history;
Copilot has no such layer. We now sit where that layer would:

- new core/context-edit.ts keeps the most recent 3 tool screenshots at full
  fidelity and clears older ones oldest-first (image -> placeholder text) once the
  cumulative image payload exceeds a ~6MB budget, only as much as needed. Lossless
  no-op when under budget; never touches top-level user-attached images.
- wired AFTER resize on all send paths (/anthropic/v1/messages,
  /openai/chat/completions, /openai/responses) AND count_tokens, so the estimate
  matches what's sent.
- errorHint gains a 413 branch (request too large -> /compact or fewer images).

Tests: new tests/core/context-edit.test.ts (7 cases) + 413 hint case + hermetic
http-e2e (12 accumulated screenshots under the per-image cap, count_tokens lands
far below raw sum -> proves clearing not resizing). 588 unit green; docker
http-e2e ALL PASSED (63); tsc clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* test(cli-e2e): real context-editing screenshot-pile case + pre-merge cli-e2e mandate

Add CLI e2e case #16: a browser-harness-style pile of 11 tool_result
screenshots posted to /anthropic/v1/messages against live Copilot. Asserts
(a) the request is well-formed, (b) it never 413s (context editing kept the
body under the gateway entity limit), and (c) Claude still reads the MOST
RECENT screenshot (answers 'green') — proving old screenshots were cleared and
recent ones preserved. This is the black-box repro of the reported 413.
Verified green end-to-end against real Copilot.

Also record the pre-merge gate in CLAUDE.md: run the real cli-e2e against live
Copilot and confirm pass before merging any worktree branch (http-e2e alone is
not sufficient), with the Windows/Git Bash mount command.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
wangcansunking added a commit that referenced this pull request Jul 2, 2026
…kable keep-floor (413 came back) (#53)

* fix(context-edit): budget below the probed 5 MiB gateway limit + breakable keep-floor

The context-editing 413 fix still 413'd on real long screenshot sessions. Two
defects, both from a budget that was never measured against the real limit:

1. IMAGE_PAYLOAD_BUDGET was 6MB — ABOVE Copilot's gateway HTTP entity limit,
   which I probed at exactly 5 MiB (a ~4.95MB body returns 400/accepted; a
   5.00MB body returns 413). Because the budget sat above the wall, context
   editing believed an over-limit payload was 'within budget' and forwarded it
   straight into a 413. Lowered to 3.5MB (>=1.5MB headroom for text/tools/JSON).

2. keep=3 was a HARD floor: the most recent 3 screenshots were never cleared,
   so if they alone exceeded the limit the body still 413'd. keep is now a
   preference — if clearing everything older isn't enough, clearing breaks
   through the floor oldest-first (up to and including the newest). A request
   that still 413s is strictly worse than one missing a recent screenshot.

Tests: budget-below-gateway-limit regression, floor-break test, and an http-e2e
assertion that the edited payload (tokens*4 bytes) fits under 5 MiB. 597 unit
green; docker http-e2e ALL PASSED (67); tsc clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* test(cli-e2e): stress case #16 with a ~9.5MB screenshot pile (proves the budget fix)

The original case #16 used solid-color 200x200 PNGs that zlib-compress to a few
hundred bytes each — an 11-screenshot pile was tiny and never actually reached
the gateway limit, so it passed even with the buggy 6MB budget. Rewrite it to
use high-entropy noise PNGs (~0.95MB base64 each, under the 1.5MB per-image
resize cap so resize passes them through), 10 of them summing to ~9.5MB unedited
— well over the probed 5 MiB wall. Against live Copilot this now genuinely
proves context editing clears down under the limit: no 413, and Claude still
reads the most-recent green screenshot. The pre-fix 6MB budget would leave ~6MB
and still 413 this.

Verified: case #16 PASS (unedited ~9.5MB -> Green, no 413) against real Copilot.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
wangcansunking added a commit that referenced this pull request Jul 3, 2026
 #52) (#54)

* fix(context-edit): dynamic whole-body budget + reactive 413 retry (issue #52 follow-up)

Issue #52: the 413 returns when a screenshot-heavy session ALSO carries a large
conversation. The 413 is on the WHOLE request body, but context editing budgeted
only image bytes against a fixed 3.5MB cap — so a ~700k-token transcript (~2.7MB
text) + 3 kept screenshots (~3.15MB) still exceeded the 5 MiB gateway wall.

Fix 1 — dynamic budget: the image allowance is now
GATEWAY_ENTITY_LIMIT (5 MiB) − SAFETY_MARGIN − nonImageBytes, capped by the fixed
budget for the common small-text case. Big text auto-clears more screenshots.
Verified on issue #52's exact 9 images: 343k text -> keep 3 (4.46MB), 500k ->
keep 2, 700k -> keep 1 (3.79MB), 900k -> keep 0 — always under the wall.

Fix 2 — reactive fallback: if the gateway STILL 413s, force-clear every
screenshot and retry once instead of relaying a 502. Streaming retries on the
first-pull 413 (before any content_block is written); non-stream wraps complete().

Tests: dynamic budget across text sizes, forceClearAllScreenshots, is413Error,
end-to-end reactive-retry through the Express app (stream + non-stream), http-e2e
big-text-fits-5MiB. 604 unit green; docker http-e2e ALL PASSED (68); tsc clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* test(cli-e2e): case #17 sized to a valid <1M-token turn (issue #52 dynamic budget)

The live CLI can't simultaneously hit the 5 MiB byte wall AND stay a valid
<1M-token request: base64 images tokenize at ~char/4, so a ~5 MiB body is
~1.3M tokens, over the model window. The byte-budget math is therefore asserted
hermetically (http-e2e, quota-free) and case #16 stresses a big screenshot pile
on its own. Case #17 proves the live consequence: a substantial mixed
conversation (~100k tokens prose + a screenshot pile) is a valid turn — no 413,
newest screenshot still read. Sized to ~591k tokens after edit, comfortably
under the 1M window.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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