Skip to content

refactor(agent-core-v2): remove the legacy kosong request layer - #352

Merged
elkaix merged 6 commits into
mainfrom
refactor/remove-legacy-kosong
Oct 1, 2026
Merged

elkaix merged 6 commits into
mainfrom
refactor/remove-legacy-kosong

Conversation

@elkaix

@elkaix elkaix commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Requirement or Bug

Remove the legacy packages/agent-core-v2/src/kosong request layer. Port the features that existed only there and fix the bugs it caused. Stacked on #349.

Bug Reproduction Steps

  1. Configure a provider with type = "openai" and env = { OPENAI_API_KEY = "sk-..." }, with no apiKey and no process env key.
  2. Start a session and send a turn.
  3. The auth check fails with AuthTokenMissingError, even though the request path would find the key.

Root Cause

20 of the 62 files under src/kosong still loaded at runtime through app/auth/* and app/kosongConfig/*. kosong keeps its own provider-definition map, and at runtime that map held only the pythinker definitions, because the standard definitions never loaded. So resolveModelAuthMaterial / resolveModelForReady (auth check) and envOverlay (vendor *_BASE_URL) ignored provider-env values for every non-pythinker provider. Real requests use llm-adapter and find them. This is a fundamental fix: one provider-definition registry, the live one.

Code Changes

  • Delete src/kosong (61 files, about 11k lines). The 19 importers now import the same symbols from #/llm-adapter/* (types are identical apart from the import path).
  • Port features that existed only in the deleted copy, each with a test that fails before and passes after:
    • OpenCode billing errors: a 401/402/403 whose body says "insufficient balance", "insufficient credit", "credits exhausted" or "please recharge" is a provider error, not provider.auth_error. Ordinary 401s stay auth errors.
    • DSML / Hermes tool calls: tool calls that some models write as text tags on the chat-completions stream are parsed into real tool calls.
    • modelRecordProviderId moved to llm-adapter/model/model.ts.
  • apps/vis imports @pymodel/agent-core-v2/llm-adapter/contract/tokens instead of the kosong subpath.
  • scripts/check-identity-freeze.mjs drops the deleted kosong path.
  • Test fix: an MCP registry test set the wrong home variable, so it did not isolate the home directory. It now sets PYTHINKER_CODE_HOME.

The default-model fallback that also lived only in kosong is not restored: since #323 the gateway tests require that default_model is never rewritten. That is a product decision, tracked in #351.

Behavior Changes and Affected Users

Behavior Before After Who relies on the old behavior Escape hatch
Vendor API key in a provider's env table Auth check ignores it, turn fails with AuthTokenMissingError Key is found, turn runs Nobody (the old behavior was a bug) n/a
Vendor *_BASE_URL in an env provider of non-pythinker type Ignored by envOverlay Applied Nobody (bug) Remove the variable from env
OpenCode 401/402/403 with a billing message provider.auth_error ("not logged in") Provider error with the billing message, not retried Clients that map provider.auth_error to a re-login prompt for this case None needed; the old message was wrong
Chat-completions stream with DSML/Hermes tool tags Tags shown as assistant text, no tool call Parsed into tool calls. Text that could start a tag is held back until it is known not to be a tag, and llm.streaming.finish arrives after the stream ends Nobody relies on raw tags None
@pymodel/agent-core-v2/kosong/* subpath import Resolves Gone apps/vis (updated in this PR); no other consumer found in the repo Import from .../llm-adapter/*

Affected modules and coverage:

  • app/auth: test/app/auth/auth.test.ts (provider-env key case, fails on main).
  • app/kosongConfig/envOverlay: new non-pythinker base-url case (fails on main).
  • human/llm openai format and stream: billing-error tests and DSML parser/recovery tests.
  • Full suites: agent-core-v2 6,491 pass, agent-gateway 1,407 pass, vis-server 173 pass; tsc and tsgo clean; no-comments and identity-freeze checks pass.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: issue must have a maintainer's /approve).
  • I have added tests that prove my feature works.
  • The behavior-change table above is complete, and every removed behavior or flipped default is named in the changeset and either has an escape hatch or was explicitly approved by a maintainer in this PR.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

elkaix added 5 commits October 1, 2026 18:04
…t path

OpenCode Go rejects requests without a stable per-conversation session id.
The header was only built in the legacy kosong requester, which the engine
no longer uses, and even there it read a conversationId that turns never set.
Derive the header from the session cache key in the live llm-adapter
requester and give the connectivity probe a random session id.
Route every importer to llm-adapter and #human, then delete src/kosong.
Port the features that only lived in the legacy copy: OpenCode billing
rejections are provider errors, DSML/Hermes text tool calls are recovered
on the OpenAI stream, and modelRecordProviderId. The auth and env-overlay
checks now read the full provider-definition registry, so vendor API keys
and base URLs in a provider env table are honored.
@coderabbitai

coderabbitai Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 23 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Repository: PyModel/pythinker-code/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 82af738b-df08-4904-b54b-56456a693475

📥 Commits

Reviewing files that changed from the base of the PR and between 69cc714 and 1c569a8.

📒 Files selected for processing (98)
  • .changeset/dsml-tool-call-recovery.md
  • .changeset/opencode-billing-error.md
  • .changeset/provider-env-api-key-auth.md
  • apps/pythinker-code/src/cli/sub/provider.ts
  • apps/vis/server/src/lib/context-projector.ts
  • apps/vis/server/test/lib/context-projector.test.ts
  • packages/agent-core-v2/src/app/auth/auth.ts
  • packages/agent-core-v2/src/app/auth/authService.ts
  • packages/agent-core-v2/src/app/auth/authStatusService.ts
  • packages/agent-core-v2/src/app/auth/configSection.ts
  • packages/agent-core-v2/src/app/config/errors.ts
  • packages/agent-core-v2/src/app/kosongConfig/configSection.ts
  • packages/agent-core-v2/src/app/kosongConfig/discoveryService.ts
  • packages/agent-core-v2/src/app/kosongConfig/envOverlay.ts
  • packages/agent-core-v2/src/app/kosongConfig/hostRequestHeadersAdapter.ts
  • packages/agent-core-v2/src/app/kosongConfig/kosongConfigService.ts
  • packages/agent-core-v2/src/app/kosongConfig/modelsDev.ts
  • packages/agent-core-v2/src/app/kosongConfig/modelsDevImport.ts
  • packages/agent-core-v2/src/app/kosongConfig/modelsDevImportService.ts
  • packages/agent-core-v2/src/app/kosongConfig/modelsDevUpstream.ts
  • packages/agent-core-v2/src/app/kosongConfig/oauthTokenAdapter.ts
  • packages/agent-core-v2/src/app/plugin/pluginService.ts
  • packages/agent-core-v2/src/features/cron/cronAgentRuntime.ts
  • packages/agent-core-v2/src/human/llm/requester/bases/openai/dsml-tool-parser.ts
  • packages/agent-core-v2/src/human/llm/requester/bases/openai/format.ts
  • packages/agent-core-v2/src/human/llm/requester/bases/openai/requester.ts
  • packages/agent-core-v2/src/human/test/llm/dsml-tool-parser-conformance.test.ts
  • packages/agent-core-v2/src/human/test/llm/dsml-tool-parser.test.ts
  • packages/agent-core-v2/src/kosong/contract/capability.ts
  • packages/agent-core-v2/src/kosong/contract/errors.ts
  • packages/agent-core-v2/src/kosong/contract/generate.ts
  • packages/agent-core-v2/src/kosong/contract/inspection.ts
  • packages/agent-core-v2/src/kosong/contract/message.ts
  • packages/agent-core-v2/src/kosong/contract/messageHelpers.ts
  • packages/agent-core-v2/src/kosong/contract/provider.ts
  • packages/agent-core-v2/src/kosong/contract/requestTrace.ts
  • packages/agent-core-v2/src/kosong/contract/tokens.ts
  • packages/agent-core-v2/src/kosong/contract/tool.ts
  • packages/agent-core-v2/src/kosong/contract/usage.ts
  • packages/agent-core-v2/src/kosong/model/catalog.ts
  • packages/agent-core-v2/src/kosong/model/catalogService.ts
  • packages/agent-core-v2/src/kosong/model/completionBudget.ts
  • packages/agent-core-v2/src/kosong/model/defaultModelPolicy.ts
  • packages/agent-core-v2/src/kosong/model/errors.ts
  • packages/agent-core-v2/src/kosong/model/hostRequestHeaders.ts
  • packages/agent-core-v2/src/kosong/model/inspection.ts
  • packages/agent-core-v2/src/kosong/model/model.ts
  • packages/agent-core-v2/src/kosong/model/model.types.ts
  • packages/agent-core-v2/src/kosong/model/modelAuth.ts
  • packages/agent-core-v2/src/kosong/model/modelOAuth.ts
  • packages/agent-core-v2/src/kosong/model/modelRequester.ts
  • packages/agent-core-v2/src/kosong/model/modelRequesterImpl.ts
  • packages/agent-core-v2/src/kosong/model/modelService.ts
  • packages/agent-core-v2/src/kosong/model/thinking.ts
  • packages/agent-core-v2/src/kosong/protocol/errors.ts
  • packages/agent-core-v2/src/kosong/protocol/protocol.ts
  • packages/agent-core-v2/src/kosong/protocol/protocolBase.ts
  • packages/agent-core-v2/src/kosong/protocol/protocolTrait.ts
  • packages/agent-core-v2/src/kosong/provider/bases/anthropic/anthropic-profile.ts
  • packages/agent-core-v2/src/kosong/provider/bases/anthropic/anthropic.contrib.ts
  • packages/agent-core-v2/src/kosong/provider/bases/anthropic/anthropic.ts
  • packages/agent-core-v2/src/kosong/provider/bases/anthropic/anthropicHooks.ts
  • packages/agent-core-v2/src/kosong/provider/bases/anthropic/index.ts
  • packages/agent-core-v2/src/kosong/provider/bases/google-genai/google-genai.contrib.ts
  • packages/agent-core-v2/src/kosong/provider/bases/google-genai/google-genai.ts
  • packages/agent-core-v2/src/kosong/provider/bases/google-genai/index.ts
  • packages/agent-core-v2/src/kosong/provider/bases/merge-user-messages.ts
  • packages/agent-core-v2/src/kosong/provider/bases/openai/chat-completions-stream.ts
  • packages/agent-core-v2/src/kosong/provider/bases/openai/index.ts
  • packages/agent-core-v2/src/kosong/provider/bases/openai/openai-common.ts
  • packages/agent-core-v2/src/kosong/provider/bases/openai/openai-legacy.contrib.ts
  • packages/agent-core-v2/src/kosong/provider/bases/openai/openai-legacy.ts
  • packages/agent-core-v2/src/kosong/provider/bases/openai/openai-responses.contrib.ts
  • packages/agent-core-v2/src/kosong/provider/bases/openai/openai-responses.ts
  • packages/agent-core-v2/src/kosong/provider/bases/openai/openaiHooks.ts
  • packages/agent-core-v2/src/kosong/provider/bases/openai/reasoning-key.ts
  • packages/agent-core-v2/src/kosong/provider/bases/request-auth.ts
  • packages/agent-core-v2/src/kosong/provider/bases/tool-call-id.ts
  • packages/agent-core-v2/src/kosong/provider/protocolAdapterRegistry.ts
  • packages/agent-core-v2/src/kosong/provider/provider.ts
  • packages/agent-core-v2/src/kosong/provider/providerDefinition.ts
  • packages/agent-core-v2/src/kosong/provider/providerService.ts
  • packages/agent-core-v2/src/kosong/provider/providers/pythinker/pythinker-errors.ts
  • packages/agent-core-v2/src/kosong/provider/providers/pythinker/pythinker-files.ts
  • packages/agent-core-v2/src/kosong/provider/providers/pythinker/pythinker-schema.ts
  • packages/agent-core-v2/src/kosong/provider/providers/pythinker/pythinker.contrib.ts
  • packages/agent-core-v2/src/kosong/provider/providers/standard.contrib.ts
  • packages/agent-core-v2/src/kosong/recordDiff.ts
  • packages/agent-core-v2/src/llm-adapter/contract/errors.ts
  • packages/agent-core-v2/src/llm-adapter/model/model.ts
  • packages/agent-core-v2/src/session/subagent/subagentModelPolicyService.ts
  • packages/agent-core-v2/test/.skip/thinking.test.ts
  • packages/agent-core-v2/test/app/auth/auth.test.ts
  • packages/agent-core-v2/test/app/kosongConfig/envOverlay.test.ts
  • packages/agent-core-v2/test/app/mcpRegistry/mcpRegistry.test.ts
  • packages/agent-core-v2/test/llm-adapter/contract/opencode-billing-error.test.ts
  • packages/agent-core-v2/test/llm-adapter/model/modelService.test.ts
  • scripts/check-identity-freeze.mjs
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@pymodel/pythinker-code@1c569a8
npx https://pkg.pr.new/@pymodel/pythinker-code@1c569a8

commit: 1c569a8

Base automatically changed from fix/opencode-session-header to main October 1, 2026 23:14
…y-kosong

# Conflicts:
#	packages/agent-core-v2/src/kosong/model/modelRequesterImpl.ts
@elkaix
elkaix enabled auto-merge (squash) October 1, 2026 23:15
@elkaix
elkaix merged commit 772e69a into main Oct 1, 2026
25 checks passed
@elkaix
elkaix deleted the refactor/remove-legacy-kosong branch October 1, 2026 23:19
elkaix pushed a commit that referenced this pull request Oct 1, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @pymodel/pythinker-code@2.4.1

### Patch Changes

- [#352](#352)
[`772e69a`](772e69a)
Thanks [@elkaix](https://github.com/elkaix)! - Run tool calls that some
models (such as DeepSeek) write as DSML or <tool_call> text instead of
showing them as plain text.

- [#352](#352)
[`772e69a`](772e69a)
Thanks [@elkaix](https://github.com/elkaix)! - Report an
insufficient-balance response from OpenAI-compatible providers as a
billing error instead of an authentication error.

- [#349](#349)
[`69cc714`](69cc714)
Thanks [@elkaix](https://github.com/elkaix)! - Fix OpenCode Go requests
failing with "Request is missing x-opencode-session".

- [#352](#352)
[`772e69a`](772e69a)
Thanks [@elkaix](https://github.com/elkaix)! - Accept a vendor API key
or base URL set in a provider's env table (for example ANTHROPIC_API_KEY
or ANTHROPIC_BASE_URL) instead of ignoring it.
## @pymodel/pythinker-web@0.2.0

### Minor Changes

- [#347](#347)
[`bca1910`](bca1910)
Thanks [@elkaix](https://github.com/elkaix)! - Align the embedded
terminal palette and workflow panel motion with the shared design token
system.

- [#347](#347)
[`bca1910`](bca1910)
Thanks [@elkaix](https://github.com/elkaix)! - Show estimated
changed-line counts for large edits in session transcripts and file
summaries instead of zero.

- [#347](#347)
[`bca1910`](bca1910)
Thanks [@elkaix](https://github.com/elkaix)! - Use the shared type scale
and corner radii on application surfaces.
## @pymodel/pythinker-desktop@1.5.1

### Patch Changes

- [#352](#352)
[`772e69a`](772e69a)
Thanks [@elkaix](https://github.com/elkaix)! - Run tool calls that some
models (such as DeepSeek) write as DSML or <tool_call> text instead of
showing them as plain text.

- [#352](#352)
[`772e69a`](772e69a)
Thanks [@elkaix](https://github.com/elkaix)! - Report an
insufficient-balance response from OpenAI-compatible providers as a
billing error instead of an authentication error.

- [#349](#349)
[`69cc714`](69cc714)
Thanks [@elkaix](https://github.com/elkaix)! - Fix OpenCode Go requests
failing with "Request is missing x-opencode-session".

- [#352](#352)
[`772e69a`](772e69a)
Thanks [@elkaix](https://github.com/elkaix)! - Accept a vendor API key
or base URL set in a provider's env table (for example ANTHROPIC_API_KEY
or ANTHROPIC_BASE_URL) instead of ignoring it.

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.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