Skip to content

fix: fix session#148

Open
liuzewen99 wants to merge 1 commit intomasterfrom
fix-session
Open

fix: fix session#148
liuzewen99 wants to merge 1 commit intomasterfrom
fix-session

Conversation

@liuzewen99
Copy link
Copy Markdown
Collaborator

@liuzewen99 liuzewen99 commented Apr 14, 2026

Summary by CodeRabbit

  • New Features

    • Added CLI options for create/update: custom session ID, disable session-ID reuse, and OSS/Polar FS storage-config support.
  • Documentation

    • Updated session create/update help and examples (fixed formatting), added storage-config examples, and raised session-update TTL upper bound.
  • Tests

    • Updated unit and e2e session tests to cover new options/flows, adjusted e2e region/default and streamlined test cleanup.

@liuzewen99 liuzewen99 requested a review from rsonghuster April 14, 2026 09:31
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 14, 2026

Warning

Rate limit exceeded

@liuzewen99 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 47 minutes and 50 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 47 minutes and 50 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 882126e5-2929-4af1-ac54-de5129ecdc9f

📥 Commits

Reviewing files that changed from the base of the PR and between af690ea and a13b261.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (6)
  • __tests__/e2e/session/run
  • __tests__/e2e/session/s.yaml
  • __tests__/ut/commands/session_test.ts
  • src/commands-help/session.ts
  • src/resources/fc/index.ts
  • src/subCommands/session/index.ts
📝 Walkthrough

Walkthrough

Adds OSS and Polar FS mount support and new session controls (--session-id, --disable-session-id-reuse); extends CLI help/examples; propagates new options into create/update FC session payloads; updates unit and e2e tests to exercise the new flags and flows.

Changes

Cohort / File(s) Summary
CLI Help
src/commands-help/session.ts
Updated session create/session update help text and examples: added --session-id, --dsr/--disable-session-id-reuse, --oss-mount-config, --polar-fs-config; removed stray punctuation in examples; increased documented --session-ttl-in-seconds upper bound.
CLI Subcommand
src/subCommands/session/index.ts
Added parsing for --disable-session-id-reuse, --oss-mount-config, --polar-fs-config; store parsed JSON (fallback to raw string); include sessionId, disableSessionIdReuse, ossMountConfig, polarFsConfig in create() payload and conditionally include disableSessionIdReuse in update().
FC Resource Implementation
src/resources/fc/index.ts
Refactored session creation to conditionally build nasConfig, ossMountConfig, and polarFsConfig and include them in a unified CreateSessionInput; added sessionId and disableSessionIdReuse to create payload; include disableSessionIdReuse in update payload.
Unit Tests
__tests__/ut/commands/session_test.ts
Added tests verifying --disable-session-id-reuse, --session-id, --oss-mount-config, and --polar-fs-config are parsed and forwarded to createFunctionSession/updateFunctionSession; updated existing expectations to include disableSessionIdReuse.
E2E Tests / Config
__tests__/e2e/session/run, __tests__/e2e/session/s.yaml
Reworked e2e script to use a REGION var, switch test access to default, create a session with --disable-session-id-reuse (capture returned sessionId), adjust update/remove flow and cleanup to handle two sessions, and tweak region defaults.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant CLI as "User CLI"
  participant Subcmd as "Session subcommand"
  participant Resource as "resources/fc.createFunctionSession"
  participant SDK as "FC SDK"
  participant FC as "Function Compute Service"

  CLI->>Subcmd: invoke with flags (session-id, --disable-session-id-reuse, --oss-mount-config, --polar-fs-config)
  Subcmd->>Subcmd: parse flags, JSON.parse storage configs (fallback to string)
  Subcmd->>Resource: call createFunctionSession(config with nas/oss/polar, sessionId, disableSessionIdReuse)
  Resource->>SDK: build CreateSessionInput and call SDK.createSession(...)
  SDK->>FC: HTTP request to create session
  FC-->>SDK: response (sessionId, details)
  SDK-->>Resource: return SDK response
  Resource-->>Subcmd: return created session info
  Subcmd-->>CLI: print JSON result (includes .sessionId)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 I dug new flags from config ground,

OSS and Polar now abound,
IDs chosen, reuse undone,
Sessions hop — two now, not one,
A joyful carrot-coded bound!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title 'fix: fix session' is vague and generic, failing to convey any meaningful information about the specific changes made to the codebase. Use a more descriptive title that highlights the main changes, such as 'feat: add session ID reuse control and OSS/PolarFS mount config support' or 'feat: add disable-session-id-reuse and storage config options to session CLI'
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-session

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 and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

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)
src/subCommands/session/index.ts (1)

82-95: Silent failure on invalid JSON could confuse users.

When JSON.parse fails, the raw string is stored and silently ignored downstream (the mount config condition in fc/index.ts will evaluate to false). This replicates the existing nasConfig pattern (lines 75-80), but users won't know their config was malformed.

Consider logging a warning when JSON parsing fails:

♻️ Suggested improvement
     if (opts['oss-mount-config']) {
       try {
         this.ossMountConfig = JSON.parse(opts['oss-mount-config']);
       } catch (error) {
+        logger.warn(`Failed to parse --oss-mount-config as JSON, will be ignored: ${error.message}`);
         this.ossMountConfig = opts['oss-mount-config'];
       }
     }
     if (opts['polar-fs-config']) {
       try {
         this.polarFsConfig = JSON.parse(opts['polar-fs-config']);
       } catch (error) {
+        logger.warn(`Failed to parse --polar-fs-config as JSON, will be ignored: ${error.message}`);
         this.polarFsConfig = opts['polar-fs-config'];
       }
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/subCommands/session/index.ts` around lines 82 - 95, The OSS and Polar FS
JSON parsing silently fall back to the raw string on parse error; update the
catch blocks for opts['oss-mount-config'] and opts['polar-fs-config'] to log a
warning when JSON.parse throws (mirroring the nasConfig handling) and then
retain the raw string in this.ossMountConfig / this.polarFsConfig; reference the
existing parsing code for nasConfig to reuse the same warning message style and
the same logger (e.g., this.logger.warn or the project's logger) so users are
informed their mount config was malformed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/commands-help/session.ts`:
- Around line 59-62: The help text for the '--region <region>' option in
session.ts uses the wrong documentation URL (2018.html); update the string
literal in the array containing '--region <region>' so it matches the other
occurrences by replacing '2018.html' with '2512917.html' (locate the array entry
near the '--region <region>' help line in session.ts to make the change).
- Around line 121-123: The help text for the session TTL option contains a wrong
upper bound "2512917"; update the option description string for '--st,
--session-ttl-in-seconds <seconds>' (the array entry containing '[Optional]
Session TTL in seconds, between 0 and 2512917') to use the correct max value
21600 to match the create command help and the validation in
src/subCommands/session/index.ts (the validation enforcing max 21600).

In `@src/resources/fc/index.ts`:
- Around line 991-1006: The documentation uses an invalid SDK field name
`bucketRegion`; update the example in src/commands-help/session.ts so it matches
the OSSMountPoint fields used in the code (see OSSMountPoint and OSSMountConfig
usage around config.ossMountConfig and mountPoints) by replacing `bucketRegion`
with the proper fields `bucketPath` and `endpoint` (so the example includes
"bucketPath": "/" and a full "endpoint" URL) so the documented JSON matches the
SDK shape the OSSMountPoint constructor expects.
- Around line 1008-1023: Update the help example JSON in the session help text
so its field names match the SDK PolarFS model: replace "polarDbClusterId" with
"instanceId" and add the required "remoteDir" property (e.g. mountPoints: [{
"instanceId": "pfs-...", "mountDir": "/mnt/polar", "remoteDir": "/" }]) so the
example aligns with PolarFsConfig/PolarFsMountConfig expectations and prevents
users from copying invalid config.

---

Nitpick comments:
In `@src/subCommands/session/index.ts`:
- Around line 82-95: The OSS and Polar FS JSON parsing silently fall back to the
raw string on parse error; update the catch blocks for opts['oss-mount-config']
and opts['polar-fs-config'] to log a warning when JSON.parse throws (mirroring
the nasConfig handling) and then retain the raw string in this.ossMountConfig /
this.polarFsConfig; reference the existing parsing code for nasConfig to reuse
the same warning message style and the same logger (e.g., this.logger.warn or
the project's logger) so users are informed their mount config was malformed.
🪄 Autofix (Beta)

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

Run ID: 35cf4177-7685-4425-980f-414d082bb3f7

📥 Commits

Reviewing files that changed from the base of the PR and between 1fb1c4f and 3a54868.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (3)
  • src/commands-help/session.ts
  • src/resources/fc/index.ts
  • src/subCommands/session/index.ts

Comment on lines 59 to 62
[
'--region <region>',
'[C-Required] Specify fc region, you can see all supported regions in https://help.aliyun.com/document_detail/2512917.html',
'[C-Required] Specify fc region, you can see all supported regions in https://help.aliyun.com/document_detail/2018.html',
],
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Inconsistent region help URL.

Line 61 uses document 2018.html while all other occurrences (lines 17, 38, 95, 115) use 2512917.html. This appears to be an unintended change.

🐛 Proposed fix
           [
             '--region <region>',
-            '[C-Required] Specify fc region, you can see all supported regions in https://help.aliyun.com/document_detail/2018.html',
+            '[C-Required] Specify fc region, you can see all supported regions in https://help.aliyun.com/document_detail/2512917.html',
           ],
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/commands-help/session.ts` around lines 59 - 62, The help text for the
'--region <region>' option in session.ts uses the wrong documentation URL
(2018.html); update the string literal in the array containing '--region
<region>' so it matches the other occurrences by replacing '2018.html' with
'2512917.html' (locate the array entry near the '--region <region>' help line in
session.ts to make the change).

@liuzewen99 liuzewen99 force-pushed the fix-session branch 4 times, most recently from a975feb to 8daee0f Compare April 15, 2026 07:01
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
src/commands-help/session.ts (1)

119-119: ⚠️ Potential issue | 🟡 Minor

TTL upper bound 2512917 is incorrect — should be 21600.

The value 2512917 matches the Aliyun document ID pattern (seen in help URLs). The create command help (line 68) correctly shows between 0 and 21600, and the validation in src/subCommands/session/index.ts (lines 190-195) enforces 21600 as the max.

🐛 Proposed fix
           [
             '--st, --session-ttl-in-seconds <seconds>',
-            '[Optional] Session TTL in seconds, between 0 and 2512917',
+            '[Optional] Session TTL in seconds, between 0 and 21600',
           ],
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/commands-help/session.ts` at line 119, The help text for the Session TTL
currently states an incorrect upper bound "2512917"; update the string entry
"'[Optional] Session TTL in seconds, between 0 and 2512917'" to use the correct
max "21600" so it reads "'[Optional] Session TTL in seconds, between 0 and
21600'"; ensure this matches the existing validation in the create subcommand
(the create command's help and the validation in the session create handler) so
that the 'Session TTL' help and the validation logic are consistent.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/commands-help/session.ts`:
- Line 53: The example OSS mount JSON in the session command uses an incorrect
region string for bucketPath; update the oss-mount-config example to use a valid
bucket path (e.g., "/" or "/data") instead of "cn-hangzhou". Specifically,
modify the example JSON's "bucketPath" field in the session help/example (the
oss-mount-config snippet) to a semantic bucket path like "/" or "/data" so it
matches the SDK expectation for bucketPath.

---

Duplicate comments:
In `@src/commands-help/session.ts`:
- Line 119: The help text for the Session TTL currently states an incorrect
upper bound "2512917"; update the string entry "'[Optional] Session TTL in
seconds, between 0 and 2512917'" to use the correct max "21600" so it reads
"'[Optional] Session TTL in seconds, between 0 and 21600'"; ensure this matches
the existing validation in the create subcommand (the create command's help and
the validation in the session create handler) so that the 'Session TTL' help and
the validation logic are consistent.
🪄 Autofix (Beta)

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

Run ID: 8728c9c0-48a3-4027-b24a-69a031e5d938

📥 Commits

Reviewing files that changed from the base of the PR and between 3a54868 and 8daee0f.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (6)
  • __tests__/e2e/session/run
  • __tests__/e2e/session/s.yaml
  • __tests__/ut/commands/session_test.ts
  • src/commands-help/session.ts
  • src/resources/fc/index.ts
  • src/subCommands/session/index.ts
✅ Files skipped from review due to trivial changes (2)
  • tests/e2e/session/s.yaml
  • tests/ut/commands/session_test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/subCommands/session/index.ts

$ s cli fc3 session create --region cn-hangzhou --function-name my-function --qualifier LATEST --session-ttl-in-seconds 600 -a default
$ s cli fc3 session create --region cn-hangzhou --function-name my-function --qualifier LATEST --nas-config '{"userId": 1000, "groupId": 1000, "mountPoints": [{"serverAddr": "example.nas.aliyuncs.com:/", "mountDir": "/mnt/nas", "enableTLS": true}]}' -a default`,
$ s cli fc3 session create --region cn-hangzhou --function-name my-function --qualifier LATEST --nas-config '{"userId": 1000, "groupId": 1000, "mountPoints": [{"serverAddr": "example.nas.aliyuncs.com:/", "mountDir": "/mnt/nas", "enableTLS": true}]}' -a default
$ s cli fc3 session create --region cn-hangzhou --function-name my-function --qualifier LATEST --oss-mount-config '{"mountPoints": [{"bucketName": "my-bucket", "bucketPath": "cn-hangzhou", "mountDir": "/mnt/oss", "readOnly": false}]}' -a default
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

The bucketPath example value is semantically incorrect.

The example shows "bucketPath": "cn-hangzhou" which appears to be a region name, not a bucket path. According to the SDK documentation, bucketPath should be the path within the OSS bucket (e.g., "/", "/data").

This likely stems from confusion with the previously incorrect bucketRegion field that was removed.

🐛 Proposed fix
-  $ s cli fc3 session create --region cn-hangzhou --function-name my-function --qualifier LATEST --oss-mount-config '{"mountPoints": [{"bucketName": "my-bucket", "bucketPath": "cn-hangzhou", "mountDir": "/mnt/oss", "readOnly": false}]}' -a default
+  $ s cli fc3 session create --region cn-hangzhou --function-name my-function --qualifier LATEST --oss-mount-config '{"mountPoints": [{"bucketName": "my-bucket", "bucketPath": "/", "endpoint": "http://oss-cn-hangzhou.aliyuncs.com", "mountDir": "/mnt/oss", "readOnly": false}]}' -a default
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/commands-help/session.ts` at line 53, The example OSS mount JSON in the
session command uses an incorrect region string for bucketPath; update the
oss-mount-config example to use a valid bucket path (e.g., "/" or "/data")
instead of "cn-hangzhou". Specifically, modify the example JSON's "bucketPath"
field in the session help/example (the oss-mount-config snippet) to a semantic
bucket path like "/" or "/data" so it matches the SDK expectation for
bucketPath.

@liuzewen99 liuzewen99 force-pushed the fix-session branch 2 times, most recently from 67c9cec to af690ea Compare April 15, 2026 09:38
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

♻️ Duplicate comments (2)
src/commands-help/session.ts (2)

119-119: ⚠️ Potential issue | 🟡 Minor

Update TTL max in help to match actual validation.

Line 119 says between 0 and 2512917, but src/subCommands/session/index.ts (Line 190-195) enforces 0..21600. This mismatch causes incorrect CLI guidance.

🐛 Proposed fix
           [
             '--st, --session-ttl-in-seconds <seconds>',
-            '[Optional] Session TTL in seconds, between 0 and 2512917',
+            '[Optional] Session TTL in seconds, between 0 and 21600',
           ],
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/commands-help/session.ts` at line 119, The help text for the session TTL
is incorrect; update the string "'[Optional] Session TTL in seconds, between 0
and 2512917'" in commands-help/session.ts to match the validator's range
(0..21600) used in the session subcommand (see validation in
src/subCommands/session/index.ts around the TTL checks), so the CLI help
accurately reflects the enforced maximum of 21600 seconds.

53-53: ⚠️ Potential issue | 🟡 Minor

Fix OSS example: bucketPath should be a path, not a region.

Line 53 uses "bucketPath": "cn-hangzhou", which is semantically incorrect for a bucket path and can mislead users.

🐛 Proposed fix
-  $ s cli fc3 session create --region cn-hangzhou --function-name my-function --qualifier LATEST --oss-mount-config '{"mountPoints": [{"bucketName": "my-bucket", "bucketPath": "cn-hangzhou", "mountDir": "/mnt/oss", "readOnly": false}]}' -a default
+  $ s cli fc3 session create --region cn-hangzhou --function-name my-function --qualifier LATEST --oss-mount-config '{"mountPoints": [{"bucketName": "my-bucket", "bucketPath": "/", "mountDir": "/mnt/oss", "readOnly": false}]}' -a default
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/commands-help/session.ts` at line 53, The OSS example in the CLI usage
string in session.ts incorrectly sets "bucketPath" to a region ("cn-hangzhou");
update that example value to a valid bucket path (e.g. "/" or "/path/to/dir") in
the OSS mount config JSON in the usage/example string so the "bucketPath"
semantically represents a path rather than a region; locate the CLI example
string around the OSS mount config (the literal containing "oss-mount-config"
and "mountPoints") and replace the "bucketPath": "cn-hangzhou" token with a
proper path value.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@src/commands-help/session.ts`:
- Line 119: The help text for the session TTL is incorrect; update the string
"'[Optional] Session TTL in seconds, between 0 and 2512917'" in
commands-help/session.ts to match the validator's range (0..21600) used in the
session subcommand (see validation in src/subCommands/session/index.ts around
the TTL checks), so the CLI help accurately reflects the enforced maximum of
21600 seconds.
- Line 53: The OSS example in the CLI usage string in session.ts incorrectly
sets "bucketPath" to a region ("cn-hangzhou"); update that example value to a
valid bucket path (e.g. "/" or "/path/to/dir") in the OSS mount config JSON in
the usage/example string so the "bucketPath" semantically represents a path
rather than a region; locate the CLI example string around the OSS mount config
(the literal containing "oss-mount-config" and "mountPoints") and replace the
"bucketPath": "cn-hangzhou" token with a proper path value.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 815b90ce-e1c5-401d-a731-31570bbf9542

📥 Commits

Reviewing files that changed from the base of the PR and between 8daee0f and af690ea.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (6)
  • __tests__/e2e/session/run
  • __tests__/e2e/session/s.yaml
  • __tests__/ut/commands/session_test.ts
  • src/commands-help/session.ts
  • src/resources/fc/index.ts
  • src/subCommands/session/index.ts
✅ Files skipped from review due to trivial changes (1)
  • tests/e2e/session/s.yaml
🚧 Files skipped from review as they are similar to previous changes (4)
  • tests/ut/commands/session_test.ts
  • src/resources/fc/index.ts
  • tests/e2e/session/run
  • src/subCommands/session/index.ts

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