Skip to content

perf(sessions): strip unused per-message fields from the session context (fixes #307) - #454

Merged
kahme247 merged 2 commits into
ompweb-dev:mainfrom
anhnt256:perf/strip-unused-session-fields
Nov 23, 2026
Merged

kahme247 merged 2 commits into
ompweb-dev:mainfrom
anhnt256:perf/strip-unused-session-fields

Conversation

@anhnt256

@anhnt256 anhnt256 commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #307.

Observable behavior changed: opening a long session over a remote link sent large per-message fields the UI never reads. On the reporter's 597-message session the response was 3.7 MB raw (881 KB gzip); without these four fields it is 1.6 MB raw (530 KB), with inputTransformations alone at 53%.

Change: lib/session-reader.ts drops inputTransformations, thinkingSignature, requestControls and contextSnapshot from assistant messages in the display context (entryToUiMessage, next to the existing stripToolResultDetails), so both the context route and the history page benefit. The strip is unconditional rather than deferThinking-only: nothing in components/, hooks/, lib/ or app/ reads these fields (verified by grep; the only mention anywhere is a streaming-delta test fixture), and the on-disk session file keeps the full message.

Tests: new test in lib/session-reader.test.mjs asserts buildSessionContext output carries none of the four fields (with and without deferThinking) while content/model survive; it fails on the unmodified code. lib/session-reader suite: 49 pass / 1 fail — the failure is the flaky native-watcher timeout test, which fails identically on the pristine base. npm run typecheck passes; scoped eslint on both changed files is clean.

Not re-measured locally: the byte saving above is the reporter's measurement on a real long session; no such fixture exists in this environment.

Summary by CodeRabbit

  • Bug Fixes
    • Assistant messages now omit unused provider metadata and signature fields from display content, including when thinking is deferred. Model details and answer text remain visible, and thinking text remains visible when deferral is disabled. Other message content is preserved, so the change is limited to the specified fields rather than altering unrelated content.

@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The session reader now removes selected provider metadata from assistant messages and content blocks during UI conversion. Regression tests check the removal with and without deferred thinking, and verify that text, model metadata, and non-deferred thinking content remain.

Changes: Assistant display messages

Layer / File(s) Summary
Strip and verify assistant fields
lib/session-reader.ts, lib/session-reader.test.mjs
Assistant messages lose inputTransformations, thinkingSignature, requestControls, and contextSnapshot. Object content blocks lose thinkingSignature and textSignature. Tests check that these fields are absent and that selected content is preserved.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Refactor · Severity of issue fixed: Medium

Suggested reviewers: kahme247, andrebrait

Merge Risk: Minimal · up to 21758

This change shrinks the session context payload by removing assistant metadata the UI does not use. Answer text, model, and non-deferred thinking text are preserved. No actionable merge-blocking risk was found.

Security architecture risk: Minimal · up to 21758

Existing session views receive less assistant metadata. The change does not alter who can read a session, which session is read, or what is saved to disk.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The changed exposure is limited to consumers of the existing display conversion, which receive fewer fields for sessions they could already read. The change adds no data source or write path.

Trust Boundaries and Controls

  • observed — The inspected reads still resolve the requested session and handle missing or unreadable files before conversion. The new filter does not participate in target selection or alter those checks.
Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: stripping unused per-message fields from the session context, which matches the stripUnusedAssistantFields change in lib/session-reader.ts and the new test. It uses th…
Linked Issues check Passed Issue #307 asks that buildSessionContext() in lib/session-reader.ts drop inputTransformations, thinkingSignature, requestControls, and contextSnapshot from the session response, at least w…
Out of Scope Changes check Passed The whole-PR diff (merge base c110474 to head 21758ff) changes only lib/session-reader.ts and lib/session-reader.test.mjs. The new helper strips the four #307 fields from assistant messages. It al…
Full details: Title check

Explanation

The title names the main change: stripping unused per-message fields from the session context, which matches the stripUnusedAssistantFields change in lib/session-reader.ts and the new test. It uses the conventional perf(sessions) prefix and references issue #307, which the PR objectives link as the source request.

Full details: Linked Issues check

Explanation

Issue #307 asks that buildSessionContext() in lib/session-reader.ts drop inputTransformations, thinkingSignature, requestControls, and contextSnapshot from the session response, at least when deferThinking is set. The diff adds stripUnusedAssistantFields, which deletes all four fields from assistant messages. It runs inside entryToUiMessage for every assistant message, so the strip applies with and without deferThinking. This meets the requirement. The PR test (per the PR description and raw summary) asserts the four fields are absent with and without deferThinking. The claim that no reader in components/, hooks/, lib/ or app/ uses these fields matches the issue. I did not re-run that search. The on-disk session file is unchanged, as the issue does not require otherwise. Compression and pagination are alternatives in the issue, not requirements, and the PR does not implement them. No unmet coding requirement is found.

Full details: Out of Scope Changes check

Explanation

The whole-PR diff (merge base c110474 to head 21758ff) changes only lib/session-reader.ts and lib/session-reader.test.mjs. The new helper strips the four #307 fields from assistant messages. It also strips thinkingSignature and textSignature from nested assistant content blocks. #307 names thinkingSignature and says it stays in the response with deferThinking=1, so the nested thinkingSignature strip falls within #307. textSignature is not named in #307. It is the same kind of opaque provider signature, and the code comment cites a fixture that shows it nested in text blocks. Its removal serves the same payload goal and does not change rendered output, since transcriptToMarkdown reads only block.thinking and block.text. The PR description does not mention the block-level strip, but the commit messages and the code comment do. This is a minor documentation gap, not an unrelated change. No unrelated change is found.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f9a3f230-d373-4be9-b9de-75450908e9f8
Commits

Reviewing files that changed from the base of the PR and between c110474 and 21758ff.

Files selected for processing: 2

  • lib/session-reader.test.mjs
  • lib/session-reader.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Comment thread lib/session-reader.ts
"contextSnapshot",
] as const;

function stripUnusedAssistantFields(message: AgentMessage): AgentMessage {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔥 The Roast: stripUnusedAssistantFields only deletes keys off the assistant message object itself. Real omp payloads nest thinkingSignature/textSignature inside each content block — the repo's own fixture tests/fixtures/omp-delta-stream.ndjson shows {"type":"thinking","thinking":"...","thinkingSignature":"..."} as a block, not a message-level field. So the claimed 53%-of-payload inputTransformations savings is real, but the signature bytes sail straight through into the UI because nobody walks message.content. You measured half the field and called it done.

🩹 The Fix: Either extend the strip to walk message.content and drop thinkingSignature/textSignature from thinking/text blocks, or confirm via grep that no renderer reads them and say so explicitly in the comment. If they're genuinely unread, add them to the allowlist in transcriptToMarkdown's assistantThinking/assistantText so the omission is visible rather than silent.

📏 Severity: warning

for (const options of [undefined, { deferThinking: true }]) {
const context = buildSessionContext(entries, undefined, options);
const assistant = context.messages[1];
assert.equal("inputTransformations" in assistant, false);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔥 The Roast: This test asserts the four message-level fields vanish — which is exactly what the implementation does, so it's a tautology wearing a lab coat. It proves the code deletes what the code deletes. Nobody here is surprised, including the code.

🩹 The Fix: Add a fixture line carrying a thinkingSignature on a content block and assert it drops (or survives, per the real contract). A test that cannot fail against the spec it claims to encode is just a comment with extra steps.

📏 Severity: nitpick

@kilo-code-bot

kilo-code-bot Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Code Review Roast 🔥

Verdict: No Issues Found | Recommendation: Merge

Oh wait, this PR is actually clean. I need to sit down. I had my flamethrower warmed up and everything.

The block-level signature strip + updated test directly address both prior findings. No new issues spotted in the incremental changes.

📊 Overall: Like finding a unicorn in production — I didn't think clean PRs existed anymore, but here we are.

Files Reviewed (2 files)
  • lib/session-reader.ts
  • lib/session-reader.test.mjs
Previous Review Summary (commit d000483)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit d000483)

Verdict: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
🚨 critical 0
⚠️ warning 1
💡 suggestion 0
🤏 nitpick 1
Issue Details (click to expand)
File Line Roast
lib/session-reader.ts 1149 stripUnusedAssistantFields only deletes message-level keys. Real omp payloads nest thinkingSignature/textSignature inside content blocks (per the repo's own omp-delta-stream.ndjson fixture), so the signature bytes sail through into the UI untouched.
lib/session-reader.test.mjs 295 The new test asserts the four message-level fields vanish — which is exactly what the implementation does, so it's a tautology wearing a lab coat. It cannot fail against the spec it claims to encode.

⚠️ Best part: The strip is unconditional and the on-disk file keeps the full message, so this is a display-context-only optimization — genuinely safe by design, and the stripToolResultDetails precedent shows the team knows how to do this right.

💀 Worst part: The headline claim is that inputTransformations alone is 53% of the payload. If thinkingSignature/textSignature are block-level (as the fixture shows), the measured win is real but incomplete — and the PR's own grep-based "nobody reads these" justification doesn't cover the block-level case at all.

📊 Overall: Like a first pancake — the shape is wrong but the ingredients are there. The intent is right, the allowlist approach is right, but the field list is incomplete and the test proves nothing.

Files Reviewed (2 files)
  • lib/session-reader.ts - 1 issue
  • lib/session-reader.test.mjs - 1 issue

Reviewed by free · Input: 76.9K · Output: 1.4K · Cached: 24.7K

@andrebrait

Copy link
Copy Markdown
Collaborator

Hi @anhnt256, thank you for your contribution, and apologies for the long wait on this PR. We really appreciate the time and effort you have put into it.

We are working through a major refactor of ompweb, including switching to our own build of omp. We are close to finishing that work; once the refactor is complete, we will turn our attention back to the pending PRs, including this one.

Thank you for your patience and for helping improve ompweb!

@kahme247

Copy link
Copy Markdown
Collaborator

Hi, thanks for this PR. It currently conflicts with main and can't be merged as-is — please rebase it onto current main and resolve the conflicts. Once it's rebased I'll re-run the checks.

After the rebase, please confirm the nested signature strip still holds. This fixes #307.

@anhnt256
anhnt256 force-pushed the perf/strip-unused-session-fields branch from a9133bd to 21758ff Compare November 23, 2026 03:33
@anhnt256

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (c110474). There was one conflict in lib/session-reader.ts: main had added the origin decoration (displayMessage) where this PR wraps the message in stripUnusedAssistantFields(...). I resolved it by combining both — the strip runs first, then the origin decoration is applied to the stripped message. That ordering is safe because the strip only touches assistant-message fields, and origin is added to user messages afterwards, so nothing the decoration adds can be stripped.

Session-reader tests: 51/51 pass. The "native watcher refreshes a session after content appends" test passed in this run, so the 15s-timeout failure seen before did not occur. Typecheck is clean.

And confirming what you asked: the nested signature strip still holds after the rebase — the #307 test covers block-level thinkingSignature/textSignature plus the message-level fields in both deferThinking modes, and it passes on the rebased branch.

@kahme247
kahme247 merged commit f1a49cc into ompweb-dev:main Nov 23, 2026
5 checks passed
andrebrait added a commit to ompweb-dev/tau that referenced this pull request Nov 23, 2026
* fix(windows): let in-app updates replace an npm-global install

Port of ompweb-dev/ompweb#519.

* fix(windows): stop a failed host candidate that got the old daemon's pid

Port of ompweb-dev/ompweb#526.

* fix(outbox): prune delivered rows inside the add's write transaction

Port of ompweb-dev/ompweb#535.

* fix(windows): find the host's scheduled task without administrator rights

Port of ompweb-dev/ompweb#539.

* fix(updates): build the tray at release and resume host update downloads

Port of ompweb-dev/ompweb#532. The committed bin/tau-tray.exe was still the omp-web build; releases now build it from native/tray. The omp runner download resume does not apply: tau has no runner download.

* fix(hosts): report pi to the server once it answers after the daemon started

Port of ompweb-dev/ompweb#542. A daemon whose startup read found no pi reads the version again (30 s, doubling to 5 min) and sends a pi_version link message, so a host that gets pi after its daemon started comes online without a restart. The runner download retry does not apply: tau has no runner download.

* docs(agents): note the pi_version link message

* fix(chat): count only completed subagents in the subagents header

Port of ompweb-dev/ompweb#440.

* feat(chat): render svg code fences inline

Port of ompweb-dev/ompweb#455.

* fix(sidebar): mark a completed session seen once it is opened

Port of ompweb-dev/ompweb#336.

* fix(i18n): add the zh-TW completed-subagents summary

Port of ompweb-dev/ompweb#545.

* perf(sessions): strip unused assistant fields from the session response

Port of ompweb-dev/ompweb#454.

* feat(api): app-info handshake and a per-connection heartbeat

Port of ompweb-dev/ompweb#407.

* feat(directory-picker): add a Browse… button that opens the OS folder dialog

Port of ompweb-dev/ompweb#544.

* feat(sessions): navigation-only reads, context ETag and a prompt-less state

Port of ompweb-dev/ompweb#415. A rename now falls back to pi's session_info entry only when pi refused it or the child is gone.

* feat(notifications): answer a pending dialog from the notification

Port of ompweb-dev/ompweb#414, without omp's formDialog and session-move aliases.

* perf(events): hold tool snapshots to one frame per second

Port of ompweb-dev/ompweb#418.

* fix(ui): prevent file-panel tabs from clipping on overflow

Port of ompweb-dev/ompweb#547.

* fix(projects): keep a re-added workspace's display data and avoid worktree path collisions

Port of ompweb-dev/ompweb#554 (rework of ompweb-dev/ompweb#297).

* feat(composer): fullscreen edit mode and one-line collapse for long sent messages

Port of ompweb-dev/ompweb#556.

* docs(changelog): note the ports from ompweb

* chore: use tau names in the ported update and tray code

* fix(markdown): sanitize svg fences with an element allowlist

A tab inside the scheme (java&#9;script:), a prefixed xlink href, <set>/<animate> retargeting an href, and CDATA or processing instructions re-parsed as HTML on insertion all got past the blocklist sanitizer.

* fix(directory-picker): offer the folder dialog only to a page on this machine

Behind a reverse proxy on this machine every connection is loopback, so the page's own Origin (or same-origin Referer) must be loopback too. The picker can be closed while a dialog is pending, and the zenity check runs once.

* fix(composer): queue or steer from the full-screen editor during a run

Send and Ctrl+Enter called handleSend, which ignores a message while a run streams, so the editor closed and nothing was sent.

* fix(notifications): keep a shared child's dialogs announceable after this server leaves it

Leaving a host-owned child that keeps running retracted its pending dialogs permanently, so the next holder could not announce a question that was still waiting. They are now forgotten (a temporary retraction), as after a resync.

* docs(notifications): drop omp-only dialog kinds from the ported comments

* fix(dialogs): answer pi's dialogs under their own ids and show the ask tool's questions

The wrapper still accepted only omp's numeric dialog ids, so every answer to a pi dialog (UUID ids) failed with invalid_ui_response, from the web dialog and from a notification. The ask tool's payload ({questions: [{question, options: string[], multiSelect}]}) reached the dialog unconverted, which expects a question list with option objects; RpcProcess now converts it.

* fix(tray): read tau's settings and logs from ~/.pi/agent

The native tray still read ~/.omp/agent/web-service.json and its logs, so it ignored the saved port, hostname and mode. Releases now build this source (scripts/build-tray.sh).

* fix(hosts): never build the local link URL from an unbracketed IPv6 address

* test(notifications): name the registry-key answer test for what it checks

* test(hosts): give the fake children pi's string dialog ids

* fix(dialogs): keep host tool calls out of dialog answers, and settle a dead child's dialogs for good

A ui_response naming a pending host tool call is refused, so its bookkeeping sees the real host_tool_result. Dialogs are only forgotten when this server leaves a shared child that is still alive. The ask tool's questions get distinct ids, and pageIsLoopback sits above handle's doc comment.

* fix(events): stop releasing held tool snapshots once the sink falls behind

* fix(composer): paste images and leave IME keys alone in the full-screen editor

* fix(directory-picker): require Origin on a non-GET, and read the Windows chooser's path as UTF-8

* fix(worktrees): report an occupied fallback worktree directory as worktree_directory_exists

* fix(notifications): keep pushes within 3993 bytes, refuse expired dialogs and settled replays

* fix(updates): release only the stopped server's own processes and recheck each pid before stopping it

* docs(notifications): name the /api/events notifications channel

* fix(updates): release every install locker after the server stops again

Scoping that release to the stopped trees missed their children on Linux and macOS, where a dead parent's children are re-parented, so the leftover check refused the update.

* fix(notifications): keep the question in a push that drops its dialog, and close expired dialogs in open tabs

* fix(updates): skip a locker whose re-listing fails; document the notifications subscribe body

* fix(updates): fail the install cleanup when a re-listing fails

Skipping the locker let rollback take an unfinished cleanup as done and restore the installation while a runtime still ran from it.

* fix(notifications): do not carry a request id past the dialog id limit

pi's ids are UUIDs; an oversized one could take the push past 3993 bytes on its own.
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.

[Feature] Strip unused per-message fields from the session API response

3 participants