Skip to content
This repository was archived by the owner on Aug 25, 2026. It is now read-only.

fix(v2): apply compatible upstream correctness follow-ups - #27

Merged
YaseenHQ merged 3 commits into
mainfrom
codex/upstream-v2-followups
Aug 10, 2026
Merged

YaseenHQ merged 3 commits into
mainfrom
codex/upstream-v2-followups

Conversation

@YaseenHQ

@YaseenHQ YaseenHQ commented Aug 10, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • isolate v1 builtin agent profiles per session without importing upstream-only plugin catalog fields
  • carry absolute OAuth authorization expiry metadata through v1 and v2 MCP auth events

These are the remaining behavior-compatible upstream fixes after the consolidated Echadron v2 parity PR. Other newer upstream commits were already present under Echadron-specific implementations or require architecture replacements that are not safe to cherry-pick.

Validation

  • pnpm --filter @moonshot-ai/agent-core test (4107 passed, 3 expected failures, 30 skipped, 1 todo)
  • pnpm --filter @moonshot-ai/agent-core-v2 test (4263 passed)
  • pnpm --filter @moonshot-ai/agent-core exec vitest run test/mcp/auth-tool.test.ts (5 passed)
  • pnpm --filter @moonshot-ai/agent-core-v2 exec vitest run test/agent/mcp/tools/auth.test.ts (5 passed)
  • pnpm --filter @moonshot-ai/kimi-code-sdk exec vitest run test/v1-v2-parity.test.ts (79 passed)
  • package typechecks for agent-core, agent-core-v2, and kimi-code-sdk

Summary by CodeRabbit

  • New Features

    • OAuth authorization updates now include an optional expiration timestamp, helping indicate how long authorization links remain valid.
  • Bug Fixes

    • Session-specific profile changes no longer modify built-in profiles or affect later sessions.
    • OAuth authorization timeout handling is now consistent throughout the authentication flow.

oocz and others added 3 commits August 10, 2026 06:58
… update (MoonshotAI#2609)

* feat(mcp): carry an absolute expiresAt on the OAuth authorization-url update

The authenticate flow waits for the OAuth callback with a fixed budget,
but the authorization-url tool update surfaced to embedding hosts did not
say when that window ends — hosts had to hardcode a mirror of the
15-minute constant to render countdowns. Include the absolute deadline
(now + effective wait timeout) in the update payload for v1 and v2.

Resolve MoonshotAI#2607

* fix(protocol,kap-server): accept expiresAt in the OAuth authorization-url update schemas

The zod validators mirrored the pre-expiresAt payload shape and would
strip the new field at the kap-server boundary.

---------

Co-authored-by: zouying <zouying@moonshot.cn>
(cherry picked from commit 3126422)
@coderabbitai

coderabbitai Bot commented Aug 10, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR adds optional OAuth authorization expiry timestamps across protocol and authentication flows. It also isolates builtin profile clones per session and adds regression coverage for catalog isolation.

Changes

OAuth authorization expiry metadata

Layer / File(s) Summary
OAuth expiry contract
packages/protocol/src/events.ts, packages/kap-server/src/protocol/events-zod.ts
OAuth authorization updates now accept an optional epoch-millisecond expiresAt value.
OAuth timeout and test updates
packages/agent-core-v2/src/agent/mcp/tools/auth.ts, packages/agent-core/src/mcp/auth-tool.ts, packages/agent-core-v2/test/agent/mcp/tools/auth.test.ts, packages/agent-core/test/mcp/auth-tool.test.ts
Both authentication tools compute one effective timeout, include its absolute expiry, and use the same timeout for OAuth completion. Tests validate the expiry window.

Session-local builtin profiles

Layer / File(s) Summary
Session-local builtin profile catalogs
packages/agent-core/src/profile/agentfile/catalog.ts, packages/agent-core/test/profile/agentfile.test.ts, .changeset/isolate-session-profile-catalogs.md
Builtin profiles are cloned through sessionLocalBuiltinProfiles during construction and snapshot restoration. Tests verify isolation from global defaults and later catalogs while preserving delegation links.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • YaseenHQ/kimi#15: Shares the builtin-profile catalog isolation changes and regression tests.
  • YaseenHQ/kimi#22: Provides the related MCP authorization update flow extended with expiresAt.

Suggested reviewers: kermanx, 7sageer

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description provides a useful summary and validation results but omits the required Related Issue, Problem, What changed, and Checklist sections. Add the required template sections, link an issue or explain the problem, and complete the checklist.
Title check ❓ Inconclusive The title identifies correctness fixes but does not state the session-profile isolation or OAuth expiry changes. Replace the broad wording with a concise summary of the primary changes, such as session profile isolation and OAuth expiry propagation.
✅ Passed checks (3 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/upstream-v2-followups

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.

@YaseenHQ
YaseenHQ merged commit f65bb85 into main Aug 10, 2026
15 of 16 checks passed

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🧹 Nitpick comments (1)
packages/agent-core/test/profile/agentfile.test.ts (1)

377-403: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

Expand the regression to cover array mutation and snapshot restoration.

The test replaces firstCoder.tools with a new array. It does not prove that the cloned tools array stays isolated during an in-place mutation. Capture the baseline list, mutate the session list in place, and compare the global defaults and second catalog with that baseline. Also exercise restoreSnapshot, which now calls sessionLocalBuiltinProfiles() at packages/agent-core/src/profile/agentfile/catalog.ts Line 155.

As per coding guidelines, extend this existing test file instead of adding an excessive new test file.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/agent-core/test/profile/agentfile.test.ts` around lines 377 - 403,
Expand the existing test around firstCoder.tools to capture the baseline tools
array, mutate that array in place, and verify DEFAULT_AGENT_PROFILES and the
second catalog retain the baseline values. Also invoke restoreSnapshot and
assert the restored session-local builtin profile still matches the baseline,
covering sessionLocalBuiltinProfiles() behavior without adding a new test file.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.changeset/isolate-session-profile-catalogs.md:
- Line 5: Update the public release note text in
isolate-session-profile-catalogs.md to use the standard spelling “built-in
profiles” instead of “builtin profiles,” without changing the rest of the
wording.

In `@packages/agent-core-v2/src/agent/mcp/tools/auth.ts`:
- Around line 111-115: Use the same start time for the advertised OAuth expiry
and completion timeout in both
packages/agent-core-v2/src/agent/mcp/tools/auth.ts:111-115 and
packages/agent-core/src/mcp/auth-tool.ts:116-122. In the corresponding
flow.complete calls, calculate and pass the remaining duration after
update-handler work rather than the original full timeout, using the expiresAt
value established in each auth flow.
- Around line 111-115: The OAuth status messages in auth.ts
(packages/agent-core-v2/src/agent/mcp/tools/auth.ts, lines 111-115) and
auth-tool.ts (packages/agent-core/src/mcp/auth-tool.ts, lines 116-122) use a
fixed 15-minute timeout; update both to interpolate the effective timeout value,
such as waitTimeoutMs, so user-visible instructions match the configured
deadline. Both sites require the same direct change.

In `@packages/agent-core-v2/test/agent/mcp/tools/auth.test.ts`:
- Around line 65-76: Update the expiry assertions in auth.test.ts lines 65-76
and auth-tool.test.ts lines 69-80 to verify that expiresAt is approximately
Date.now() plus the configured timeoutMs of 100, using a controlled clock or an
appropriate tolerance. Replace the broad 15-minute upper bound in both test
sites while preserving the existing authorization URL and serverName assertions.

---

Nitpick comments:
In `@packages/agent-core/test/profile/agentfile.test.ts`:
- Around line 377-403: Expand the existing test around firstCoder.tools to
capture the baseline tools array, mutate that array in place, and verify
DEFAULT_AGENT_PROFILES and the second catalog retain the baseline values. Also
invoke restoreSnapshot and assert the restored session-local builtin profile
still matches the baseline, covering sessionLocalBuiltinProfiles() behavior
without adding a new test file.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 0b716159-3c2d-46b6-8628-fe3617965390

📥 Commits

Reviewing files that changed from the base of the PR and between a9b1250 and da3e4b6.

📒 Files selected for processing (9)
  • .changeset/isolate-session-profile-catalogs.md
  • packages/agent-core-v2/src/agent/mcp/tools/auth.ts
  • packages/agent-core-v2/test/agent/mcp/tools/auth.test.ts
  • packages/agent-core/src/mcp/auth-tool.ts
  • packages/agent-core/src/profile/agentfile/catalog.ts
  • packages/agent-core/test/mcp/auth-tool.test.ts
  • packages/agent-core/test/profile/agentfile.test.ts
  • packages/kap-server/src/protocol/events-zod.ts
  • packages/protocol/src/events.ts

"@moonshot-ai/kimi-code": patch
---

Prevent one session's subagent tool projection from changing builtin profiles in later sessions.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Use the standard spelling built-in.

Replace builtin profiles with built-in profiles in the public release note.

Proposed wording
-Prevent one session's subagent tool projection from changing builtin profiles in later sessions.
+Prevent one session's subagent tool projection from changing built-in profiles in later sessions.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Prevent one session's subagent tool projection from changing builtin profiles in later sessions.
Prevent one session's subagent tool projection from changing built-in profiles in later sessions.
🧰 Tools
🪛 LanguageTool

[grammar] ~5-~5: Ensure spelling is correct
Context: ... subagent tool projection from changing builtin profiles in later sessions.

(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.changeset/isolate-session-profile-catalogs.md at line 5, Update the public
release note text in isolate-session-profile-catalogs.md to use the standard
spelling “built-in profiles” instead of “builtin profiles,” without changing the
rest of the wording.

Source: Linters/SAST tools

Comment on lines +111 to +115
const waitTimeoutMs = timeoutMs ?? DEFAULT_AUTH_TIMEOUT_MS;
const customData: McpOAuthAuthorizationUrlUpdateData = {
serverName,
authorizationUrl: urlText,
expiresAt: Date.now() + waitTimeoutMs,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Use one start time for expiresAt and OAuth completion.

Both implementations compute expiresAt before update dispatch, then start completion with the full relative timeout. Update-handler work can make the engine wait beyond the advertised expiry.

  • packages/agent-core-v2/src/agent/mcp/tools/auth.ts#L111-L115: pass the remaining duration to flow.complete at Line 132.
  • packages/agent-core/src/mcp/auth-tool.ts#L116-L122: pass the remaining duration to flow.complete at Line 139.
📍 Affects 2 files
  • packages/agent-core-v2/src/agent/mcp/tools/auth.ts#L111-L115 (this comment)
  • packages/agent-core/src/mcp/auth-tool.ts#L116-L122
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/agent-core-v2/src/agent/mcp/tools/auth.ts` around lines 111 - 115,
Use the same start time for the advertised OAuth expiry and completion timeout
in both packages/agent-core-v2/src/agent/mcp/tools/auth.ts:111-115 and
packages/agent-core/src/mcp/auth-tool.ts:116-122. In the corresponding
flow.complete calls, calculate and pass the remaining duration after
update-handler work rather than the original full timeout, using the expiresAt
value established in each auth flow.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Use the configured timeout in all user-visible OAuth messages.

Both implementations calculate a configurable deadline but keep the status text at timeout 15 min. This gives users incorrect instructions when a non-default timeoutMs is used.

  • packages/agent-core-v2/src/agent/mcp/tools/auth.ts#L111-L115: interpolate the effective timeout into the status message.
  • packages/agent-core/src/mcp/auth-tool.ts#L116-L122: interpolate the effective timeout into the status message.
📍 Affects 2 files
  • packages/agent-core-v2/src/agent/mcp/tools/auth.ts#L111-L115 (this comment)
  • packages/agent-core/src/mcp/auth-tool.ts#L116-L122
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/agent-core-v2/src/agent/mcp/tools/auth.ts` around lines 111 - 115,
The OAuth status messages in auth.ts
(packages/agent-core-v2/src/agent/mcp/tools/auth.ts, lines 111-115) and
auth-tool.ts (packages/agent-core/src/mcp/auth-tool.ts, lines 116-122) use a
fixed 15-minute timeout; update both to interpolate the effective timeout value,
such as waitTimeoutMs, so user-visible instructions match the configured
deadline. Both sites require the same direct change.

Comment on lines +65 to +76
const authUpdate = updates.find(
(u) => u.kind === 'custom' && u.customKind === MCP_OAUTH_AUTHORIZATION_URL_TOOL_UPDATE,
);
expect(authUpdate?.customData).toMatchObject({
serverName: 'notion',
authorizationUrl: 'https://example.com/authorize?state=abc',
});
// The deadline is absolute (now + wait timeout), so hosts never mirror
// the engine-side constant.
const { expiresAt } = authUpdate?.customData as { expiresAt?: number };
expect(expiresAt).toBeGreaterThan(Date.now());
expect(expiresAt).toBeLessThanOrEqual(Date.now() + 15 * 60 * 1000);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Make expiry assertions match the configured timeout.

Both tests pass timeoutMs: 100 but accept any expiry up to 15 minutes. This does not detect regressions that ignore the configured timeout.

  • packages/agent-core-v2/test/agent/mcp/tools/auth.test.ts#L65-L76: assert an approximately 100 ms deadline with a controlled clock or tolerance.
  • packages/agent-core/test/mcp/auth-tool.test.ts#L69-L80: assert an approximately 100 ms deadline with a controlled clock or tolerance.
📍 Affects 2 files
  • packages/agent-core-v2/test/agent/mcp/tools/auth.test.ts#L65-L76 (this comment)
  • packages/agent-core/test/mcp/auth-tool.test.ts#L69-L80
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/agent-core-v2/test/agent/mcp/tools/auth.test.ts` around lines 65 -
76, Update the expiry assertions in auth.test.ts lines 65-76 and
auth-tool.test.ts lines 69-80 to verify that expiresAt is approximately
Date.now() plus the configured timeoutMs of 100, using a controlled clock or an
appropriate tolerance. Replace the broad 15-minute upper bound in both test
sites while preserving the existing authorization URL and serverName assertions.

@github-actions github-actions Bot mentioned this pull request Aug 11, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants