Skip to content

Harden OpenRouter path with opt-in transcript and routing controls#50

Closed
blue-az wants to merge 2 commits into
langchain-ai:mainfrom
blue-az:harden-openrouter-path
Closed

Harden OpenRouter path with opt-in transcript and routing controls#50
blue-az wants to merge 2 commits into
langchain-ai:mainfrom
blue-az:harden-openrouter-path

Conversation

@blue-az

@blue-az blue-az commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Problem

On the OpenRouter path with constrained/budget models, documentation runs fail with HTTP 500 errors before summarization ever triggers: the summarization middleware's default trigger (~170k tokens) sits far above the payload size where OpenRouter requests actually start failing (roughly 270–340KB, ~12–25k tokens depending on the model). Two secondary issues compound this on longer runs: generated openwiki.* variant directories (from testing/validation runs) leak into discovery and get re-read, and subagent fan-out multiplies transcript growth.

Changes

All hardening is strictly opt-in — with no environment variables set, behavior is unchanged for every provider:

  • OPENWIKI_OPENROUTER_MAX_INPUT_TOKENS — when set, attaches a model profile with this maxInputTokens to OpenRouter model instances (via Object.defineProperty, so frozen/non-extensible instances don't crash), which lets the summarization middleware trigger early enough to stay under the payload limit. Suggested value for constrained models: 15000.
  • OPENWIKI_DISABLE_SUBAGENTS=1 — disables subagent task delegation for runs where transcript growth is the binding constraint.
  • OPENWIKI_DISABLE_MODEL_FALLBACK=1 — disables OpenRouter fallback routing for deterministic single-model runs.
  • Prompt discipline: discovery/read exclusions for openwiki.* variant directories so testing/validation copies of the wiki are never inspected or documented.
  • Docs: the new options are documented in openwiki/operations/credentials-and-updates.md.

Verification

  • pnpm run build, pnpm run lint:check, and pnpm run format:check all pass.
  • Live-validated end-to-end on the OpenRouter path with the cap set: summarization prunes at the configured threshold and full --init/--update runs complete with no 500s (previously reproducible failures).

Related

The remaining workspace-pollution item found during this testing is filed separately as #49 (conversation_history/ offloads written into the target repository).

🤖 Generated with Claude Code

…marization, disable subagents, and ignore openwiki.* directories

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

configureDeepAgentHarness() only calls registerHarnessProfile() when OPENWIKI_DISABLE_SUBAGENTS === "1", but there are no corresponding tests verifying that the task tool is actually disabled. Since this changes runtime behavior by removing subagent delegation, please add an integration or unit test that confirms the task tool is excluded and generalPurposeSubagent.enabled is false when the environment variable is set, while leaving the default behavior unchanged. This helps prevent future regressions.

Adds node:test coverage (no new deps) for the subagent-disable path:
- disabled profile drops the task tool and sets generalPurposeSubagent.enabled=false
- the exclusion middleware filters the task tool out of the model call when set
- default behavior is unchanged (no middleware, no tools removed) when unset
- the opt-in gate only triggers on the literal "1"

Extracts the harness profile into a pure buildSubagentDisabledProfile() and
shares the task tool name via a single constant so the profile and middleware
stay in sync. Adds a "test" script.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@blue-az

blue-az commented Jul 4, 2026

Copy link
Copy Markdown
Contributor Author

Good call — added node:test coverage in 6e17267 (no new deps; tsx was already dev-installed). The disabled profile now has an asserted shape (task excluded, generalPurposeSubagent.enabled false), and the middleware test invokes wrapModelCall to confirm task is filtered out of the model call while default behavior stays untouched (no middleware, no tools removed when the flag is unset). I also pulled the tool name into one shared constant so the profile and middleware can't drift out of sync. Thanks for the review.

@blue-az

blue-az commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

Pushed the requested test coverage in 6e17267 — could you re-review when you get a chance?

@blue-az

blue-az commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

Closing in favor of #312 — main has moved far enough (connector tools, output modes, ChatGPT OAuth) that the same three opt-in controls needed a clean redo rather than a conflict resolution. Thanks for the review here; the test-coverage ask carried over.

@blue-az blue-az closed this Jul 13, 2026
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.

2 participants