Skip to content

claude-subscription-directsdk: land 15 reviewed contributor fixes (#426 #382 #406 #421 #422 #423 #427 #425 #419 #416 #412 #404 #408 #410 #387) - #445

Merged
teknium1 merged 34 commits into
mainfrom
land/directsdk-slate-1119
Nov 19, 2026
Merged

teknium1 merged 34 commits into
mainfrom
land/directsdk-slate-1119

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Fifteen Claude subscription plugin fixes from contributors, landed together. Each one fixes something users hit, for example model ids like anthropic/claude-sonnet-5 failing, parallel calls cancelling each other, or a dropped connection compressing your conversation. Every commit keeps its author. This PR only stacks them on current main and resolves the CHANGELOG line each one adds.

Every PR below was reviewed: its premise was checked on main, and its new tests fail on main's code and pass on its head. Where we changed a PR, our commits sit on top of the contributor's, authored Teknium.

PR Author What changes for users
#426 @mikerotenberg Tests only: two tests no longer depend on the host they run on
#382 @amsavarthan No "No module named directsdk" after Hermes reloads plugins mid-session
#406 @100yenadmin Survives the OS clearing core's temporary import copy of the plugin (rebased: keeps #382's __init__.py)
#421 @salch-cred Vendor-prefixed model ids (anthropic/claude-sonnet-5) work instead of 404 + admission refusal on every retry
#422 @salch-cred An outdated claude early on PATH is skipped for a supported one; --version asked once per binary (our fix); Windows .exe/.cmd lookup
#423 @salch-cred Closing one client no longer cancels other in-flight calls (our fix: contract test, dead refusal removed, README)
#427 @salch-cred A dropped stream is named with core's premature-close wording, so it is retried and never read as context overflow (our fix)
#425 @salch-cred Opt-in reserve that stops before the first extra-usage-billed request, also from each turn's rate_limit_event (our fix)
#419 @RomainNicault One stdin watchdog thread per request instead of one Timer per replayed frame
#416 @dankkush Subagent requests write their prompt cache at 5 m, not 1 h
#412 @metahacker The relay starts without a reverse DNS lookup of its own address
#404 @metahacker A step's relay closes at once, not at the next 50 ms poll
#408 @metahacker A call queued for a max_concurrent slot never starts after its deadline or cancellation
#410 @metahacker evals/ci.sh also runs on Windows (CI only)
#387 @zdarovka When a plan window is used up, Hermes is told when it reopens

Conflict resolutions:

Tests: full plugin suite on the stacked head against hermes-agent main 502009cc+: 655 passed, 9 subtests passed. No merge commits (git rev-list --merges origin/main..HEAD is empty).

Not covered: no live subscription turns were run. Everything is offline tests with a real Claude Code 2.1.292 binary, plus code reading.

Fixes #381, fixes #377, fixes #380, fixes #378, fixes #396. Part of #398 (item 1).

Supersedes #426, #382, #406, #421, #422, #423, #427, #425, #419, #416, #412, #404, #408, #410, #387. Each of those will be closed with a credit comment naming its landed commits.

mikerotenberg and others added 30 commits November 19, 2026 10:58
… host

The missing-CLI discovery tests pass only on hosts with no claude in a
system prefix: _resolve falls back to /opt/homebrew/bin and /usr/local/bin,
so a host with Claude Code installed there finds the real binary and the
'no claude' assertions fail. Patch _SYSTEM_PREFIXES empty on both the flat
and package-relative directsdk_setup copies, and add a positive test that
the prefix stays a fallback that never overrides an explicit command.

The no-uid workspace case deletes os.getuid. In an environment without
USER, _with_login_identity then falls back to pwd.getpwuid(os.getuid())
and raises AttributeError before the workspace branch under test runs.
Give that case a synthetic USER.
Hermes core's plugin re-discovery evicts the plugin package from
sys.modules; the registered profile survives, but its methods did a
lazy relative import at call time. After eviction that fails as
"No module named 'directsdk'", surfaced to gateway-served surfaces
(mobile/desktop) as "Failed to initialize OpenAI client".

Import directsdk and directsdk_setup once at module load and
reference them from create_client/setup_status/discover_models/
fetch_account_usage, so no import runs at call time.

tests/test_sysmodules_eviction.py: red on main (4 failed), green
on this change (4 passed); full suite passes.
Hermes core can pass an OpenRouter-style canonical id such as
anthropic/claude-sonnet-5 even when the config names claude-sonnet-5.
_route_base only stripped a leading claude-, so the vendor prefix reached
the native CLI, which 404s. A 404 is not an auth error, so the admission
guard denied every retry and the turn silently fell back to another
provider. Strip anthropic/ and openrouter/ before routing; leave other
namespaces alone.

Fixes #377
…laude

A systemd service PATH can put an old Claude Code install ahead of the
current one. With 2.1.148 the tool payload is dropped from the request and
the model answers as a title generator. When the bare claude found on PATH
is below the supported minimum, look for a newer executable in the install
prefixes first. An explicit command override is never second-guessed.

Fixes #380
… CLIs through which()

_resolve runs on every turn, so the version check spawned `claude --version`
before every request. Cache it per (realpath, mtime, size), so `claude update`
is noticed and a transient failure is retried. The prefix scan used a bare
os.path.join(prefix, 'claude'), which misses claude.exe / claude.cmd on
Windows; use shutil.which per prefix and skip the PATH hit itself. Test
fakes are named claude.cmd on Windows. CHANGELOG line for #380.
Hermes' auxiliary client cache closes a client bound to another live event
loop. Client.close() cancelled every in-flight request on it, so two tool
calls running in parallel (two vision_analyze calls in one step) could fail
with 'Claude request cancelled' or 'Claude client is closed'. Each request
owns and reaps its own native process, so closing needs no cleanup; Stream.close()
and cancel() remain the explicit per-request stop paths.

Fixes #378
…-contract test on the stream's own close

Client.close() no longer cancels running requests (#378), so the _closed flag
only made a cached client refuse every later call with 'Claude client is
closed', the second symptom in the issue. Drop it. test_fail_closed_and_cancellation
relied on Client.close() finalizing an unstarted stream; it now closes that
stream itself. CHANGELOG line for the fix.
A 200 cut short raised ClaudeAPIError with status_code=None and the transport
label only inside the prose, so core's message-based classifier saw an
unknown error: no same-provider retry, no fallback chain, and no compression
network-failure guard. Append the canonical wording core already matches
(server disconnected, connection reset by peer, ...) for known relay failures,
keeping the original label for reports. Unknown failures are unchanged.

Fixes #396
…-close wording

'server disconnected' / 'connection reset by peer' / 'incomplete chunked read'
are core's _SERVER_DISCONNECT_PATTERNS, which a large session on a non-reasoning
model (claude-haiku-4-5, haiku-5-5) classifies as context_overflow with
should_compress=True, so a dropped stream would have compressed the
conversation. Use core's premature-close / connection-reset wording instead,
which is always a connection timeout retry. The test now runs the wrapped
error through core's real classify_api_error for both a non-reasoning and a
reasoning model (red on the previous mapping: 4 Haiku cases compress).
CHANGELOG line for #396.
…illed request

The request that first crosses a plan limit is already billed; ask/stop
only act on the next one. Add extra_usage_reserve_percent (e.g. 97): under
ask/stop, refuse once an account-wide plan window reaches that percent,
using the same zero-inference get_usage probe. Unset or invalid keeps 100,
so existing installs are unchanged. notify/allow never probe.

Refs #398
…imit_event; declare and document it

The reserve only took effect on a get_usage probe, which runs only with no
current answer. After any turn the process holds the turn's own
rate_limit_event answer (using_overage false below 100%) for up to 15
minutes, so a running gateway kept sending past the reserve until the plan
wall: the setting worked only on a fresh process. The event summary now
carries the fuller account-wide window's utilization (unifiedWindows
five_hour/seven_day), and under ask/stop with permitted overage a window at
the reserve counts as spilling. The refusal says it was the reserve. The
setting is declared in plugin.yaml (Desktop settings form) and documented in
the README; CHANGELOG line under Added.
…hread per replayed frame

Every replayed frame is one stdin write, and each write started a threading.Timer
(one thread) as its stall guard: 602 thread starts for a 300-round history.
One watchdog thread per request now guards every write. A write records when it
began; the thread never sleeps past the timeout, so it wakes before the deadline
of any write that began while it slept, then sleeps until exactly that deadline.

Plugin CPU per call (4 vCPU Linux, Claude Code 2.1.327, loopback upstream):
100 rounds 0.19 -> 0.10 s, 300 rounds 0.42 -> 0.23 s. Claude Code's own CPU is
unchanged.
… at 5m, not 1h

Core clamps a delegated child to the 5m cache tier (_apply_child_cache_ttl: a
subagent calls every few seconds for minutes and is gone, so the 2x write buys
retention it never collects). Core can only clamp the cache_control markers it
builds. On this route native places them, and a `claude -p` turn is Claude
Code's main-conversation bucket, which asks for the one-hour tier on a
subscription within plan usage. Every child request therefore wrote at 1h:
2x the input rate instead of 1.25x.

The profile hook reads the cache scope core stamps on a child (sub_<hash>,
prompt_cache_scope.is_sibling_cache_scope) and returns hermes_cache_ttl=5m; the
spawn then starts native with CLAUDE_CODE_PROMPT_CACHE_TTL=5m (documented,
Claude Code 2.1.242+). A tier the user exported wins. Every other request keeps
native's default.

CLAUDE_CODE_SUBAGENT_PROMPT_CACHE_TTL is deliberately not used: it governs
requests outside the main bucket, and a -p turn is inside it.
metahacker and others added 4 commits November 19, 2026 10:58
Native's limit message names a clock time ("resets 3:45pm") that core
cannot parse, so core never knew when a used-up window reopens. The
relay now keeps the reset of a 429 whose unified status is "rejected",
and the error carries it as body["resets_at"], the field core reads for
its fallback bench and limit notice.
@teknium1
teknium1 merged commit 72eb3b8 into main Nov 19, 2026
64 checks passed
This was referenced Nov 19, 2026
metahacker added a commit to metahacker/hermes-official-plugins that referenced this pull request Nov 19, 2026
…ession-steer: main's fixes carried onto the kept process

NousResearch#445 lands 15 fixes on main. Where a kept process takes the same path, it gets the same fix:
close() no longer refuses or cancels a call, it ends the kept process (NousResearch#378); a delegated child's
5m cache tier is in the launch env and so in what a kept process is matched on (NousResearch#416); an incomplete
upstream answer keeps its transport phrase and plan-window reset (NousResearch#396, NousResearch#387); and one stdin watchdog
per request serves a kept step's frames too (NousResearch#419). The watchdog ends with its step, so a kept
process between steps holds neither a thread nor its client. One-shots mount no MCP server here, so
the frozen-copy test checks that a one-shot names none instead of the inert helper.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment