Skip to content

feat(pflash): --pflash on|off, with the unified view by default - #878

Merged
davide221 merged 2 commits into
Luce-Org:mainfrom
Graffioh:fix/pflash-unified-long-line
Oct 28, 2026
Merged

davide221 merged 2 commits into
Luce-Org:mainfrom
Graffioh:fix/pflash-unified-long-line

Conversation

@Graffioh

@Graffioh Graffioh commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

PFlash is now --pflash on|off, and the unified view is the default PFlash path. The chat view serves only the requests the unified view cannot take, and the unified view adopts its output, so the conversation stays on one append-only view.

  • --pflash on|off (or --pflash=on) replaces --prefill-compression off|auto|always:
    • on compresses prompts from --prefill-threshold tokens, as auto did.
    • always is gone: --prefill-threshold 0 compresses every prompt.
    • --prefill-compression now fails startup and points to --pflash.
    • The Docker entrypoint takes LUCE_PFLASH=on|off instead of LUCE_PREFILL_MODE.
    • /props reports pflash.mode as "on" or "off".
    • Callers in luce_box (dashboard launchers, eval runners, blog) are updated in Luce-Org/luce_box#567.
  • No PFLASH_UNIFIED. With --pflash on, the unified view serves requests whenever the selection gives per-candidate scores. That means a strict-selection environment, which is what the release profile sets. Selections without per-candidate scores (legacy or split scorer, fold strategy) keep the chat view. If PFLASH_UNIFIED is still set, startup reports it and ignores it. The release profile drops it and now applies 14 defaults.
  • Long lines go to the chat view. Content is paged in whole lines, so a line longer than its region's cap could only be dropped whole. A needle-in-a-haystack prompt is one 119K-token line (as niah_gen.py writes it), so about 91 tokens were served and the answer was wrong. A newest-turn message with an over-cap line now counts as content the view cannot page, like content under five lines. The line is checked twice: against a cap on all of the message's tokens, before scoring, and against the region's own cap, which leaves out the always-kept first and last two lines and the overheads (a line that fits the first can still miss the second when those lines are long). Then:
    • A conversation the view would start is handed back to the chat view, which selects inside the line.
    • A view that continues serves the message verbatim.
    • The log names it: [pflash-unified] message N: a X-token line is over its cap Y (or over its region's cap Y).
  • Adoption after a hand-back. After an uncached or reset_uncached hand-back (cold history, or such a paste), the chat view serves the turn. The unified view then adopts the served prompt as the conversation's view, with no regions. The next turn continues it append-only and reuses its prefix, instead of handing back again. This also covers a tool session the chat view serves whole. Unified stats count it as adopt.<reason>. Trade-off: content the chat view left out of the adopted prompt cannot be recalled later.
  • Agent message mapping. The drafter's query step maps messages by rendering the template with a placeholder per content. An assistant turn that only calls tools has empty content, and a placeholder there changes how the template renders the turn. Agent requests therefore failed the mapping and were served unpaged ("the template does not render message contents verbatim"). Empty contents are now skipped, like system messages. This bug predates this PR.
  • Concurrent serving. Under concurrent serving the unified view reads the prefix-cache measurement the scheduler thread took before handing the request over, as the chat view does. Before, it looked up the prefix cache from the compression worker while the scheduler could change it.
  • Retries that pin new text. A retry of the same messages whose pflash_required text names lines the stored prompt left out is compressed afresh, not answered with that prompt. The unified view already checked its regions. The chat view's repeat now checks its kept spans (this bug predates this PR). An adopted prompt records no kept spans, so with pflash_required it is never repeated.
  • Persisted views. The disk view identity now includes the paging rules' version. Views written under the old rules, such as a needle-less prompt, are no longer replayed or continued; they age out with the cache TTL.

Evidence

Setup: an R9700 (gfx1201) running the release profile with the three published head files, q4_0 KV, --max-ctx 204800 and a fresh --kv-cache-dir per run.

Three 120K needle cases from niah_gen.py, sent to /v1/chat/completions:

served tokens answer correct first token
main 90-91 of 119,910 0/3 13.6-15.1 s
this branch 27,194-27,244 3/3 41.5-42.7 s

The chat view's relevance-spread check passes (0.056-0.069 < 0.11). The scorer ranked the needle segment #2 of 318 even on main; the needle was lost at paging, not at scoring.

Two-turn chat, needle paste then a follow-up question:

  • Turn 1 is handed back, compressed to 27,194 tokens, adopted, and answered correctly in 42.6 s.
  • Turn 2 continues the view, reusing 27,187 tokens, and answers in 0.5 s.

Agent request with an 80,635-token tool output (4,000 lines, key on line 2500), after an empty-content tool-call turn:

served tokens answer time
without the mapping fix 80,635 (nothing paged) correct 135 s
this branch 21,133 (one region paged) correct 64.5 s

In the same session, the follow-up request continued the view and its recall fired.

Tests

  • test_unified_long_line_paste_goes_to_the_chat_view fails on main, where the 12K-token line is replaced by a marker. Here it passes, and a follow-up turn continues the adopted view.
  • test_unified_long_line_tool_output_is_served_whole: a fresh agent turn with a one-line tool output is served raw by the chat view and adopted. The next call continues the view with prefix equality.
  • test_unified_cold_chat_history_is_adopted_after_the_chat_view: turn 1 matches the chat-view-only baseline token for token; turn 2 continues and reuses the snapshot cut.
  • Startup tests: the view is off without a selection environment and off with the legacy scorer.
  • test_unified_long_line_under_the_message_cap_but_over_the_region_cap: two long always-kept lines, then a kiwi line that fits the message's cap but not the region's. It fails without the region check (the line is dropped) and passes here (hand-back, kiwi served).
  • test_unified_repeat_of_an_adopted_prompt_with_a_new_pin_serves_it: an adopted chat-view prompt, then a retry pinning a sentence it dropped. It fails without either the chat-view or the unified-view check.
  • test_entrypoint.sh passes with LUCE_PFLASH.
  • test_server_unit: 1062 passed, 0 failed, 4 skipped; test_tool_checks: 92 passed (HIP build, rebased on 3ef243e).
  • Live smoke on the R9700 with the release profile: 8 private dev rows at 32K-64K, all served by the unified view, no errors, same correct count as before the review fixes.

Not covered

  • Recall into content the chat view dropped from an adopted prompt.
  • Paging inside a long line (sub-line units), which would need markers, re-read hashes and recall below line granularity.
  • There is no switch to turn the unified view off while PFlash is on.
  • No unit test for the empty-content mapping fix: the mock template doesn't branch on empty content. The live agent run above covers it.

🤖 Generated with Claude Code

@Graffioh
Graffioh force-pushed the fix/pflash-unified-long-line branch from c5a8f61 to 62fa792 Compare October 22, 2026 13:03
@Graffioh Graffioh changed the title fix(pflash): a one-line paste over the region cap goes to the chat view instead of being dropped feat(pflash): unified view by default, with the chat view for content it cannot page Oct 22, 2026
@Graffioh Graffioh changed the title feat(pflash): unified view by default, with the chat view for content it cannot page feat(pflash): --pflash on|off, with the unified view by default Oct 22, 2026
@Graffioh
Graffioh force-pushed the fix/pflash-unified-long-line branch from 0991056 to f2b1713 Compare October 23, 2026 08:19
@Graffioh
Graffioh marked this pull request as ready for review October 23, 2026 08:19

@davide221 davide221 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code review

No issues found. Checked for bugs and logic errors in the changed code.

Reviewed f2b1713c · 1 candidate issue checked, kept at ≥70% confidence · add the code-review label to review again

Graffioh and others added 2 commits October 25, 2026 12:18
- A line longer than its cap can take was dropped whole, whatever it scored (a one-line
  paste with its needle). The check runs on the message's tokens and again on the region's
  own cap, which leaves out the always-kept head and tail lines. Such a message sends a view
  the turn would start to the chat view, which selects inside the line; a view that
  continues serves it verbatim.
- Views paged under older rules are not served again (views version bump).
- Tool-call turns with empty content no longer break the request probe's message mapping.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- --pflash on|off replaces --prefill-compression off|auto|always. The old flag and
  LUCE_PREFILL_MODE fail with a hint; the entrypoint takes LUCE_PFLASH=on|off. /props reports
  pflash.mode "on" or "off". --pflash on --prefill-threshold 0 compresses every prompt.
- With --pflash on and the strict-selection environment, the unified view is on, and
  PFLASH_UNIFIED is gone. A request it hands back goes to the chat view, whose prompt it
  adopts, so the next turn continues that prompt.
- Under concurrent serving the unified view reads the prefix cache as the scheduler thread
  measured it, as the chat view does, instead of reading it from the compression worker.
- A retry that pins pflash_required text is not answered with a stored prompt that may have
  left it out: the chat view's repeat checks its kept spans, and an adopted prompt, which
  records none, is compressed afresh.

BREAKING CHANGE: --prefill-compression and LUCE_PREFILL_MODE are removed; use --pflash on|off
and LUCE_PFLASH=on|off.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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