Skip to content

fix(api): return parsing-status counts at the top level of each dataset (#17595) - #17611

Merged
JinHai-CN merged 3 commits into
infiniflow:mainfrom
Anai-Guo:fix/list-datasets-parsing-status-top-level-17595
Aug 31, 2026
Merged

JinHai-CN merged 3 commits into
infiniflow:mainfrom
Anai-Guo:fix/list-datasets-parsing-status-top-level-17595

Conversation

@Anai-Guo

Copy link
Copy Markdown
Contributor

Fixes #17595.

Problem

include_parsing_status=true on List Datasets returns the counts nested under a parsing_status object:

{ "parsing_status": { "unstart_count": 0, "running_count": 0, "cancel_count": 0, "done_count": 1, "fail_count": 0 } }

Both references document them as top-level fields of each dataset record:

  • docs/references/http_api_reference.md — the include_parsing_status=true success example lists unstart_count, running_count, cancel_count, done_count, fail_count as siblings of id / name / chunk_count. That example predates fix(api): honor include_parsing_status in List Datasets endpoint #16913 (it is already there at 6e82e27, 2026-06-29).
  • docs/references/python_api_reference.md — "each DataSet object will include the following additional attributes", with the example print(dataset.done_count, dataset.fail_count, dataset.running_count).

#16913 (which fixed #16855) wired the flag up correctly but attached the helper's result as a sub-object, so the shipped shape does not match the contract it was implementing — its own description says the helper "already returned the documented shape".

Fix

Merge the counts into the record instead of nesting them:

if status_by_kb:
    kb.update(status_by_kb.get(kb["id"], {}))

remap_dictionary_keys passes unknown keys through untouched, so the five count fields land at the top level exactly as documented. Behaviour when the flag is absent/false is unchanged — no new keys are added.

Tests

test/unit_test/api/apps/services/test_dataset_api_service_list_datasets.py was added by #16913 and asserted the nested shape, so its expectations move to the documented one. The mock-interaction assertions (helper called once with the kb ids / not called at all, string-coercion of the flag, empty page) are untouched; only the response-shape assertions changed, and the "no counts" checks are now stricter — a shared _assert_no_counts() helper asserts that neither parsing_status nor any of the five count fields appear.

$ pytest test/unit_test/api/apps/services/test_dataset_api_service_list_datasets.py
7 passed

Against unmodified main, the three shape tests fail (test_..._true_attaches_counts, test_..._string_true, test_..._missing_kb_gets_no_counts) and the other four pass, so the suite tracks the fix rather than the implementation.

Note (not addressed here)

The Python SDK's RAGFlow.list_datasets() does not accept include_parsing_status at all, and DataSet.__init__ drops response keys that are not already attributes — so dataset.done_count from the SDK reference cannot work even with this fix. That is a separate gap in sdk/python; happy to follow up in another PR if you'd like it closed too.

🤖 Generated with Claude Code

…et (infiniflow#17595)

The List Datasets endpoint nested the include_parsing_status counts under a
"parsing_status" object, while the HTTP API and Python SDK references both
document them as top-level fields of each dataset record.

Signed-off-by: Anai-Guo <[email protected]>
@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Jul 31, 2026
@coderabbitai

coderabbitai Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f3b4912c-7a73-4ac8-88c5-166a8fa8703a

📥 Commits

Reviewing files that changed from the base of the PR and between ef906c3 and 7b057a1.

📒 Files selected for processing (1)
  • test/unit_test/api/apps/services/test_dataset_api_service_list_datasets.py
💤 Files with no reviewable changes (1)
  • test/unit_test/api/apps/services/test_dataset_api_service_list_datasets.py

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The dataset listing service now returns parsing-status counts as top-level dataset fields. Regression tests cover enabled, disabled, truthy-string, falsy-string, and missing-dataset cases.

Changes

Dataset parsing-status response

Layer / File(s) Summary
Update dataset listing response shape
api/apps/services/dataset_api_service.py
list_datasets adds parsing-status count fields directly to each dataset record instead of nesting them under parsing_status.
Validate top-level count behavior
test/unit_test/api/apps/services/test_dataset_api_service_list_datasets.py
Tests validate top-level counts and reject nested status data across flag and missing-data cases.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 7b057

This change only flattens documented parsing-status counts into each dataset record while preserving behavior when the option is disabled; no actionable merge-blocking risk remains beyond normal checks and review.

Poem

I’m a rabbit with counts in a row,
Top-level fields now clearly show.
Nested status hops away,
Tests guard the new display.
Parsing carrots grow! 🐇

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 76.92% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 13 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main API change: returning parsing-status counts at the top level of each dataset.
Description check ✅ Passed The description provides clear problem context, the proposed fix, test coverage, behavior details, and an explicit note about the separate Python SDK gap. It does not use the template's exact "### Sum…
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.
Full details: Description check

Explanation

The description provides clear problem context, the proposed fix, test coverage, behavior details, and an explicit note about the separate Python SDK gap. It does not use the template's exact "### Summary" heading, but it includes the required summary information and is substantially complete.

  • Fix all pre-merge checks with AI

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.

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (1)
api/apps/services/dataset_api_service.py (1)

456-459: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add structured logging for the new parsing-status flow.

When parsing status is enabled, this code performs an extra service lookup and changes the response enrichment. Add a debug or info log with non-sensitive context, such as the dataset count and flag state. Use the module’s existing logger.

🤖 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 `@api/apps/services/dataset_api_service.py` around lines 456 - 459, Add a debug
or info log in the parsing-status enrichment flow around the status_by_kb lookup
and kb.update, using the module’s existing logger. Include only non-sensitive
context such as the dataset count and whether parsing status is enabled, while
preserving the current response enrichment behavior.

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.

Nitpick comments:
In `@api/apps/services/dataset_api_service.py`:
- Around line 456-459: Add a debug or info log in the parsing-status enrichment
flow around the status_by_kb lookup and kb.update, using the module’s existing
logger. Include only non-sensitive context such as the dataset count and whether
parsing status is enabled, while preserving the current response enrichment
behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 26e266ec-197e-424b-be03-e4aca2d9a1f4

📥 Commits

Reviewing files that changed from the base of the PR and between 5ba8c4f and 0690b65.

📒 Files selected for processing (2)
  • api/apps/services/dataset_api_service.py
  • test/unit_test/api/apps/services/test_dataset_api_service_list_datasets.py

@dosubot dosubot Bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Jul 31, 2026
@Anai-Guo
Anai-Guo force-pushed the fix/list-datasets-parsing-status-top-level-17595 branch from 8a735c5 to 0690b65 Compare July 31, 2026 22:13
@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels Jul 31, 2026
@Anai-Guo

Copy link
Copy Markdown
Contributor Author

Heads-up on the conflict marker: main moved under this branch a few hours after it was opened, and the two files this PR touches were both changed upstream (api/apps/services/dataset_api_service.py and test/unit_test/api/apps/services/test_dataset_api_service_list_datasets.py).

The source-file hunk still merges cleanly — the anchor is unchanged:

if status_by_kb:
    kb["parsing_status"] = status_by_kb.get(kb["id"], {})

The only real conflict is in the regression test. main added

assert "parsing_status" in payload["data"][0]

to test_list_datasets_with_include_parsing_status_true_attaches_counts, which is precisely the nested-shape assertion this PR replaces with top-level count checks. Resolution is "take this branch's version" for that hunk.

I unfortunately can't force-push a rebase myself: my fork can't be synced with main because the token in use lacks the workflow scope and main has since touched .github/workflows/sep-tests.yml, so both merge-upstream and a rebase push are rejected. If it's easier, I'm happy to close this and have someone re-apply the two-line change directly; the substance is just:

if status_by_kb:
    # counts belong at the top level of each dataset record per the HTTP API
    # and Python SDK references, not under a nested "parsing_status" object
    kb.update(status_by_kb.get(kb["id"], {}))

plus flipping the test assertions from record["parsing_status"][...] to record[...].

@JinHai-CN
JinHai-CN requested a review from Lynn-Inf August 19, 2026 12:32

@Lynn-Inf Lynn-Inf 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.

LGTM. This can be merged once conflicts are resolved and CI passes.

@JinHai-CN

Copy link
Copy Markdown
Member

@Anai-Guo Would you please resolve the conflicts?

@Anai-Guo

Copy link
Copy Markdown
Contributor Author

@JinHai-CN Yes — the merge is resolved and green locally (11/11 in test_dataset_api_service_list_datasets.py); I'm waiting on a credential refresh on my side before I can push the synced branch, and I'd rather flag that now than leave you waiting. The conflict is small, so here it is in full in case you'd prefer to take it directly:

main moved the "counts were attached" assertion out of test_list_datasets_with_include_parsing_status_string_true and into test_list_datasets_with_include_parsing_status_true_attaches_counts, then added test_list_datasets_with_ids_filters_query_once in the vacated spot. Two changes resolve it:

  1. In ..._string_true, keep both sides — this PR's assert payload["data"][0]["done_count"] == 1, followed by main's new test_list_datasets_with_ids_filters_query_once.
  2. In ..._true_attaches_counts, the assertion main relocated there — assert "parsing_status" in payload["data"][0] — has to be restated for the top-level shape this PR introduces:
assert "done_count" in payload["data"][0]

Worth calling out: (2) does not show up as a conflict. Git auto-merges it cleanly, and the result is a test that asserts the nested parsing_status key still exists while the rest of the same test asserts it doesn't — so the file only fails once you actually run it. Whoever lands this, please run the module rather than trusting a clean merge.

api/apps/services/dataset_api_service.py merged without conflict and is unchanged from the reviewed version.

🤖 Generated with Claude Code

@JinHai-CN JinHai-CN added the ci Continue Integration label Aug 20, 2026
@JinHai-CN

JinHai-CN commented Aug 20, 2026 •

Copy link
Copy Markdown
Member

@Anai-Guo The PR is conflicts with current code base.

@Taranum01

Copy link
Copy Markdown
Contributor

@JinHai-CN I notice this is still flagged as CONFLICTING. The conflict in test_dataset_api_service_list_datasets.py is now resolved on my fork at Taranum01:pr-17611-conflict-resolution.

If @Anai-Guo pulls the diff from that branch into fix/list-datasets-parsing-status-top-level-17595, the conflict goes away and the PR becomes mergeable. All 11 tests in test_dataset_api_service_list_datasets.py pass after the resolution (just pytest test/unit_test/api/apps/services/test_dataset_api_service_list_datasets.py).

Concretely the conflict was at one block (line ~300 in the test file):

  • main had added test_list_datasets_with_ids_filters_query_once after _string_true and a small set of fixes to _true_attaches_counts that reverted the flat-count contract (it still asserted assert "parsing_status" in payload["data"][0] and by_id["kb-a"]["parsing_status"] == status_by_kb["kb-a"], which is exactly the bug your PR removes).
  • fix(api): return parsing-status counts at the top level of each dataset (#17595) #17611 had refactored _true_attaches_counts to loop for kb_id, counts in status_by_kb.items() so each *_count is asserted at the top level, and added assert payload["data"][0]["done_count"] == 1 at the end of _string_true.

Resolution: keep main's new test, keep #17611's refactored _true_attaches_counts (per the PR review by @Lynn-Inf), keep #17611's new _string_true assertion, and drop main's stale-shape regressed assertions.

If the merge bot still shows DIRTY after the fix-up, a fresh push to the same branch is usually enough to retrigger it.

@Anai-Guo

Copy link
Copy Markdown
Contributor Author

@JinHai-CN — I have the conflict resolved and verified locally, but I currently cannot push the merge commit: merging main into this branch necessarily updates .github/workflows/*, and my token lacks the workflow scope, so both git push and the fork-sync API are refused. I'm getting that scope refreshed; in the meantime here is the full resolution so it isn't blocking you.

api/apps/services/dataset_api_service.py — auto-merges cleanly, no action needed. The fix still applies verbatim: main today still has kb["parsing_status"] = status_by_kb.get(kb["id"], {}) at line 505.

test/unit_test/.../test_dataset_api_service_list_datasets.py — one conflict, and one thing worth flagging, because git's auto-merge is silently wrong here:

  1. Keep upstream's new test_list_datasets_with_ids_filters_query_once (that's the visible conflict — pure append-vs-append, take both sides).
  2. Delete this line from test_list_datasets_with_include_parsing_status_true_attaches_counts:
    assert "parsing_status" in payload["data"][0]
    Upstream relocated that assertion into the same function body this PR rewrites. Git merges it without a conflict marker, and the result contradicts itself two lines later (assert "parsing_status" not in by_id[kb_id]). It encodes the nested contract this PR replaces.

With just that, the file is green: 11 passed (including upstream's new ids test).

Happy to push it the moment I have the scope, or if you'd prefer, the two changes above are small enough to apply directly in the web conflict editor.

@coderabbitai

coderabbitai Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@JinHai-CN

Copy link
Copy Markdown
Member

@Anai-Guo I just resolved the conflicts on web. Would you please help check the code, again?

… flattening

`test_list_datasets_with_include_parsing_status_true_attaches_counts`
asserted `"parsing_status" in payload["data"][0]` and then, three lines
later, `"parsing_status" not in by_id[kb_id]`. The first assertion was
left over from the nested-dict shape this PR replaces; the counts are
now merged at the top level of each record, so it can never hold.

Removing it makes the test consistent with the contract the rest of the
file already checks.

Signed-off-by: Anai-Guo <[email protected]>
@codecov

codecov Bot commented Aug 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 39.07%. Comparing base (6342632) to head (7b057a1).
⚠️ Report is 150 commits behind head on main.

Files with missing lines Patch % Lines
api/apps/services/dataset_api_service.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main   #17611       +/-   ##
===========================================
- Coverage   90.65%   39.07%   -51.58%     
===========================================
  Files          10       54       +44     
  Lines         717    14911    +14194     
  Branches      118      117        -1     
===========================================
+ Hits          650     5827     +5177     
- Misses         39     9058     +9019     
+ Partials       28       26        -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Anai-Guo

Copy link
Copy Markdown
Contributor Author

Friendly ping @Lynn-Inf @JinHai-CN — this has been APPROVED since 2026-08-20 and the branch is still MERGEABLE / CLEAN against main. Is there anything else needed before it can go in?

🤖 Generated with Claude Code

@JinHai-CN
JinHai-CN merged commit b149a39 into infiniflow:main Aug 31, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

4 participants