Opt-in OpenRouter hardening + subagent kill switch (redo of #50 against current main)#312
Open
blue-az wants to merge 1 commit into
Open
Opt-in OpenRouter hardening + subagent kill switch (redo of #50 against current main)#312blue-az wants to merge 1 commit into
blue-az wants to merge 1 commit into
Conversation
Three independent, opt-in run-hardening controls, none of which change behavior unless explicitly set: - OPENWIKI_OPENROUTER_MAX_INPUT_TOKENS attaches a maxInputTokens profile to OpenRouter model instances so DeepAgents' summarization middleware triggers early enough to stay under OpenRouter's payload limit on constrained/budget models, instead of failing with an HTTP 500 on large transcripts. - OPENWIKI_DISABLE_MODEL_FALLBACK=1 disables OpenRouter's route: "fallback" model list for deterministic single-model runs. - OPENWIKI_DISABLE_SUBAGENTS=1 excludes the task tool via both a registered harness profile and runtime middleware (the same tool name enforced in one place), and updates the subagent-discipline prompt text to match, for runs where transcript growth from subagent fan-out is the binding constraint. Also excludes openwiki.* variant directories (testing/validation copies of generated docs) from repository discovery, so they are never inspected or documented. This supersedes langchain-ai#50, which hardened the same OpenRouter path against an older main; main has since gained connector tools, output modes, and ChatGPT OAuth login that touched every function langchain-ai#50 modified, so this re-implements the same opt-in controls directly against current main instead of resolving that merge conflict. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
Author
|
PRATHAM KUMAR (@rajpratham1) tagging you since you reviewed the original version of this on #50 — this is the same hardening (OpenRouter token-cap, model-fallback disable, subagent kill switch), redone against current main since #50's base had drifted too far to cleanly rebase. Test coverage for the subagent-disable path (your original ask) carried over, plus new coverage for the fallback-route and token-cap logic. |
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.
Summary
This supersedes #50. That PR hardened the OpenRouter path against
mainas of early July;mainhas since landed ChatGPT/Codex OAuth login, the connector system, output modes, and a rewrittendocs-only-backend, all of which touched every function #50 modified (createModel, thecreateDeepAgentcall site,createModeInstructions). Rather than force a conflict resolution across that much drift, this re-implements the same three opt-in controls directly against currentmain.All three are strictly opt-in — with nothing set, behavior is unchanged for every provider:
OPENWIKI_OPENROUTER_MAX_INPUT_TOKENS— attaches amaxInputTokensprofile to OpenRouter model instances (Object.defineProperty, so a frozen/non-extensible instance doesn't crash), so DeepAgents' summarization middleware triggers early enough to stay under OpenRouter's payload limit on constrained/budget models, instead of failing with an HTTP 500 on large transcripts. Suggested value for constrained models:15000.OPENWIKI_DISABLE_MODEL_FALLBACK=1— disables OpenRouter'sroute: "fallback"model list for deterministic single-model runs.OPENWIKI_DISABLE_SUBAGENTS=1— excludes thetasktool from the model, enforced in two places that share one tool-name constant: a registered DeepAgents harness profile (excludedTools,generalPurposeSubagent.enabled: false) and runtime middleware (wrapModelCallfilterstaskout of the tool list). The subagent-discipline prompt text is swapped to match, so the system prompt doesn't tell the model it can delegate when the tool has been removed.Also:
openwiki.*variant directories (testing/validation copies of generated docs) are excluded from repository discovery in the prompt, so they're never inspected or documented as part of a real run.Why bundle these three
They're independent switches but came from the same investigation (hardening a constrained-model OpenRouter run) and the original review thread on #50 already covered this scope; splitting them into separate PRs now would just re-litigate settled ground. Happy to split on request.
Test plan
pnpm run typecheck— cleanpnpm run lint:check— cleanpnpm run format:check— cleanpnpm run build— cleanpnpm test— 213/213 passing across 20 files, including two new files:test/subagent-disable.test.ts—isSubagentDisabledonly trips on the literal"1";buildSubagentDisabledProfile()'s shape; default behavior unchanged (no middleware, no tools removed) when unset; thetasktool is filtered from the model call when disabled, all other tools pass through unchanged.test/openrouter-hardening.test.ts—isModelFallbackDisabledonly trips on"1"; non-OpenRouter providers never get a fallback list; OpenRouter gets the primary model plus fallback ids by default, without duplicating the primary when it's also a fallback id; disabled collapses to a single model;resolveOpenRouterMaxInputTokensparsing (unset → undefined, non-numeric → undefined, valid → parsed).test/prompt.test.tsfor theopenwiki.*exclusion bullet and both branches of the subagent-discipline text.🤖 Generated with Claude Code