Skip to content

fix(ragflow): accept numeric update_time from RAGFlow /documents - #114

Closed
Ruidooww wants to merge 1 commit into
mainfrom
fix/ragflow-update-time-number
Closed

fix(ragflow): accept numeric update_time from RAGFlow /documents#114
Ruidooww wants to merge 1 commit into
mainfrom
fix/ragflow-update-time-number

Conversation

@Ruidooww

@Ruidooww Ruidooww commented Jul 1, 2026

Copy link
Copy Markdown
Owner

Summary

  • Widen zod schema for updatedAt / updated_at / update_time in RagflowClientImpl.listDocs to accept both string and number — the running RAGFlow instance returns update_time as a unix timestamp (seconds or ms), which previously failed validation for every doc.
  • Normalize numeric timestamps to ISO strings inside the mapper (auto-detect s vs ms via 1e12 threshold) so RagflowDocument.updatedAt stays typed as string and no downstream consumer changes.
  • Add regression test in ragflow.real.spec.ts covering both seconds and milliseconds inputs.

Why

On the demo branch (#113) the D1 knowledge view was silently rendering the 3-row KNOWLEDGE_FALLBACK_ROWS because KbSyncService.runOnce recorded added:0 / status:failed for every run — the RAGFlow /datasets/:id/documents payload was rejected by zod. Fix unblocks D1 real 204-doc data for the sprint demo.

Test plan

  • pnpm --filter api exec vitest run test/ragflow.real.spec.ts test/kb-sync.service.spec.ts — 19 passed (existing 18 + new regression case)
  • Manual: after api rebuild, POST /api/internal/admin/kb-sync/run returns status:success and kb_documents populates to ~204 rows

🤖 Generated with Claude Code

RAGFlow returns update_time as a unix timestamp number (some deployments
in seconds, some in ms). The zod schema in listDocs response only allowed
z.string(), so parsing failed for every doc, KB sync recorded 0/0/0 and
D1 knowledge view fell back to the hard-coded rows.

Widen the schema to z.union([string, number]) for updatedAt / updated_at /
update_time, and normalize numeric timestamps to ISO strings in the
mapper (auto-detecting seconds vs ms via 1e12 threshold) so downstream
code that expects RagflowDocument.updatedAt: string keeps working
unchanged.

Regression test in ragflow.real.spec.ts covers both s and ms inputs.
@Ruidooww

Ruidooww commented Jul 1, 2026

Copy link
Copy Markdown
Owner Author

Closing as superseded by #115, which merged the demo polish work and includes the broader RAGFlow date parsing, pagination, and chunk_count handling. This PR is now dirty against main and should not be merged separately.

@Ruidooww Ruidooww closed this Jul 1, 2026
@Ruidooww Ruidooww reopened this Jul 1, 2026
@Ruidooww

Ruidooww commented Jul 1, 2026

Copy link
Copy Markdown
Owner Author

Superseded by #115 — same update_time: number fix landed there with a cleaner ragflowDateSchema union + normalizeRagflowDate helper. Verified against apps/api/src/clients/ragflow.ts on main (lines 105, 115-116, 181). Closing without merge.

@Ruidooww Ruidooww closed this Jul 1, 2026
@Ruidooww
Ruidooww deleted the fix/ragflow-update-time-number branch July 1, 2026 07:04
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