Skip to content

test(tui): bound diff viewer mount readiness before selected-request polling - #840

Merged
agenteinstinct1-max merged 3 commits into
dev-vibecodedfrom
fix/diff-viewer-kv-mount-readiness
Nov 11, 2026
Merged

agenteinstinct1-max merged 3 commits into
dev-vibecodedfrom
fix/diff-viewer-kv-mount-readiness

Conversation

@agenteinstinct1-max

@agenteinstinct1-max agenteinstinct1-max commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Issue for this PR

Closes #839

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Test harness only: observe the viewer mount below KVProvider before starting the existing selected-request readiness loop. A 2000 ms monotonic mount deadline bounds asynchronous render waits, clears its timer, and observes late render rejection. Keep the post-mount 10 attempts with 25 ms waits and all host/CI limits unchanged.

The real 400 ms KV lock test waits for acquisition before rendering and propagates acquisition failure. Added deadline tests cover instant renders and a pending render that rejects after expiry, including one destroy and no further polling.

How did you verify your code works?

Ran the affected Linux tests: 12 pass, 0 fail, 41 expectations. Also ran the existing repository 30000 ms invocation, two failing controls, and the real KV-lock diagnostic described below.

Exact qualification

  • Final CI: https://github.com/mdev34-lab/silvercode/actions/runs/42965958786

  • The same Arena reviewer explicitly adjudicated all four later Kilo findings against the public PR head and kept CLEAN: Promise.race installs rejection handlers on all inputs; awaiting the losing render in finally would reintroduce an unbounded wait. The late-rejection test is adequate with source semantics, and the quoted 5000 ms comment is absent from V4. Kilo itself reported four findings, not a clean review.

  • Head: 8b73484

  • Tree: aee73451214300397147cb02b2bc93d39917f0b6

  • Base: ef8e500

  • Full one-file patch independently reviewed by the same Arena reviewer after the earlier must-fix findings. Final result: CLEAN, no remaining must-fix.

  • Review: https://arena.ai/agent/01a1c89d-fb30-7ae6-8f25-2dc4247e3a11

  • Local Linux: 12 pass, 0 fail, 41 expectations, including the existing repository 30000 ms invocation.

  • Controls: removing the mount wait fails the acquired-KV-lock regression; removing the render deadline race fails the pending-render regression.

  • Diagnostic using the real renderDiffViewer path and a 3500 ms acquired KV lock: mount rejection at 2034 ms; 3 pass, 0 fail, no extra Bun unhandled error. This diagnostic did not directly instrument real renderer destruction. The cleanup wrapper source and fake-app regression tests cover the one-destroy/no-further-polling contract.

Limits and merge gate

The deadline is cooperative, not a hard real-time guarantee or synchronous event-loop preemption. The 25 ms polling sleep can add a small overshoot. No render-duration cap is claimed.

The controlled KV-lock failure establishes a pre-mount mechanism on the base and #836, not the actual cause of the two Windows CI failures. Exact-head CI is now green: Linux units (22 minutes), Windows units, typecheck and all policy checks passed on 8b73484. This PR does not waive #835 or #836 gates. The independent review remains applicable to this unchanged head.

Screenshots / recordings

Not a production UI change. Test-harness-only readiness and cleanup correction.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions

Copy link
Copy Markdown

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

async function renderWithin(app: Awaited<ReturnType<typeof testRender>>, deadline: number) {
const remaining = deadline - performance.now()
if (remaining <= 0) throw new Error("Timed out waiting for the diff viewer to mount")
// Promise.race below subscribes to render, so a late rejection after expiry is observed.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

SUGGESTION: Incorrect comment about Promise.race behavior

Promise.race settles on the first promise to settle; it does not "subscribe" to observe late rejections of the losing promise. The losing promise's rejection becomes unhandled unless separately awaited.

timer = setTimeout(() => reject(new Error("Timed out waiting for the diff viewer to mount")), remaining)
})
try {
await Promise.race([render, expiry])

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

WARNING: Potential unhandled promise rejection when deadline expires

When expiry wins the race, the render promise is left pending. If it later rejects (as simulated in the test at line 382), the rejection is unhandled. Consider attaching a .catch() to render or awaiting it in the finally block to prevent unhandled rejections.

expect(destroyCount).toBe(1)
})

test("diff viewer mount deadline bounds a pending render and observes its late rejection", async () => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

SUGGESTION: Test name claims to "observe late rejection" but doesn't assert on it

The test triggers a late rejection at line 382 but only verifies that renderCount and destroyCount don't change. It doesn't assert that the late rejection is observed or handled. Consider renaming to "diff viewer mount deadline bounds a pending render and cleans up once" or adding an assertion for the late rejection.

}
})

const MOUNT_DEADLINE_MS = 2000 // Deadline for the KV provider to mount children (real lock + read settle); a 400ms held lock mounts in about 0.55s. Leaves most of Bun's test host budget for the unchanged post-mount loop and cleanup.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

SUGGESTION: Comment references Bun's default test timeout

The comment states "well before Bun's default 5000ms test timeout". Bun's default test timeout is indeed 5000ms, but this is an implementation detail that could change. Consider referencing the actual timeout configuration or removing the specific version-dependent number.

@kilo-code-bot

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

Copy link
Copy Markdown

Code Review Summary

Status: 4 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 3
Issue Details (click to expand)

WARNING

File Line Issue
packages/tui/test/cli/tui/diff-viewer.test.tsx 436 Potential unhandled promise rejection when deadline expires

SUGGESTION

File Line Issue
packages/tui/test/cli/tui/diff-viewer.test.tsx 429 Incorrect comment about Promise.race behavior
packages/tui/test/cli/tui/diff-viewer.test.tsx 355 Test name claims to "observe late rejection" but doesn't assert on it
packages/tui/test/cli/tui/diff-viewer.test.tsx 411 Comment references Bun's default test timeout
Files Reviewed (1 file)
  • packages/tui/test/cli/tui/diff-viewer.test.tsx - 4 issues

Fix these issues in Kilo Cloud


Reviewed by free · Input: 45.8K · Output: 12.3K · Cached: 162.2K

@github-actions

Copy link
Copy Markdown

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@agenteinstinct1-max
agenteinstinct1-max merged commit 32c33f4 into dev-vibecoded Nov 11, 2026
17 checks passed
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.

TUI tests: wait for KV-dependent diff viewer mount with bounded cleanup

1 participant