Skip to content

fix: align Zod contracts with runtime data - #7499

Open
c121914yu wants to merge 6 commits into
labring:mainfrom
c121914yu:fix-zod
Open

fix: align Zod contracts with runtime data#7499
c121914yu wants to merge 6 commits into
labring:mainfrom
c121914yu:fix-zod

Conversation

@c121914yu

@c121914yu c121914yu commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

What changed

  • switch system model validation to a type-discriminated union and preserve embedding weight in desensitized models
  • strictly validate normal model update and JSON import APIs before persistence, fill schema defaults, and remove runtime-only fields
  • add an idempotent root-admin data-clean API for legacy system model configurations, with dry-run, safe numeric normalization/defaults, one bulk write, and immediate cache reload on every formal run
  • normalize plugin-provided LLM maxTemperature: null after the final runtime model type is resolved
  • document the model cleanup in the V4.16.0-beta2 Chinese and English upgrade guides
  • normalize legacy team plan records into the strict contract and represent unlimited values as null across backend, cache, API, and UI
  • serialize dataset training dataId through the ObjectId schema and remove the response cast
  • route password request validation through parseApiInput and return rate-limit failures as UserError instances
  • exempt one-time root-admin upgrade and data-clean APIs from product OpenAPI documentation requirements

Why

PR #7493 enabled response parsing and exposed mismatches between strict Zod contracts and historical or runtime values. These changes fix producers and stored data instead of broadly loosening response schemas. Runtime reload also merged plugin null values back into otherwise clean database configurations, so normalization now runs after the final model type is known.

Model cleanup

Call POST /api/admin/dataClean/cleanSystemModelConfigs with {"dryRun":true,"sampleLimit":20} first, then repeat with dryRun:false after reviewing invalidSamples. A formal run always rebuilds the system model cache, even when updated is 0. functionCall remains optional and a missing embedding weight defaults to 0.

Validation

  • 17 targeted model runtime/update/import/data-clean tests
  • 10 targeted system and team OpenAPI contract tests
  • local port 3000 verification: 187 records unchanged, formal cleanup updated 0 and reloaded cache, authenticated init returned 131 active models with no explicit null maxTemperature
  • pnpm --filter @fastgpt/app typecheck
  • ESLint, Prettier, textlint, document reference checks, and pre-commit hooks

Paired enterprise change

  • labring/fastgpt-pro#1060 updates Admin consumers for nullable unlimited quotas and optional legacy renewal fields.

@c121914yu
c121914yu marked this pull request as ready for review August 11, 2026 13:36
Copilot AI lite review requested due to automatic review settings August 11, 2026 13:36
@github-actions

github-actions Bot commented Aug 11, 2026

Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 24.83% 2231 / 8982
🔵 Statements 24.84% 2347 / 9448
🔵 Functions 21.19% 463 / 2184
🔵 Branches 20.13% 1032 / 5125
File CoverageNo changed files found.
Generated in workflow #2174 for commit bb053f0 by the Vitest Coverage Report Action

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6be6bec72b

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +281 to +284
if (totalPoints === null || surplusPoints === null) {
await teamPointCache.clear(teamId);
} else {
await teamPointCache.set({ teamId, totalPoints, surplusPoints });

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep point-cache refresh off the response critical path

This change awaits a Redis write or two-key deletion on every getTeamPlanStatus call, whereas the previous cache refresh was intentionally fire-and-forget. In the inspected upload/presign and team-plan-status request paths, a slow or unavailable Redis instance will now add its timeout latency even though the MongoDB result is already available and the cache implementation treats writes as best-effort; deployments without subscription limits also perform and await the deletion on every call. Refresh or clear the cache without blocking the business response.

Useful? React with 👍 / 👎.

@github-actions

github-actions Bot commented Aug 11, 2026

Copy link
Copy Markdown

Build Successful - Preview fastgpt Image for this PR:

ghcr.io/labring/fastgpt-pr:fastgpt_16f37b7d13716dfa825dacbe9bb6ee4c8e6790bc

🕒 Time: 2026-08-12 00:36:22 (UTC+8)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR tightens runtime producers to match stricter Zod/OpenAPI contracts by normalizing legacy/unlimited plan semantics, improving request input validation, and aligning dataset/system-model payload shapes across backend and frontend.

Changes:

  • Switched password-related API routes to use parseApiInput and extended API tests to cover malformed bodies/injection-shaped inputs.
  • Normalized team plan “unlimited” values to null across wallet status + permission checks, and updated UI to handle null quotas safely.
  • Aligned dataset training dataId serialization with ObjectIdSchema and refined system model validation via a discriminated union.

Reviewed changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
projects/app/test/api/support/user/account/updatePasswordByOld.test.ts Adds assertions for parseApiInput error handling and tightens request typing in tests.
projects/app/test/api/support/user/account/resetExpiredPsw.test.ts Extends malformed-body coverage and reuses a direct handler import for parse-error scenarios.
projects/app/test/api/core/dataset/training/getTrainingError.test.ts Ensures dataId is present in fixtures and asserted as serialized string in responses.
projects/app/test/api/core/dataset/training/getDatasetTrainingError.test.ts Adds dataId fixtures + asserts string serialization for grouped error items.
projects/app/src/pages/api/support/user/account/updatePasswordByOld.ts Routes body validation through parseApiInput for consistent API-boundary errors.
projects/app/src/pages/api/support/user/account/resetExpiredPsw.ts Routes body validation through parseApiInput for consistent API-boundary errors.
projects/app/src/pages/api/core/dataset/training/getDatasetTrainingError.ts Removes response casting so response typing relies on schema parsing/aggregation results.
projects/app/src/pages/account/info/index.tsx Updates plan usage calculations/UI to correctly handle null (unlimited) quotas.
projects/app/src/pageComponents/dashboard/TeamPlanStatusCard.tsx Handles unlimited points display and fixes hide/show logic with time-based re-rendering.
projects/app/src/components/support/wallet/NotSufficientModal/index.tsx Updates points usage display/progress behavior to support null quotas.
packages/service/test/support/wallet/sub/utils.test.ts Adds coverage for legacy plan normalization, fractional points, and null-unlimited normalization.
packages/service/test/support/permission/teamLimit.test.ts Adds tests confirming null quotas disable limits for points/dataset checks.
packages/service/support/wallet/sub/utils.ts Implements unlimited normalization to null and updates cache behavior accordingly.
packages/service/support/permission/teamLimit.ts Updates limit checks to treat null quotas as unlimited (no restriction).
packages/service/core/ai/config/utils.ts Keeps embedding weight in desensitized system models by not blanking it out.
packages/service/common/api/frequencyLimit.ts Wraps rate-limit failure messages in UserError for consistent error handling.
packages/global/test/openapi/common/team.test.ts Adds contract tests for fractional points and null unlimited plan values.
packages/global/support/wallet/sub/type.ts Updates plan schemas to allow fractional points and null unlimited values in client status.
packages/global/openapi/common/system/api.ts Switches system model schema to discriminatedUnion('type', ...).
packages/global/core/dataset/type.ts Validates/serializes training dataId via ObjectIdSchema.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines 173 to 181
it('should reject newPsw as non-string (injection guard)', async () => {
vi.stubEnv('PASSWORD_EXPIRED_MONTH', '1');
const resetExpiredPswApi = await loadResetExpiredPswApi();

const twoMonthsAgo = new Date();
twoMonthsAgo.setMonth(twoMonthsAgo.getMonth() - 2);
await MongoUser.findByIdAndUpdate(testUser._id, {
passwordUpdateTime: twoMonthsAgo
});

@github-actions

github-actions Bot commented Aug 11, 2026

Copy link
Copy Markdown

Docs Preview Deployed!

🔗 👀 Click here to visit preview

ghcr.io/labring/fastgpt-docs-pr:bb053f0319009a09c3dc81d364891d847a8a89df

🕒 Time: 2026-08-12 10:36:55 (UTC+8)

@github-actions

github-actions Bot commented Aug 11, 2026

Copy link
Copy Markdown

Admin Preview Image Ready!

ghcr.io/labring/fastgpt-pr:admin_16f37b7d13716dfa825dacbe9bb6ee4c8e6790bc

🕒 Time: 2026-08-12 00:33:34 (UTC+8)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants