Skip to content

feat: add -kb to make page type classification opt-in - #2554

Open
dogancanbakir wants to merge 1 commit into
devfrom
feat-kb-opt-in
Open

feat: add -kb to make page type classification opt-in#2554
dogancanbakir wants to merge 1 commit into
devfrom
feat-kb-opt-in

Conversation

@dogancanbakir

@dogancanbakir dogancanbakir commented Aug 12, 2026

Copy link
Copy Markdown
Member

Closes #2543

-json/-csv initialized 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

    • Added knowledge base classification via the -knowledge-base and -kb command-line options.
    • Knowledge base classification is automatically enabled when page-type or legacy error-page filters are used.
  • Bug Fixes

    • Improved classifier initialization across supported classification scenarios.
    • Classification setup errors are handled appropriately, allowing execution to continue when classification is optional.
  • Documentation

    • Updated usage documentation with the new knowledge base option.

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown

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

Run ID: 27b0f61f-3e3a-47bf-94b9-57135a6df699

📥 Commits

Reviewing files that changed from the base of the PR and between cb58e92 and 9bcc668.

📒 Files selected for processing (1)
  • runner/runner.go

Walkthrough

The change adds knowledge-base classification configuration, derives classification from page-type filters, updates output settings, and initializes the classifier whenever classification is enabled.

Changes

Classification control

Layer / File(s) Summary
Classification options and derived state
runner/options.go, README.md
Options now includes KnowledgeBase. The -knowledge-base and -kb flags set this field. Page-type filters and deprecated error-page filtering imply classification, and the option is documented.
Conditional runner initialization
runner/runner.go
The runner initializes dit when classification is enabled. Initialization errors are fatal when page-type filtering is configured and are logged otherwise.

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
Loading

Suggested reviewers: ayanrajpoot10

Poem

I’m a rabbit with flags in my tray,
Knowledge-base paths now lead the way.
Filters wake the classifier bright,
Errors choose their proper flight.
Hop, hop—the runner starts just right! 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: adding the -kb flag to make page-type classification opt-in.
Linked Issues check ✅ Passed The changes add opt-in classification, prevent unnecessary model downloads for JSON/CSV output, and preserve classification for explicit filters [#2543].
Out of Scope Changes check ✅ Passed The README, option handling, and classifier initialization changes directly support the linked issue and stated objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat-kb-opt-in

Comment @coderabbitai help to get the list of available commands.

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8114098 and cb58e92.

📒 Files selected for processing (5)
  • README.md
  • runner/classifier.go
  • runner/options.go
  • runner/runner.go
  • runner/runner_test.go

Comment thread runner/classifier.go Outdated
Comment thread runner/runner.go
Comment on lines +434 to +442
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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 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.

Suggested change
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.

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.

Add a flag to disable page-type classification (dit model download) when using -json/-csv

1 participant