Skip to content

Import selected dpcode stability fixes#2

Merged
Jay1 merged 6 commits into
mainfrom
feature/import-dpcode-fixes
May 23, 2026
Merged

Import selected dpcode stability fixes#2
Jay1 merged 6 commits into
mainfrom
feature/import-dpcode-fixes

Conversation

@Jay1

@Jay1 Jay1 commented May 23, 2026

Copy link
Copy Markdown
Owner

Summary

  • Stabilize provider model discovery loading state during initial placeholder fetches.
  • Reset terminal mouse-reporting modes during snapshot replay and reattach.
  • Serialize full parsed diffs for copy/select-all behavior.
  • Optimize streamed text collection to avoid repeated chunk array copies and decoder passes.

Verification

  • bun run --cwd apps/web test src/lib/providerDiscoveryReactQuery.test.ts src/components/DiffPanel.logic.test.ts src/lib/diffRendering.test.ts
  • bun run --cwd apps/server test src/stream/collectUint8StreamText.test.ts src/terminal/Layers/Manager.test.ts
  • LSP diagnostics: no errors on workspace scan
  • Aikido scan on changed helper code returned no issues

Summary by CodeRabbit

  • New Features

    • Improved diff copy/export so copied diffs include full serialized unified text and respect an “armed” select-all state.
  • Bug Fixes

    • Terminal snapshot/history now preserves mouse-reporting reset state so replays show correct terminal behavior.
    • More accurate model discovery pending detection for clearer UI/skeleton states.
  • Tests

    • Added tests for diff selection/serialization, stream text collection, provider discovery, and terminal snapshot behavior.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 23, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Appends a mouse-reporting reset sequence to terminal snapshots and replay resets; adds diff serialization and armed select-all/copy behavior with clipboard override; refactors Uint8 stream collection to accumulate binary chunks and enforce maxBytes; centralizes provider discovery pending logic in a new helper.

Changes

Terminal Mouse Reporting Reset

Layer / File(s) Summary
Mouse reset constant and server snapshot augmentation
packages/shared/src/terminalThreads.ts, apps/server/src/terminal/Layers/Manager.ts, apps/server/src/terminal/Layers/Manager.test.ts
MOUSE_REPORTING_RESET_SEQUENCE constant is exported, imported into server Manager, and appended to session history via snapshotHistory(). Tests are updated to expect the reset suffix in persisted/reopened histories.
Web client snapshot replay reset augmentation
apps/web/src/components/terminal/terminalRuntime.ts
Snapshot replay reset now writes \u001bc followed by MOUSE_REPORTING_RESET_SEQUENCE to align client replay with server snapshots.

Diff Panel Armed Select-All/Copy Behavior

Layer / File(s) Summary
Diff rendering serialization infrastructure
apps/web/src/lib/diffRendering.ts, apps/web/src/lib/diffRendering.test.ts
Adds serialization helpers (stripLineBreak, serializeHunkHeader, serializeFileDiffMetadata, serializeRenderablePatchText) to render parsed RenderablePatch data back to git-diff text; tests verify headers and added/deleted lines are present.
Diff panel armed selection logic
apps/web/src/components/DiffPanel.logic.ts, apps/web/src/components/DiffPanel.logic.test.ts
Adds resolveDiffSelectAllArmed to arm selection when Meta/Ctrl+A occurs inside the diff viewport, preserve armed state for Meta/Ctrl+C and modifier-only keys, and disarm for other keys; tests cover viewport-scoped arming and state persistence.
DiffPanel component armed copy integration
apps/web/src/components/DiffPanel.tsx
Adds diffSelectAllArmedRef, memoizes renderablePatch, derives diffCopyText from serializeRenderablePatchText(renderablePatch) with a fallback, and installs capture-phase document listeners (keydown, pointerdown, copy) to track armed state and override browser copy with serialized diff text when armed.

Uint8 Stream Text Collection Refactor

Layer / File(s) Summary
Stream text collection with maxBytes enforcement
apps/server/src/stream/collectUint8StreamText.ts, apps/server/src/stream/collectUint8StreamText.test.ts
Introduces CollectState (chunks, byteLength, truncated); fold logic uses early exit on truncation, computes remaining bytes and slices the current chunk to enforce maxBytes, accumulates chunks in-place, and decodes final UTF-8 text via Buffer.concat. Tests verify full collection and truncation behavior.

Provider Discovery Pending State Centralization

Layer / File(s) Summary
isInitialModelDiscoveryPending helper
apps/web/src/lib/providerDiscoveryReactQuery.ts, apps/web/src/lib/providerDiscoveryReactQuery.test.ts
Adds exported isInitialModelDiscoveryPending that returns true when isLoading or when isFetching while isPlaceholderData is true; tests validate initial load vs. background refetch scenarios.
ChatView discovery pending state integration
apps/web/src/components/ChatView.tsx
ChatView now uses isInitialModelDiscoveryPending for cursorModelDiscoveryPending and kiloModelDiscoveryPending instead of inline conditions.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 I nibble bytes and stitch the stream,
I tuck a reset where mice might teem,
Diffs copy clean when keys align,
Discovery waits then shows its sign,
A hop of changes, neat and keen!

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 13.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Import selected dpcode stability fixes' is partially related to the changeset but vague and overly broad. It doesn't specify what stability issues are being addressed. Use a more specific title that highlights the main technical improvement, such as 'Stabilize model discovery and improve diff serialization and stream collection.'
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The PR description provides a clear summary of four functional areas with verification steps, meeting the template requirements despite not following all optional template sections.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/import-dpcode-fixes

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


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

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added size:L vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. labels May 23, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
apps/web/src/lib/providerDiscoveryReactQuery.test.ts (1)

5-25: ⚡ Quick win

Add a direct test for the isLoading branch.

Current tests cover both isFetching paths, but not the explicit isLoading path.

✅ Suggested test addition
 describe("isInitialModelDiscoveryPending", () => {
+  it("treats loading state as initial discovery", () => {
+    expect(
+      isInitialModelDiscoveryPending({
+        isLoading: true,
+        isFetching: false,
+        isPlaceholderData: false,
+      }),
+    ).toBe(true);
+  });
+
   it("treats placeholder refetches as initial discovery", () => {
     expect(
       isInitialModelDiscoveryPending({
         isLoading: false,
         isFetching: true,
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/web/src/lib/providerDiscoveryReactQuery.test.ts` around lines 5 - 25,
Add a test that directly asserts the isLoading branch of
isInitialModelDiscoveryPending: create a new it block in
providerDiscoveryReactQuery.test that calls isInitialModelDiscoveryPending with
isLoading: true (and isFetching/isPlaceholderData set to values that won't
interfere, e.g., false) and expect the result toBe(true); reference the
isInitialModelDiscoveryPending function name so the test specifically verifies
the explicit isLoading path rather than relying on isFetching placeholder
behavior.
apps/web/src/lib/diffRendering.test.ts (1)

57-80: ⚡ Quick win

Strengthen serialization test with a round-trip parse assertion.

Current toContain checks can pass even if diff structure is malformed. Add an assertion that reparsing the serialized output yields expected file/hunk stats.

Proposed test hardening
 describe("serializeRenderablePatchText", () => {
   it("serializes parsed file diffs back into complete unified patch text", () => {
@@
     expect(serialized).toContain("-const oldValue = 1;");
     expect(serialized).toContain("+const newValue = 1;");
+    expect(summarizePatchStats(serialized ?? "")).toEqual({ additions: 2, deletions: 1 });
   });
 });
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/web/src/lib/diffRendering.test.ts` around lines 57 - 80, Add a
round-trip assertion: after serializing with
serializeRenderablePatchText(getRenderablePatch(patch)), call
getRenderablePatch(serialized) and assert the reparsed result's file and hunk
metadata match expected values (e.g., number of files, hunks per file, and hunk
header ranges) to ensure the serialized patch is a well-formed unified diff; use
the existing helpers serializeRenderablePatchText and getRenderablePatch to
perform the reparse and compare file/hunk stats rather than only string
contains.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/web/src/components/DiffPanel.tsx`:
- Around line 580-586: The handleCopy handler currently returns early when
event.clipboardData is missing causing armed full-diff copies to fail; update
handleCopy to fall back to a reliable clipboard write by using
navigator.clipboard.writeText(diffCopyText) if available, and if not, create a
temporary textarea, set its value to diffCopyText, programmatically select it
and call document.execCommand('copy'), then clean up; keep the existing checks
for diffSelectAllArmedRef.current and diffCopyText, ensure
diffSelectAllArmedRef.current is set to false before attempting the async
navigator.clipboard.writeText to avoid races, and preserve
event.preventDefault() when using the in-event clipboardData branch.

---

Nitpick comments:
In `@apps/web/src/lib/diffRendering.test.ts`:
- Around line 57-80: Add a round-trip assertion: after serializing with
serializeRenderablePatchText(getRenderablePatch(patch)), call
getRenderablePatch(serialized) and assert the reparsed result's file and hunk
metadata match expected values (e.g., number of files, hunks per file, and hunk
header ranges) to ensure the serialized patch is a well-formed unified diff; use
the existing helpers serializeRenderablePatchText and getRenderablePatch to
perform the reparse and compare file/hunk stats rather than only string
contains.

In `@apps/web/src/lib/providerDiscoveryReactQuery.test.ts`:
- Around line 5-25: Add a test that directly asserts the isLoading branch of
isInitialModelDiscoveryPending: create a new it block in
providerDiscoveryReactQuery.test that calls isInitialModelDiscoveryPending with
isLoading: true (and isFetching/isPlaceholderData set to values that won't
interfere, e.g., false) and expect the result toBe(true); reference the
isInitialModelDiscoveryPending function name so the test specifically verifies
the explicit isLoading path rather than relying on isFetching placeholder
behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9a3d43d6-e7e1-450a-9d84-d359dd33853d

📥 Commits

Reviewing files that changed from the base of the PR and between 2f0c0c5 and 1026e3f.

📒 Files selected for processing (14)
  • apps/server/src/stream/collectUint8StreamText.test.ts
  • apps/server/src/stream/collectUint8StreamText.ts
  • apps/server/src/terminal/Layers/Manager.test.ts
  • apps/server/src/terminal/Layers/Manager.ts
  • apps/web/src/components/ChatView.tsx
  • apps/web/src/components/DiffPanel.logic.test.ts
  • apps/web/src/components/DiffPanel.logic.ts
  • apps/web/src/components/DiffPanel.tsx
  • apps/web/src/components/terminal/terminalRuntime.ts
  • apps/web/src/lib/diffRendering.test.ts
  • apps/web/src/lib/diffRendering.ts
  • apps/web/src/lib/providerDiscoveryReactQuery.test.ts
  • apps/web/src/lib/providerDiscoveryReactQuery.ts
  • packages/shared/src/terminalThreads.ts

Comment on lines +580 to +586
const handleCopy = (event: ClipboardEvent) => {
if (!diffSelectAllArmedRef.current) return;
diffSelectAllArmedRef.current = false;
if (!diffCopyText || !event.clipboardData) return;
event.preventDefault();
event.clipboardData.setData("text/plain", diffCopyText);
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Add a clipboard fallback when event.clipboardData is unavailable.

In the armed path, copy override currently no-ops if clipboardData is missing, which can drop the intended full-diff copy behavior in some environments.

Proposed fallback for reliability
     const handleCopy = (event: ClipboardEvent) => {
       if (!diffSelectAllArmedRef.current) return;
       diffSelectAllArmedRef.current = false;
-      if (!diffCopyText || !event.clipboardData) return;
-      event.preventDefault();
-      event.clipboardData.setData("text/plain", diffCopyText);
+      if (!diffCopyText) return;
+      if (event.clipboardData) {
+        event.preventDefault();
+        event.clipboardData.setData("text/plain", diffCopyText);
+        return;
+      }
+      void navigator.clipboard?.writeText(diffCopyText).catch(() => undefined);
     };
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/web/src/components/DiffPanel.tsx` around lines 580 - 586, The handleCopy
handler currently returns early when event.clipboardData is missing causing
armed full-diff copies to fail; update handleCopy to fall back to a reliable
clipboard write by using navigator.clipboard.writeText(diffCopyText) if
available, and if not, create a temporary textarea, set its value to
diffCopyText, programmatically select it and call document.execCommand('copy'),
then clean up; keep the existing checks for diffSelectAllArmedRef.current and
diffCopyText, ensure diffSelectAllArmedRef.current is set to false before
attempting the async navigator.clipboard.writeText to avoid races, and preserve
event.preventDefault() when using the in-event clipboardData branch.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/web/src/components/DiffPanel.tsx (1)

1080-1114: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Use one effective collapsed state for oversized files.

Line 1113 forces collapse when !canRender, but Lines 1137 and 1101 still use/toggle isCollapsed alone, so the chevron can imply expandability even when expansion is impossible.

Suggested fix
-                    const isCollapsed = collapsedFiles.has(fileKey);
+                    const isUserCollapsed = collapsedFiles.has(fileKey);
+                    const isEffectivelyCollapsed = isUserCollapsed || !canRender;
                     return (
                       <div
@@
-                          if (!clickedHeader) return;
+                          if (!clickedHeader || !canRender) return;
                           event.stopPropagation();
                           toggleFileCollapsed(fileKey);
                         }}
                       >
@@
-                            collapsed: isCollapsed || !canRender,
+                            collapsed: isEffectivelyCollapsed,
@@
-                                  transform: isCollapsed ? "rotate(-90deg)" : "rotate(0deg)",
+                                  transform: isEffectivelyCollapsed
+                                    ? "rotate(-90deg)"
+                                    : "rotate(0deg)",

Also applies to: 1133-1138, 1144-1148

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/web/src/components/DiffPanel.tsx` around lines 1080 - 1114, The collapse
UI uses isCollapsed but ignores the canRender flag in some places, so calculate
a single effectiveCollapsed value (e.g., const effectiveCollapsed = isCollapsed
|| !canRender) inside the renderableFiles map and use that everywhere: pass
effectiveCollapsed to the FileDiff collapsed prop, use effectiveCollapsed when
rendering the chevron/expand indicator, and guard toggleFileCollapsed so it only
runs when canRender is true (do not toggle when !canRender). Update references
to isCollapsed in the click handler, chevron rendering, and any other places
(e.g., where you check or display expandability) to use effectiveCollapsed to
keep behavior consistent.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@apps/web/src/components/DiffPanel.tsx`:
- Around line 1080-1114: The collapse UI uses isCollapsed but ignores the
canRender flag in some places, so calculate a single effectiveCollapsed value
(e.g., const effectiveCollapsed = isCollapsed || !canRender) inside the
renderableFiles map and use that everywhere: pass effectiveCollapsed to the
FileDiff collapsed prop, use effectiveCollapsed when rendering the
chevron/expand indicator, and guard toggleFileCollapsed so it only runs when
canRender is true (do not toggle when !canRender). Update references to
isCollapsed in the click handler, chevron rendering, and any other places (e.g.,
where you check or display expandability) to use effectiveCollapsed to keep
behavior consistent.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d7131f3b-587c-403c-9b83-8b7636c372f3

📥 Commits

Reviewing files that changed from the base of the PR and between 1026e3f and 320f748.

📒 Files selected for processing (3)
  • apps/web/src/components/DiffPanel.tsx
  • apps/web/src/lib/diffRendering.test.ts
  • apps/web/src/lib/diffRendering.ts

@Jay1 Jay1 merged commit 34e3eef into main May 23, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant