Skip to content

fix(chat): count each container's first member in the /btw item cap - #3133

Merged
devswha merged 1 commit into
mainfrom
fix/omp-btw-item-count
Nov 6, 2026
Merged

devswha merged 1 commit into
mainfrom
fix/omp-btw-item-count

Conversation

@devswha

@devswha devswha commented Nov 6, 2026

Copy link
Copy Markdown
Owner

Part of #3024 (follow-up of #3019, opt-in Side conversations chip for OMP /btw).

What

GET /api/pane/btw skips a topic file of more than 20,000 JSON items before parsing it. The pre-parse count took {, [ and , outside strings, so the first member of every non-empty container went uncounted: nested single-item arrays could carry about twice the cap (Codex's MEDIUM on #3024). The count now also counts a container's first member where it starts (skipping whitespace; [] and {} add nothing), so it counts every member and container.

Only reached with hand-made history files while a device has Settings → Chat → Composer → Side conversations chip (experimental) turned on (off by default). No changelog fragment: the feature is unreleased, and its changelog entry is unchanged.

Not changed (LOW on #3024, left as they are)

  • The 200 ms listing clock cannot interrupt a blocking filesystem call.
  • The listing stops at 2,000 entries, .title files included, so a topic past that point in a session of more than 1,000 topics stays unseen.
  • Phone Back with an enlarged diagram, and Shift+Tab leaving the list open (neither reproduced).
  • The cache's text budget counts UTF-16 code units, not bytes.

Validation

  • Failing first: the new test in server/omp-btw.test.ts (1,500 chains of eleven nested single-item containers, about 34,500 items, about 18,000 when counted the old way) failed on main (the topic was listed), then passed.
  • bun test server/omp-btw.test.ts: 13 pass, 0 fail.
  • bun run typecheck: pass.
  • bun run check fast: all green (workflow syntax, generated types and themes, typecheck, build, unit 12618 pass / 0 fail / 50 skip).
  • Skipped: integration and browser suites (server-only change to a pure helper; the route's contract test is unchanged).

The pre-parse JSON item count missed the first member of every non-empty container, so nested single-item arrays could pass at about twice the 20,000-item cap. Part of #3024.
@coderabbitai

coderabbitai Bot commented Nov 6, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 15 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 74976f2 and 3999510.

Files selected for processing: 2

  • server/omp-btw.test.ts
  • server/omp-btw.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@devswha

devswha commented Nov 6, 2026

Copy link
Copy Markdown
Owner Author

Reviews at 3999510:

  • omo (dori review): CLEAR.
  • Codex (adversarial, Terra 6.1 xhigh): no HIGH, MEDIUM or LOW. It fuzzed 30,000 generated JSON trees (nested containers, escapes, Unicode, lone surrogates) and every BMP character as whitespace, and found no undercount and no false skip. The real loader accepts 19,999 and 20,000 items and skips 20,001 and 20,002 with more: true.
  • CodeRabbit: rate limited ("Review limit reached"), so no CodeRabbit review ran on this head.

Unresolved review threads: 0. The LOW items of #3024 stay open there, as listed in the PR body.

@devswha

devswha commented Nov 6, 2026

Copy link
Copy Markdown
Owner Author

Local merge gate: PASS

Local merge gate: PASS #3133 merge=e6c173e0b78d head=3999510130e6 main=39be94de3bca on herdr-ci-runner:local on devswha-ThinkStation-P620 CPUs 64-127 in 623s, reruns=1

The Linux suites of the required checks (Fast checks, Integration and browser), run on main 39be94d with this PR's head 3999510 merged in (local merge e6c173e0b78d, not pushed), as groups side by side in the self-hosted CI runner image on herdr-ci-runner:local on devswha-ThinkStation-P620 CPUs 64-127 (15% busy before the start, host load 92.81; shards=4 unit_workers=8 browser_main_workers=2 browser_other_workers=16). Scope: full. Native Windows install and the macOS checks are not part of this gate.

Step Command Result Seconds Counts
fast-install bun install --frozen-lockfile pass 0 -
release-guards bun scripts/release-guards.ts --base 39be94de3bca pass 0 -
fast bun run check fast pass 208 tests 12629 pass / 0 fail; check steps 6 ok / 0 failed
integration-install bun install --frozen-lockfile pass 0 -
integration bun run check integration pass 215 tests 1232 pass / 0 fail; check steps 3 ok / 0 failed
browser-main-install bun install --frozen-lockfile pass 0 -
browser-main-build bun run build pass 12 -
browser-main BROWSER_SCRIPTS=ui-regression,ui-contexts-regression bun run check run -- bun scripts/ci-browser-parallel.ts pass 578 browser scripts 2/2 passed
browser-other-install bun install --frozen-lockfile pass 0 -
browser-other-build bun run build && bun run build:shell pass 16 -
browser-other BROWSER_EXCLUDE=<those two> bun run check run -- bun scripts/ci-browser-parallel.ts pass 599 browser scripts 174/174 passed

Reruns:

  • browser scripts/ui-contexts-regression.ts failed, then passed on its automatic second run

Total 623s.

@devswha

devswha commented Nov 6, 2026

Copy link
Copy Markdown
Owner Author

Merge note (merge pass) at head 3999510:

  • omo review receipt: CLEAR at this exact head; Codex adversarial pass found nothing. Unresolved review threads: 0 (GraphQL). CodeRabbit: rate-limited, no review ran on this head; gated on the reviewers and the local gate instead.
  • Local merge gate: PASS on main 39be94d + this head (comment above): check fast, integration, both browser groups in the CI runner image. ui-contexts-regression failed once (notification-view page error "Cannot set properties of undefined (setting 'isWrapped')") and passed on its automatic rerun; this PR only touches server/omp-btw.ts.
  • Merged on the local gate instead of waiting for GitHub's browser jobs; origin/main had not moved since the gated main.
  • Part of OMP /btw history read: bound empty follow-ups, the folder scan and the stat-to-read window #3024: the remaining LOW items stay open there.

@devswha
devswha merged commit 340cefb into main Nov 6, 2026
20 checks passed
@devswha
devswha deleted the fix/omp-btw-item-count branch November 6, 2026 06:29
devswha added a commit that referenced this pull request Nov 6, 2026
…er reflow with no scrollback (#3140)

## Problem

Browser regressions on unrelated PRs (#3130 twice on GitHub, #3133 once
locally) failed with the page error `Cannot set properties of undefined
(setting 'isWrapped')`, first seen in
`scripts/notification-view-regression.ts` (the pane split, then the
agent pane closing, resizes the terminal).

## Cause

Two bugs in xterm 6.0.0 itself, both still on xterm's `master`:

1. `Buffer._reflowSmaller`: when a narrower width wraps rows and the
cursor's row is pushed to the bottom, the `ybase === 0` branch raises
`ybase` with no bound. The other branch keeps `ybase` under
`min(maxLength, length + inserted) - rows`; this one does not. With
Ovis's `scrollback: 0` (`maxLength === rows`), `ybase` becomes 1 on a
buffer of exactly `rows` lines, so the cursor's row `ybase + y` is past
the buffer's end. Writes there land on the top row (the circular list
wraps around), and after the next taller resize the row is `undefined`,
so `lineFeed` or `print` throws on `.isWrapped`. Reproduced with `bun
test`: 40x5 terminal with three 35-cell rows, `resize(10, 5)` leaves
`baseY + rows = 6` on a 5-line buffer; `resize(5, 8)` and a write throw.
2. `InputHandler.eraseInDisplay` case 1 (`ESC[1J` from a row's last
column) unwraps `lines.get(j + 1)`, where `j` is a screen row, not a
buffer row (`ybase` is missing). In a scrolled buffer it unwraps a
history row instead of the screen row below the cursor. From the
screen's last row it reaches past the buffer's end, which throws the
same error once the buffer keeps history (herdr-core panes,
`terminal-history`).

Not a write/dispose race: writes after `dispose()` and writes
interleaved with resizes on a sound buffer were checked and do not
throw.

## Change

`patches/@XTerm%[email protected]` (regenerated with `bun patch`):
- `Buffer.ts`: the `ybase === 0` branch uses the same bound as the other
branch. With no scrollback, the reflow then trims the top row instead.
- `InputHandler.ts`: `ESC[1J` unwraps `lines.get(ybase + j + 1)` only
when that row is on screen, except after a selective erase (`CSI ? 1 J`,
DECSED) that left protected cells on the cursor's row, which the next
row still continues.

## Tests

- New `src/lib/terminalReflow.test.ts` (patched xterm, as
`terminalWidths.test.ts` uses it):
- The narrower-reflow case keeps `baseY + rows <= length`, the cursor
stays on its own row, and a taller resize plus a write works. On
origin/main's patch it fails with `Expected: <= 5, Received: 6`.
- `ESC[1J` in a scrolled buffer unwraps the screen row below the cursor.
On main it fails with `isWrapped` still `true`.
- `ESC[1J` from the last row does not throw. On main it throws the
`isWrapped` TypeError.
- `ESC[?1J` over a protected row keeps the next row wrapped (failed on
this PR's first head; found by the Codex review).
- `ESC[?1J` over a row with nothing protected unwraps the next row
(failed on the second head; found by CodeRabbit).
- A throwaway grid (every pair of 14 resizes and scrollback changes
around 19 control sequences, starting from the broken state) threw 7
distinct `undefined` errors on main and none with this patch.
- The notification-view step looped 30 times on the host passed every
time, so the browser loop does not reproduce the flake reliably. The
unit tests above are the deterministic reproduction.

## Validation

- `bun run check fast` at this head (run on old-desktop through the
heavy runner): ok, 12643 unit tests passing.
- `bun test src/lib/terminalReflow.test.ts
src/lib/terminalWidths.test.ts src/lib/ghostty/
scripts/xterm-composition.test.ts src/lib/terminalFileLinks.test.ts
src/lib/inputRow.test.ts`: 155 pass at this head.
- `scripts/ui-contexts-regression.ts` in the CI runner image
(`herdr-ci-runner:local`, on old-desktop): exit 0, 121 PASS lines,
notification-view included (first head; the later commits change only
`ESC[?1J`, which these scripts do not send).
- Not run: the full integration and browser suites (CI runs them).

## Reviews

- omo (`dori review`) on the first head `95a7edd0`: CLEAR. On the final
head `a305d475`: CLEAR.
- Codex (Terra, xhigh): no regression from the reflow bound. It compared
20,000 generated resize cases against the pre-PR code, scrollback > 0
included; contents, cursor, markers and saved positions matched, and the
only difference was the intended viewport correction. One MEDIUM was
reproduced and fixed in the second commit: a selective erase above
(DECSED) unwrapped the next row although protected cells survived.
- Left as is, not changed by this PR: a marker can point to a stale row
after a narrower reflow with no scrollback (Codex reproduced the same
result before this PR). On a random resize fuzz, the unpatched xterm
leaves `baseY + rows > length` 48 times and this patch leaves it 0
times. Cursor, marker and savedY counts stay at the same level as
upstream.
- CodeRabbit on the second head: one Minor (a selective erase that
leaves the cursor's row empty must still unwrap the next row), fixed in
the third commit.
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.

1 participant