feat: add -kb to make page type classification opt-in - #2554
feat: add -kb to make page type classification opt-in#2554dogancanbakir wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughThe change adds knowledge-base classification configuration, derives classification from page-type filters, updates output settings, and initializes the classifier whenever classification is enabled. ChangesClassification control
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant RunnerOptions
participant Runner
participant dit
RunnerOptions->>Runner: Enable classification from flags or filters
Runner->>dit: Create classifier with dit.New()
dit-->>Runner: Return classifier or initialization error
Runner-->>RunnerOptions: Continue or return an error based on filters
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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.
Inline comments:
In `@runner/classifier.go`:
- Around line 19-21: Protect the temporary default logger replacement in
Runner.New with a package-level mutex, locking before slog.Default is saved and
slog.SetDefault installs gologgerSlogHandler, and unlocking only after the
deferred restoration completes. Ensure the mutex covers the entire save,
replacement, and restore sequence so overlapping Runner.New calls cannot leave
the temporary handler installed.
In `@runner/runner.go`:
- Around line 434-442: Update the newDitClassifier error handling within the
classificationEnabled path to return the wrapped initialization error
unconditionally, removing the hasPageTypeFilter distinction and non-fatal
logging path. Ensure every enabled-classification failure prevents returning a
Runner with a nil classifier.
🪄 Autofix
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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 3be27126-e8e0-40d8-82b4-83d33926eb23
📒 Files selected for processing (5)
README.mdrunner/classifier.gorunner/options.gorunner/runner.gorunner/runner_test.go
| if options.classificationEnabled() { | ||
| ditClassifier, err := newDitClassifier() | ||
| if err != nil { | ||
| gologger.Warning().Msgf("Could not initialize page classifier: %s", err) | ||
| // without a classifier the page type filters silently pass | ||
| // everything through, so a failure is fatal when one is in use | ||
| if options.hasPageTypeFilter() { | ||
| return nil, errors.Wrap(err, "could not initialize page classifier") | ||
| } | ||
| gologger.Error().Msgf("Could not initialize page classifier: %s", err) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Return an error when explicit classification initialization fails.
With -kb and no page-type filter, Lines 436-442 log the error and return a Runner with a nil classifier. classifyPage then emits only pHash, without PageType or Forms. The command reports success although requested classification is unavailable.
Return the initialization error for every classificationEnabled() path.
Proposed fix
if options.classificationEnabled() {
ditClassifier, err := newDitClassifier()
if err != nil {
- // without a classifier the page type filters silently pass
- // everything through, so a failure is fatal when one is in use
- if options.hasPageTypeFilter() {
- return nil, errors.Wrap(err, "could not initialize page classifier")
- }
- gologger.Error().Msgf("Could not initialize page classifier: %s", err)
+ return nil, errors.Wrap(err, "could not initialize page classifier")
}
runner.ditClassifier = ditClassifier
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if options.classificationEnabled() { | |
| ditClassifier, err := newDitClassifier() | |
| if err != nil { | |
| gologger.Warning().Msgf("Could not initialize page classifier: %s", err) | |
| // without a classifier the page type filters silently pass | |
| // everything through, so a failure is fatal when one is in use | |
| if options.hasPageTypeFilter() { | |
| return nil, errors.Wrap(err, "could not initialize page classifier") | |
| } | |
| gologger.Error().Msgf("Could not initialize page classifier: %s", err) | |
| if options.classificationEnabled() { | |
| ditClassifier, err := newDitClassifier() | |
| if err != nil { | |
| return nil, errors.Wrap(err, "could not initialize page classifier") | |
| } | |
| runner.ditClassifier = ditClassifier | |
| } |
🤖 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 `@runner/runner.go` around lines 434 - 442, Update the newDitClassifier error
handling within the classificationEnabled path to return the wrapped
initialization error unconditionally, removing the hasPageTypeFilter distinction
and non-fatal logging path. Ensure every enabled-classification failure prevents
returning a Runner with a nil classifier.
cb58e92 to
9bcc668
Compare
Closes #2543
-json/-csvinitialized the dit classifier, downloading a ~92MB model with no way to opt out. Classification is now opt-in via-kb, implied by-fpt/-fep.Supersedes #2544 (thanks @jatinder14).
Summary by CodeRabbit
New Features
-knowledge-baseand-kbcommand-line options.Bug Fixes
Documentation