community icon indicating copy to clipboard operation
community copied to clipboard

[0.10.118/Windows] Thread distillation always fails: hard-coded 4096→3840 output budget, UsageUnknown, and Discovery FoldOverflow abort even a 4-message thread

Open Beyfish opened this issue 3 weeks ago • 6 comments

Describe the bug

On Nowledge Mem 0.10.118 (Windows), thread distillation is effectively stuck: every retried / freshly scheduled thread_distillation run ends with either distillation_recovery_usage_unknown or distillation_output_invalid, and no memories are saved (covered_messages=0, memories=0).

The scheduler ignores the configured provider max_tokens=16384 and always uses a hard-coded first-attempt output_budget=4096. Its recovery path then lowers the budget to 3840 instead of increasing it. When the model produces reasoning-heavy output, the upstream returns an empty reply / output-token error, or a valid JSON object containing overflow; Nowledge then either:

  1. converts a known provider error into UsageUnknown (because gateway usage is unreported) and locks the run as distillation_recovery_usage_unknown, or
  2. rejects the model's own overflow marker as Contract(Overflow(FoldOverflow { phase: Discovery, bound: ModelDeclared })) and ends with distillation_output_invalid instead of re-chunking / trimming / continuing.

This also reproduces on a 4-message thread, so it is not only a "very long thread" problem.

Environment

  • Nowledge Mem 0.10.118, Windows, local backend; nmem -j status → status=ok, restart_required=false.
  • Provider: magpie:nowledge-agent, OpenAI-compatible gateway http://127.0.0.1:3425/v1.
  • Provider settings: timeout=1800.0, max_tokens=16384.
  • Background purpose: group/longcat-2.5 (restored after testing); comparison purpose: auto/deepseek-v4.1-flash (restored after testing).
  • nmem -j config provider test --purpose background -j → {"success":true,"message":"Connection with key successful","provider":"magpie:nowledge-agent","model":"group/longcat-2.5"}.
  • budget_paused=false, background_lane_pauses=[]; no daily/hourly token budget configured.
  • POST /memories/distill, POST /memories/distill/schedule and nmem threads distill <thread_id> all return enqueued=true / Smart background distillation scheduled.; none is synchronous.

To Reproduce

  1. Configure the provider as above with background=group/longcat-2.5.
  2. Take failed / partially completed thread_distillation runs and start a new Distill for each affected stored thread with force_distill=true (21 threads; 4–4461 messages). Also start a new Distill for a 4-message thread (force_distill=true).
  3. Let the single background worker process the queue.
  4. Inspect GET /agent/knowledge-processing/status?include_history=true, GET /threads/{thread_id}/coverage, and the application log.

POST /memories/distill/triage for the 4-message thread returns {"should_distill":false,"reason":"Content too short"}; force_distill=true bypasses that gate, so the short thread is still a valid minimal reproduction.

Expected behavior

  • The configured max_tokens=16384 (or an explicit, user-configurable initial_output_budget / recovery_output_budget) should be respected. A recovery attempt should increase or fit the budget, not reduce 4096 to 3840.
  • A 4-message thread should be able to finish a fresh distillation and produce coverage.memories > 0.
  • If the model returns well-formed JSON with overflow: true, the ruling fold should split, trim, or continue with another bounded chunk instead of terminating the whole run with FoldOverflow.
  • A known upstream error (empty reply, SSE code=534) should be classified as a provider/dispatch failure, not as UsageUnknown merely because the gateway did not report usage. It should not permanently lock the run with unknown_usage_outcome=true / abandonable=true.
  • New Distill / Retry should not keep increasing automatic_distillation_failure_count and pushing automatic_distillation_next_eligible_at 12–24 hours into the future for what is effectively a fixed client-side budget/contract problem.

Actual behavior / evidence

Latest state at 2026-11-12T15:12:53Z:

  • Of 34 thread_distillation entries in task_history: 31 failed, 3 partial, 0 success.
  • Error kinds: distillation_recovery_usage_unknown 18, distillation_output_invalid 6, distillation_request_timeout_insufficient 5, distillation_recovery_pending 3, distillation_recovery_scope_changed 2.
  • 21 freshly scheduled Distill jobs: 12 terminal (all failed: 8 usage_unknown, 4 output_invalid), 1 running, 8 queued. 0 success.
  • Three 4-message canary jobs are still queued; /threads/<4-message-thread>/coverage remains {"total_messages":4,"covered_messages":0,"memories":0}.
  • nmem -j stats shows memories=7, but those memories came from unrelated memory_created / earlier successful automatic tasks, not from these retried threads. Coverage per affected thread is still 0.

Representative log lines (timestamps UTC; secrets and host paths removed):

2026-11-12T10:18:33.737143Z INFO nmem_server::scheduler_service::generation: scheduler LLM attempt starting attempt=0 task_type=thread_distillation purpose=background wants_json=true output_budget=4096
2026-11-12T10:33:55.292818Z INFO nmem_server::scheduler_service::generation: scheduler LLM attempt finished attempt=0 task_type=thread_distillation purpose=background wants_json=true output_budget=4096 ok=true usage_unreported=true reasoning_only=false finish_reason="stop"
2026-11-12T10:33:55.317083Z INFO nmem_server::scheduler_service::generation: scheduler LLM attempt starting attempt=0 task_type=thread_distillation purpose=background wants_json=true output_budget=3840
2026-11-12T10:53:12.877552Z ... AgentHarness provider stream error (raw) session_id=sched-thread_distillation error=CompletionError: ProviderResponseError: {"error":{"message":"Nous Portal (OAuth): an empty reply (the model answered nothing; try again) — cut at its length, the whole output spent on reasoning","type":"api_error"}}
2026-11-12T10:53:12.886817Z ... ruling fold execution stopped before publication error=UsageUnknown
2026-11-12T10:53:12.934109Z ... scheduler task finished task_id="thread-distill-a26486b67a" task_type=thread_distillation status=failed events=1 error_kind="distillation_recovery_usage_unknown" error_message="The model dispatch outcome and usage are unknown. No memories were saved. ... This run cannot safely send another model call. ... start a new Dist..."
2026-11-12T11:13:17.297767Z ... AgentHarness provider stream error (raw) ... {"error":{"message":"妙手 SSE 错误:code=534 msg=输出token超出 max_tokens,可以尝试让模型精简输出或拆文件输出"}}
2026-11-12T11:13:17.302592Z ... error=UsageUnknown
2026-11-12T11:39:19.108873Z ... ruling fold execution stopped before publication error=Contract(Overflow(FoldOverflow { phase: Discovery, bound: ModelDeclared, observed: None, limit: None }))
2026-11-12T11:39:19.157443Z ... scheduler task finished task_id="thread-distill-261d562e79" task_type=thread_distillation status=failed events=1 error_kind="distillation_output_invalid" error_message="The model could not produce a complete source-bound ruling assessment. No memories were saved." automatic_distillation_failure_count=6 automatic_distillation_next_eligible_at="2026-11-13T11:39:19.117530+00:00"

The Chinese SSE message means: CatPaw SSE error: code=534, output tokens exceeded max_tokens; ask the model to shorten its output or split it across files.

For the distillation_output_invalid path, result_metadata.ruling_fold_rejection contains e.g.:

{"phase":"Discovery","contract":"Overflow","cause":"not_json_rejection","response_bytes":8070,"finish_reason":"stop","present_keys":["proposals","carry","overflow"],"missing_keys":[],"unknown_keys":0,"scanned":true}

The response is valid JSON and explicitly declares overflow, yet the fold is aborted rather than continued.

Workarounds already ruled out (not fixes)

  • Raising provider timeout to 1800 s and max_tokens to 16384: the scheduler still logs output_budget=4096 / 3840.
  • Direct hidden-task Retry: ends with distillation_recovery_scope_changed and the message The conversation, scope, or memory policy changed. Start a new Distill request instead of resuming this run.
  • Fresh POST /memories/distill/schedule with force_distill=true: it enqueues a new run but eventually hits the same budget / UsageUnknown / FoldOverflow paths.
  • Magpie model spec <member> --reasoning off and group pick=catpaw/longcat-2.5: direct probes still contain reasoning_content and all-zero usage; a post-change task still failed distillation_recovery_usage_unknown. This was rolled back.
  • Setting model prices to $0: only affects cost accounting, not the distillation budget; the main model was retained.
  • Temporarily switching purposes.background to auto/deepseek-v4.1-flash: a direct strict-JSON probe returns valid JSON and real usage (prompt_tokens=188, completion_tokens=811, reasoning_tokens=695, total_tokens=999), but the scheduled task thread-distill-20116332a3 still failed distillation_output_invalid with phase=Discovery, contract=Overflow, cause=not_json_rejection, response_bytes=8070. Background was restored to group/longcat-2.5.

Impact

A core workflow is blocked with no working user-side workaround. Each task takes roughly 8–30 minutes on the single worker, then fails, increments the automatic failure count, and sets a long cooldown. Repeating Retry / Distill Only adds more doomed high-priority jobs to the queue. Because the result is enqueued=true with HTTP 200 but no coverage, this is also close to a silent failure from the user's perspective.

Suggested fixes

  1. Expose initial_output_budget and recovery_output_budget in Settings / CLI / API, or derive them from the provider's max_tokens. Recovery must not lower 4096 → 3840.
  2. In the ruling fold, treat a valid overflow response as a continuation signal: re-chunk, trim, or run another bounded fold with the remaining carry, instead of Contract(Overflow(FoldOverflow ...)). Include observed/limit values in the error.
  3. Separate "provider returned a known error" from "provider dispatch/usage is genuinely unknown". Do not convert an empty reply or SSE code=534 into UsageUnknown solely because usage_unreported=true; keep it retryable / eligible for a fresh Distill.
  4. When a gateway returns finish_reason="stop" and a valid JSON body but zero usage, record usage_unknown without treating the entire dispatch as unsafe; allow an explicit user-triggered retry without the 12–24 h automatic cooldown escalation.
  5. Provide a bounded synchronous/preview execution path (or a way to run one selected task ahead of the queue) so users can verify a configuration change without waiting hours behind existing queued distillations.

Related issues

  • #1012 — long-thread Discovery/Synthesis Overflow termination. This report adds that even a 4-message thread fails, that the budget is fixed at 4096 then reduced to 3840, and that provider errors are converted into UsageUnknown.
  • #790 — output-token budget is the wrong cost lever; finish_reason=length is misreported as "no answer".
  • #984 — reasoning-only model burns the 3072 budget and recovery drops scope.
  • #965 — usage_unknown after repeated stalls blocks the queue.
  • #953 — recovery pinned as partial with usage_unknown; Retry returns 409.

Screenshots

N/A; redacted log excerpts and task-history fields are included above.

Additional context

Full redacted task-history JSON, per-thread coverage snapshots, gateway probe results, and bounded queue-verification logs are available on request. No API keys, tokens, or full application logs are included here.

Beyfish avatar Nov 12 '26 15:11 Beyfish

Suggested labels for triage (I could not apply them because this account lacks label permissions): type/bug, severity/major, component/distillation, component/agents, component/ai-providers, impact/silent-failure. Related: #1012, #790, #984, #965, #953.

Beyfish avatar Nov 12 '26 15:11 Beyfish

Confirmed on macOS Apple Silicon with Nowledge Mem 0.10.120 (desktop app, bundled server, and CLI all report 0.10.120).

As of 2026-11-17, the official desktop update endpoint also reports 0.10.120 as latest. The local upgrade check reports current_version=latest_version=0.10.120 and update_available=false. This report therefore describes the currently offered version, not an older installation.

Environment and verified configuration

  • macOS arm64, local desktop backend.
  • Models are accessed through the existing Magpie gateway.
  • The configured provider output ceilings were raised to the models' advertised limits: 384,000 tokens for DeepSeek V4.1 Flash and 128,000 for GPT Luna.
  • Provider request deadlines are 3,600 seconds.
  • Hourly, daily, and per-task additional token budgets are set to 0 (no additional budget).
  • There is no explicit low-reasoning override in the final configuration. The user wants to retain the models' reasoning capability, rather than disable or reduce reasoning to fit the scheduler's output allowance.

Actual results

  1. The scheduler still sends thread_distillation requests with output_budget=4096 and, on another observed fold, 3840, independently of the much larger provider setting.
  2. A diagnostic DeepSeek run explicitly using low reasoning still exhausted all 4,096 output tokens on reasoning and returned no final content. This was a diagnostic test only; the low override was subsequently removed.
  3. A GPT Luna run returned complete JSON with finish_reason="stop", but publication was rejected with Discovery / Overflow / ModelDeclared. The run made five model calls and ended as distillation_output_invalid, with no memories saved.
  4. A separate GPT Luna run did save one Memory, but the task ended partial with distillation_candidates_skipped. This is evidence that the connection and save path can work, not evidence that distillation is fixed.

Representative redacted native diagnostics:

scheduler LLM attempt starting task_type=thread_distillation purpose=background wants_json=true output_budget=4096

ruling fold response rejected by its contract
phase=Discovery contract="Overflow" cause="not_json_rejection"
response_bytes=4551 finish_reason="stop"
top_level="object" missing_keys=[] unknown_keys=0
present_keys=["proposals","carry","overflow"]

ruling fold execution stopped before publication
error=Contract(Overflow(FoldOverflow {
  phase: Discovery, bound: ModelDeclared,
  observed: None, limit: None
}))

scheduler task finished
task_type=thread_distillation status=failed
error_kind="distillation_output_invalid"

The known upstream empty-reply/output-exhaustion error was also classified as distillation_recovery_usage_unknown, even though the gateway record showed a completed response with its entire output allowance consumed by reasoning.

Requested resolution

Could you provide a fixed build or a supported configuration path that addresses all three layers?

  1. Make the effective phase output allowance follow the configured model's output capability, or expose a supported phase-level setting. A recovery attempt should not shrink the allowance from 4096 to 3840. Reasoning should remain available at the user's chosen strength.
  2. Treat a well-formed overflow response as a continuation/repartition signal and retain verified progress, instead of terminating the entire fold. Source-grounding and reference validation should remain intact.
  3. Distinguish a known upstream output-exhaustion/empty-response error from genuinely uncertain dispatch or publication, and provide a recovery path that does not duplicate already committed Memories.

Related: #1012 and #790.

Bulk manual retries were stopped after the unresolved native failure was confirmed. Existing conversations and saved Memories were preserved. No private conversation text, local paths, credentials, account identifiers, or full application logs are included in this report.

aboat0625-cpu avatar Nov 17 '26 11:11 aboat0625-cpu

Sorry for the late reply, and thanks @Beyfish and @aboat0625-cpu for the detailed reports and diagnostic examples on Windows and macOS. We've received your feedback about distillation failing on the output budget and overflow checks, and will look into this with the team as soon as we can.

QingZ11 avatar Nov 20 '26 15:11 QingZ11

感谢转交开发团队。原始会话和现有证据我会继续保留,不把降低 reasoning 强度、删改会话或盲目重复重试当成修复,也不再公开上传整段私人会话。

后续如果修复发布,麻烦在本帖标明 Windows 构建版本/官方配置入口;我可以用同一个四消息小样本复测,分别确认输出预算、overflow 后的恢复,以及保存时是否重复,而不是只看“这次成功了”。如果团队需要更多日志,请具体列出最小脱敏字段,我再按字段补充。当前先等待团队处理,不新增同症状 issue。

Beyfish avatar Nov 20 '26 18:11 Beyfish

Another data point that the distillation budget ignores the provider's max_tokens, this time on 0.10.124 (Linux, self-hosted), with the built-in DeepSeek provider (deepseek-flash, official API, Chat Completions).

Here the recovery does raise the budget, from 3,328 to 13,312, and most folds succeed. The budget still ignores the provider's max_tokens, though, and some folds fail.

The provider's max_tokens does not bound these calls. The 16,384-token attempt of thread-distill-983e29130b started at 15:21:10 UTC and returned 16,384 tokens. At that point the provider's max_tokens was still 8,192: a config backup taken at 15:16:35 UTC holds 8,192, and the new value of 384,000 was saved at 15:21:41.

Numbers between 2026-11-26 14:55 and 2026-11-27 09:30 UTC:

  • Thread distillation tasks: 27 succeeded and 6 failed with distillation_output_limit_reached.
  • First attempt at 3,328: 182 of 236 thread_distillation calls stopped with length.
  • Recovery at 13,312: every call but four finished with stop, at 1,200 to 7,500 output tokens, from inputs of 17,000 to 74,000 tokens.
  • All 491 thread_distillation calls in this window report reasoning_only=false, and the failure fingerprints say reasoning_control=Disabled.

Ruling folds that failed:

Time (UTC) Task Input tokens Budgets (first, recovery)
2026-11-26 15:21:57 thread-distill-983e29130b 871,824 4,096, 16,384
2026-11-26 15:56:54 thread-distill-0dce6ec4fc 37,651 3,328, 13,312
2026-11-26 16:25:17 thread-distill-3072419280 842,225 4,096, 16,384
2026-11-26 18:29:00 task-ab18b64c4db0 62,636 3,328, 13,312
2026-11-26 18:51:34 task-aced694b00f0 40,054 3,328, 13,312
2026-11-27 09:06:02 task-db8fe725355d 62,636 3,328, 13,312

The latest one:

2026-11-27T09:05:06Z scheduler LLM attempt finished ... output_budget=3328 input_tokens=62636 output_tokens=3328 reasoning_only=false finish_reason="length"
2026-11-27T09:05:06Z WARN structured response did not satisfy its contract at the output limit; retrying once previous_output_budget=3328 expanded_output_budget=13312 reported_exhaustion=true
2026-11-27T09:06:02Z scheduler LLM attempt finished ... output_budget=13312 input_tokens=62636 output_tokens=13312 reasoning_only=false finish_reason="length"
2026-11-27T09:06:02Z WARN ruling fold generation failed error=the model exhausted its 13312-token output budget before returning a valid structured response
2026-11-27T09:06:02Z INFO distillation failure fingerprint class="unknown" failure=Truncated wire=ChatCompletions host_class=Official reasoning_control=Disabled json_mode=JsonObject finish_reason=Some(Length)

The UI then says "Choose a model with a larger output limit in Settings > Models". That points to the wrong fix, because the provider is already at its maximum; #790 describes the same problem with the message.

What would help, beyond what this issue already asks:

  • Base the recovery budget on the provider's max_tokens, or allow more than one recovery step.
  • Log the last part of a truncated reply, or flag repetition. The log does not keep the reply, so we cannot tell a long answer from a runaway one.
  • Minor: nmem config provider set has no --max-tokens flag. max_tokens can only be changed with POST /remote-llm/config.

E-Mezzogori avatar Nov 27 '26 09:11 E-Mezzogori

Thanks @E-Mezzogori for the 0.10.124 numbers and breakdown! We've passed your observations on the recovery output cap, provider max_tokens handling, and error messaging along to the team, and we'll update this issue once a release with the fix is out.

QingZ11 avatar Nov 27 '26 09:11 QingZ11