Skip to content

fix(diagnosis): validate contexts before chunking analysis#215

Merged
himanshu231204 merged 2 commits into
OpenAgentHQ:mainfrom
Nithin00614:fix/validated-contexts
Jul 23, 2026
Merged

fix(diagnosis): validate contexts before chunking analysis#215
himanshu231204 merged 2 commits into
OpenAgentHQ:mainfrom
Nithin00614:fix/validated-contexts

Conversation

@Nithin00614

Copy link
Copy Markdown
Contributor

Summary

Fixes #62.

This PR ensures that ChunkingQualityAnalyzer receives validated string contexts instead of raw evaluation output.

Changes

  • Added context validation before invoking ChunkingQualityAnalyzer
  • Filtered non-string context entries before analysis
  • Added a regression test covering mixed valid and invalid context inputs

Validation

  • Added regression test
  • Diagnosis test suite passes
  • Ruff passes
  • Mypy passes

@himanshu231204

Copy link
Copy Markdown
Member

/oc review pr

@opencode-agent

Copy link
Copy Markdown
Contributor

PR Review: fix/validated-contexts

Summary

Fixes #62 — ensures ChunkingQualityAnalyzer receives validated list[str] contexts instead of raw evaluation output that may contain non-string items.

Changes

File Δ What
analyzer.py +43/-12 New _extract_validated_contexts() helper; metadata validation; context filtering in _extract_scores
test_integration.py +49/-1 Regression test for context validation; Path import moved under TYPE_CHECKING

Review

Correctness: The logic is sound. _extract_validated_contexts filters to isinstance(context, str) and _extract_scores now does the same for counting/length metrics. Metadata is validated to dict or None before passing downstream. The regression test directly verifies non-string entries are stripped.

Minor issues:

  1. Duplicated filtering logic_extract_scores (lines 198-207) and _extract_validated_contexts (lines 220-235) perform identical context extraction + string filtering. Consider having _extract_scores delegate to _extract_validated_contexts to DRY it up.

  2. Indentation inconsistencyanalyzer.py:130-134:

                chunking_issues = self._chunking_analyzer.analyze(
                        question,        # 8-space indent (was 4)
                        contexts,
                        metadata,
                )

This uses an 8-space hanging indent while the rest of the file uses 4-space (e.g., the DiagnosisReport call at line 150). Should be consistent with project style.

Tests: The regression test test_chunking_receives_validated_contexts is well-written — uses a capture proxy instead of mocking the full analyzer, and covers string/dict/int/None cases.

Verdict

Approved with minor nits. Fix the indentation and optionally DRY up the duplicated context filtering.

New%20session%20-%202026-07-23T17%3A25%3A37.336Z
opencode session  |  github run

@himanshu231204
himanshu231204 merged commit e1347e0 into OpenAgentHQ:main Jul 23, 2026
8 checks passed
@github-actions

Copy link
Copy Markdown

🎉 Congratulations @Nithin00614!

Your pull request has been successfully merged into main. 🚀

Thank you for contributing to OpenAgentHQ and helping improve the project.

We truly appreciate your contribution and hope to see you back with more amazing PRs!

Happy Open Sourcing! ❤️

🌟 This is your first merged contribution to this repository.
Welcome to the OpenAgentHQ contributors family!

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.

diagnosis(analyzer): ChunkingQualityAnalyzer receives raw unvalidated contexts from item dict

2 participants