Skip to content

fix(agent): isolate qodercli from inherited SDK mode - #242

Merged
zpzjzj merged 2 commits into
alibaba:mainfrom
JHWang-1997:fix/qodercli-sdk-env-leak
Sep 11, 2026
Merged

zpzjzj merged 2 commits into
alibaba:mainfrom
JHWang-1997:fix/qodercli-sdk-env-leak

Conversation

@JHWang-1997

@JHWang-1997 JHWang-1997 commented Sep 11, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Prevent the built-in qodercli adapter from inheriting QODER_AGENT_SDK_ENTRYPOINT from SDK-hosted parent processes such as Qoder Work. Without this isolation, nested ordinary qodercli commands are misclassified as Agent SDK sessions and fail with sdk_invalid_args.

Related issues

Closes #240

Changes

  • unset QODER_AGENT_SDK_ENTRYPOINT for version checks, inline and file/stdin runs, resumed sessions, and MCP remove/add commands
  • apply the same isolation to the global and CN qodercli profiles
  • add regression coverage for run, resume, profile-default, and MCP command builders
  • document the behavior change in the changelog

Test plan

  • make test passes
  • make verify passes (fmt + vet + lint)
  • make build passes
  • Deterministic QoderCLI single-turn and multi-turn E2E tests with the SDK marker inherited
  • Manual run and MCP argument-validation checks with qodercli 1.1.3, 1.1.6, and 1.1.9

Notes for reviewers

The adapter intentionally remains on qodercli's ordinary -p --output-format json protocol. Merely switching to stream-json would be incomplete because genuine Agent SDK mode also requires structured stdin, initialization/control messages, and an SDK authentication payload.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-11T07:01:43.723801Z 2d19a61 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@JHWang-1997

Copy link
Copy Markdown
Collaborator Author

Validation record:

  • make fmt: passed.

  • go test -race ./internal/agent -run 'Test(BuildQoder|QoderCLI)': passed.

  • make verify: passed (go vet, revive, and golangci-lint; 0 issues).

  • make test: passed across all packages with the host Qoder credential variables removed from the test environment:

    env -u QODER_PERSONAL_ACCESS_TOKEN \
      -u QODER_CN_ACCESS_TOKEN \
      -u QODERCN_PERSONAL_ACCESS_TOKEN \
      make test
  • make build: passed.

  • Manual argument-validation checks:

    • Before the fix, ordinary CLI invocations with QODER_AGENT_SDK_ENTRYPOINT=sdk-ts failed with sdk_invalid_args on qodercli 1.1.3, 1.1.6, and 1.1.9.
    • With the new env -u QODER_AGENT_SDK_ENTRYPOINT prefix, all three versions passed SDK-mode argument validation and reached the normal network/authentication stage; none produced sdk_invalid_args.

This confirms that the adapter remains on its existing ordinary JSON protocol while being isolated from SDK mode inherited from the parent process.

@JHWang-1997

Copy link
Copy Markdown
Collaborator Author

Follow-up validation after commit 51b94db:

  • Completed the previously uncovered MCP path: both qodercli mcp remove and qodercli mcp add now clear QODER_AGENT_SDK_ENTRYPOINT.
  • Applied the same isolation to the default version probe and fallback run command so every adapter-managed qodercli invocation uses the ordinary CLI protocol consistently.
  • make fmt: passed.
  • go test -race ./internal/agent -run 'Test(NewQoder|BuildQoder|QoderCLI|BuildMCP)': passed.
  • make verify: passed (go vet, revive, and golangci-lint; 0 issues).
  • make test: passed across all packages.
  • make build: passed.
  • Deterministic QoderCLI single-turn and multi-turn E2E tests passed with QODER_AGENT_SDK_ENTRYPOINT=sdk-ts inherited by the skill-up process.
  • Manual MCP argument-validation checks passed with qodercli 1.1.3, 1.1.6, and 1.1.9: after the wrapper removed the inherited marker, each version reached normal MCP command handling without sdk_invalid_args.

Risk review:

  • No remaining adapter-managed qodercli execution path was found without SDK-environment isolation. The availability check uses command -v, and the installer invokes the official install script rather than qodercli itself.
  • The wrapper remains compatible with the repository's supported POSIX-shell execution model, including Windows execution through Git Bash.
  • Ordinary CLI authentication is unchanged: the command still requires the edition-specific PAT or existing local login state.
  • The CN command builders are covered by regression tests; a qodercn binary was not available for a live local invocation.

@zpzjzj zpzjzj left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@zpzjzj
zpzjzj added this pull request to the merge queue Sep 11, 2026
@zpzjzj zpzjzj mentioned this pull request Sep 11, 2026
6 tasks done
Merged via the queue into alibaba:main with commit e789437 Sep 11, 2026
10 checks passed
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.

[Bug] qodercli engine inherits Qoder Agent SDK environment and fails with sdk_invalid_args

2 participants