Skip to content

Custom field longtext - #255

Closed
OvisMaximus wants to merge 5 commits into
admonstrator:mainfrom
OvisMaximus:custom_field_longtext
Closed

OvisMaximus wants to merge 5 commits into
admonstrator:mainfrom
OvisMaximus:custom_field_longtext

Conversation

@OvisMaximus

Copy link
Copy Markdown
Contributor

Bugfix: Zettelrobbe lacked a custom field type which exists in paperless-ngx called longtext. this code provides that datatype.
Bugfix: Don't cut LLM results artificially before digesting them.
Refactoring: move code to cope with paperless-ngx enumerables into dataProcessingUtils.js

@admonstrator

Copy link
Copy Markdown
Owner

Thanks a lot, @OvisMaximus! Your ideas landed in #364, rebuilt on the current main: the Long text option, one shared write-back for scan, queue and OCR (which also gives the OCR path custom fields and the restore snapshot), history names taken from the entities that were actually set, the custom field type check on save, and the clearer tag warning. Two things were left out: the Ollama change, because the fixed num_ctx/num_predict would override the configured context and RESPONSE_TOKENS, and the .idea/ files. You are credited as a co-author on the commits. Closing this in favour of #364.

OvisMaximus added a commit to OvisMaximus/zettelrobbe that referenced this pull request Oct 4, 2026
Background
Brings in 34 upstream commits up to v2026.09.03: the shared
documentProcessingService write-back (admonstrator#255), the entity creation guard and
the Duplicates / "Simplify tags" pages, long text custom fields (admonstrator#220), the
ai-processed tag on untagged documents (admonstrator#248), the container restart loop fix
(admonstrator#241), the Playground removal (admonstrator#359) and dependency bumps.

Changes
- Write-back: buildUpdateData()/saveDocumentChanges() in server.js,
  routes/setup.js and mistralOcrService.js are replaced by upstream's
  documentProcessingService. The local helpers in
  services/dataProcessingUtils.js were a subset of it and are removed.
- The local trigger-tag removal (REMOVE_TRIGGER_TAGS in predefined mode)
  moved from server.js into documentProcessingService.saveDocumentChanges(),
  so it now applies to the scan, the queue and the OCR path alike.
- paperlessService keeps the CachedNameIdEnum caches for tags,
  correspondents and document types. Upstream's creation guard runs after
  the enum lookup; _guardEntitiesFromTagCache() reads the enum instead of
  the removed tagCache Map.
- clearTagCache() now invalidates the tag and correspondent enums instead
  of refilling them right away (as its doc comment already said);
  clearDocumentTypeCache() also invalidates the document type enum.
  CachedNameIdEnum gains invalidate().
- listCorrespondentsNames()/listDocumentTypesNames() return { id, name }
  objects again. They returned bare strings, which broke every caller that
  maps `.name` (scan prompt lists, OCR path, dashboard list, Simplify).
- Playground removed as upstream did, including the local
  analyzePlayground() in ollamaService and its truncation test cases.
- Tests: run-tests.js lists both sides' tests; upstream tests that poked
  paperlessService.tagCache use the enum API; entity-creation-guard cases
  now use names the enum lookup does not match, plus a case that pins the
  enum mapping a name holding every word of an existing correspondent.
- Prettier applied to paperlessService.js and serviceUtils.js; OpenAPI
  regenerated (identical to upstream).

Testing
node scripts/run-tests.js --all on Windows with Node 26: 100 passed,
7 skipped, 16 failed. All 16 fail the same way on plain upstream/main or
on the pre-merge HEAD: Windows temp-dir EBUSY/EPERM on cleanup, CRLF
working-tree copies of the CSS (icon-sizing), upstream's changelog lagging
its v2026.09.03 bump (changelog-releases), and the local
llm-ocr-fallback-phrases refactoring test. ESLint and Prettier clean on
the touched files.

Impact
Prefix-like correspondent proposals are still mapped by the local enum
lookup before upstream's guard can only hint at them; the guard records
mappings only for names the lookup does not resolve.

Upstream Status
Merge of upstream/main at 1836fc9.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
admonstrator pushed a commit that referenced this pull request Oct 5, 2026
Background:
The automated bump in 1836fc9 set PAPERLESS_AI_VERSION to v2026.09.03
without a matching block in config/changelog.js, so
test-changelog-releases fails on main and on every PR against it, and
the What's New modal still shows v2026.09.02.

Changes:
- config/changelog.js: v2026.09.03 block summarising what landed on
  main since v2026.09.02 (#220/#255 long text custom fields and the
  type check, #255 history and log fixes, #248 ai-processed tag,
  #241 restart loop, #359 Playground removal).

Testing:
- node scripts/run-tests.js --all: 111 passed, 6 skipped, 0 failed.

Impact:
Release notes only; no behaviour change.

Upstream Status:
Not applicable.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QiLkccEvCtMAgcB1g5dSNM
0cyris pushed a commit to 0cyris/paperless-ai-next that referenced this pull request Oct 16, 2026
…ator#220, admonstrator#255)

Background
Paperless-ngx has a `longtext` custom field type without the 128-character
limit of `string`. The processing path already handled it: the validator
applies the length guard to `string` only, the prompt builders treat any
other type as free text, and the settings route stores whatever type it is
given. Only the type selector in Settings lacked the option, so using a long
text field meant editing the CUSTOM_FIELDS JSON by hand. PR admonstrator#220 and PR admonstrator#255
both add the option.

Changes
- Settings: add "Long text" (`longtext`) to the custom field type selector
  and label `string` as "Text (up to 128 characters)", so the difference is
  visible where the type is chosen.
- New offline test `custom-field-longtext`: a longtext value over 128
  characters passes validation unchanged (line breaks included), a string
  value over 128 is still skipped, and the selector offers both types.
  Registered in the runner under the processing area.

Not taken from admonstrator#255: the buildUpdateData refactor into
dataProcessingUtils.js (the pipeline is being unified separately), the
Ollama change (hard-coded num_ctx 32k and num_predict -1 override the
configured context and RESPONSE_TOKENS budget), and the IDE files.

Testing
- node scripts/run-tests.js --test custom-field-longtext: passes; fails
  against the old view.
- node scripts/run-tests.js --all in a clean worktree: 108 passed,
  7 skipped (need a running server or pdftoppm), 0 failed.
- eslint and prettier clean on the changed JS files.

Impact
UI only: one more option in the custom field type selector. No change to
processing, the API or stored configuration.

Upstream Status
Not applicable (fork-only UI).

Co-Authored-By: rsaether76 <264263539+rsaether76@users.noreply.github.com>
Co-Authored-By: OvisMaximus <5701377+OvisMaximus@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
0cyris pushed a commit to 0cyris/paperless-ai-next that referenced this pull request Oct 16, 2026
Background
server.js (scheduled scan), routes/setup.js (manual queue) and
services/mistralOcrService.js (OCR) each carried their own copy of
buildUpdateData/saveDocumentChanges, and the copies had drifted apart:
- The queue sent the Paperless-ngx update in parallel with the local
  bookkeeping and never checked the result, so a rejected update still
  marked the document as processed and wrote history and metrics. It also
  crashed on metrics-less analyses and did not pass the document id to the
  creation guard.
- The OCR path dropped custom fields entirely, never saved the snapshot
  "restore original" needs, did not apply the AI-processed tag when tagging
  was off, and let a failing document type or correspondent lookup abort
  the whole run.
- The scan crashed on a null custom field entry.
PR admonstrator#255 moved the shared parts into a helper module; this does the same
with the whole write-back.

Changes
- New services/documentProcessingService.js (singleton) with
  buildUpdateData() and saveDocumentChanges(), built from the scan copy
  plus the queue copy's null-entry guard and dashboard invalidation.
- server.js, routes/setup.js and mistralOcrService._runAiAnalysis() call it;
  their copies and the now unused validateCustomFieldValue imports are gone.
- History and the processed list record the document's title when title
  generation is off (the OCR path did this already; the others stored null).
- Tests: new document-processing-service (payload, snapshot order, rejected
  update, title fallback, OCR custom fields, all three call sites);
  mistral-ocr-no-processed-on-update-failure mocks the real processTags()
  contract and asserts the snapshot; ai-processed-tag-without-tags reads
  the new module.

Testing
- node scripts/run-tests.js --all in a clean worktree: 109 passed,
  7 skipped (need a running server or pdftoppm), 0 failed.
- The new test fails against the previous call sites (OCR custom fields,
  local copies).
- Real module graph loads (service, OCR service, routes) without cycles.
- eslint and prettier clean on all changed files; OpenAPI unchanged.

Impact
Queue and OCR processing behave like the scheduled scan. OCR-processed
documents now get custom fields and can be restored. No API or config
change.

Upstream Status
Not applicable (fork-only code path).

Co-Authored-By: OvisMaximus <5701377+OvisMaximus@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
0cyris pushed a commit to 0cyris/paperless-ai-next that referenced this pull request Oct 16, 2026
…admonstrator#255)

Background
The history stored the model's raw answer for correspondent and document
type, not what was written to Paperless-ngx. The two differ whenever the
answer is mapped to an existing entry (another spelling via the creation
guard, a restricted list) or not applied at all (restriction without a
match, detection switched off). The History page then showed names that
exist nowhere in Paperless-ngx, its correspondent filter listed them, the
document type statistics counted them, and a correspondent merge, which
rewrites history rows by name, could not find them. PR admonstrator#255 fixed this by
fetching both names from Paperless-ngx after the update.

Changes
- buildUpdateData() keeps the name of the entity getOrCreateCorrespondent()
  and getOrCreateDocumentType() returned, as history-only keys next to
  _customFieldsForHistory; no extra API request.
- saveDocumentChanges() writes those names to the history and strips them
  from the payload. Nothing set means an empty column.
- Test document-processing-service covers a mapped name and the two
  "not set" cases (restriction without a match, detection off).

Testing
- node scripts/run-tests.js --all in a clean worktree: 109 passed,
  7 skipped (need a running server or pdftoppm), 0 failed.
- The two new cases fail against the previous commit.

Impact
New history rows show the names Paperless-ngx has; rows for fields that
were not set stay empty instead of showing the model's suggestion.
Existing rows are not rewritten.

Upstream Status
Not applicable (fork-only code path).

Co-Authored-By: OvisMaximus <5701377+OvisMaximus@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
0cyris pushed a commit to 0cyris/paperless-ai-next that referenced this pull request Oct 16, 2026
…ype (admonstrator#255)

Background
When a custom field's name already exists in Paperless-ngx, the create
request fails with 400 and createCustomFieldSafely() takes the existing
field instead. Its data type was never compared, so a field added as
"Long text" while Paperless-ngx has it as `string` saved without a word,
and every value over 128 characters was dropped during processing. PR admonstrator#255
added the comparison and turned it into a 400.

Changes
- paperlessService.findCustomFieldTypeConflicts(): refreshes the custom
  field cache once and lists configured fields whose name exists with
  another data_type (case-insensitive); null when Paperless-ngx cannot be
  asked.
- POST /settings runs the check before anything is saved or created and
  answers 400 { success: false, error } naming the field and both types.
  Only fields added or changed in this save are refused; entries configured
  before only warn, so a mismatch in an operator-injected CUSTOM_FIELDS
  cannot lock the settings page. An unreachable Paperless-ngx skips the
  check with a warning instead of blocking the save.
- Unlike admonstrator#255, the save order and the handling of other field creation
  errors stay as they were.
- OpenAPI: the 400 response of POST /settings describes the new case and
  the actual { success, error } body; openapi.json regenerated.
- New offline test settings-custom-field-type-conflict (mount-router):
  refusal without save/create, legacy entry warns only, matching and new
  fields are saved and created, unreachable Paperless-ngx does not block.

Testing
- node scripts/run-tests.js --all in a clean worktree: 110 passed,
  7 skipped (need a running server or pdftoppm), 0 failed.
- The refusal case fails against the previous commit.
- eslint and prettier clean on all changed files.

Impact
Saving Settings can now fail with a clear message when a newly added custom
field conflicts with Paperless-ngx. The settings page already shows the
error text in its dialog.

Upstream Status
Not applicable (fork-only settings).

Co-Authored-By: OvisMaximus <5701377+OvisMaximus@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
0cyris pushed a commit to 0cyris/paperless-ai-next that referenced this pull request Oct 16, 2026
Background
With PROCESS_PREDEFINED_DOCUMENTS=yes, a TAGS value that matches no tag in
Paperless-ngx makes the scan find nothing, and the log only said "None of
the specified tags were found" without saying which ones were looked for.

Changes
- Both warnings in paperlessService (document listing and the TAGS lookup)
  list the configured tag names.

Testing
- node scripts/run-tests.js --all in a clean worktree: 110 passed,
  7 skipped (need a running server or pdftoppm), 0 failed.

Impact
Log text only.

Upstream Status
Not applicable.

Co-Authored-By: OvisMaximus <5701377+OvisMaximus@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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.

2 participants