Skip to content

fix(tui): make the clipboard fail-fast window explicit so the test pins the contract - #228

Closed
KooshaPari wants to merge 1 commit into
masterfrom
fix/clipboard-helper-fail-fast-window
Closed

KooshaPari wants to merge 1 commit into
masterfrom
fix/clipboard-helper-fail-fast-window

Conversation

@KooshaPari

@KooshaPari KooshaPari commented Nov 3, 2026 •

Copy link
Copy Markdown
Owner

User description

Why

Build & Test (desk-linux) in run 41547128038 failed on master (dabaab5b8):

---- tui::app::helpers::clipboard_helper::tests::helper_that_exits_nonzero_falls_through stdout ----
panicked at crates/jcode-tui/src/tui/app/helpers/clipboard_helper.rs:79:9:
assertion failed: !copy_via_clipboard_helper("false", &[], "hello")

2516 passed, 1 failed.

Root cause (observed, not assumed)

The failing test's timestamp is ~154 ms after the previous test finished, which matches the fixed 150 ms poll budget in copy_via_clipboard_helper. That function's contract is:

  • helper exits 0 inside the window -> copy
  • helper exits nonzero inside the window -> fall through
  • helper still running when the window closes -> copy (it owns the selection)

The last branch is a heuristic, and it is the only thing separating "failed" from "owns the selection". On a loaded shared runner false was not reaped inside 150 ms, so the owner branch won and the assertion failed. This is not just a flaky test: a real xclip failing slowly would also be reported as a successful copy, which is the exact class of false "Copied" that 1jehuang#684 fixed.

Reproduced deterministically on the extracted function:

window sh -c 'sleep 1; exit 7' expected
150 ms (production) true (misclassified as owner) false
30 s false false

Change

  • Extract copy_via_clipboard_helper_within(program, args, text, window); keep the public signature and the production window unchanged (HELPER_FAIL_FAST_WINDOW = 150 ms).
  • Tests supply their own window so they assert the contract instead of racing the scheduler:
    • TEST_SETTLE_WINDOW (30 s) for every "exits nonzero" / "exits 0" case;
    • a 10 ms live-owner window so sleep 30 is deterministically still running.
  • New regression test helper_that_exits_nonzero_late_still_falls_through fails against the old fixed-window code.
  • ordering_tests::first_helper_that_wins uses the same settle window (it had the same race).
  • Documented the window contract and its known limitation in the doc comment.

Runtime behaviour is unchanged: no change to fallback order, no change to the production budget.

Validation

  • rustfmt --edition 2024 --check clean.
  • Extracted-function harness, 6/6 pass, including the two rows in the table above.
  • Full crate validation on Linux is delegated to the self-hosted desk-linux runner in this PR's CI (the module is cfg'd out on macOS, where this was authored.
    BODY
    )

CodeAnt-AI Description

Make clipboard-helper failure tests deterministic

What Changed

  • Tests can set the polling window so helper exit results do not depend on scheduler timing; production keeps its existing 150 ms window.
  • Added coverage for delayed failures and long-running helpers, and made fallback-order tests use a stable polling window.

Impact

✅ Fewer timing-dependent clipboard test failures
✅ Delayed helper failures covered in regression tests

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.


Closes #234

Refs #231. This PR does not fix the production false-success defect described in #231: runtime behaviour is unchanged, including the 150 ms HELPER_FAIL_FAST_WINDOW heuristic. #231 remains open and must not be closed by this change.

…ns the contract

`copy_via_clipboard_helper` polls a freshly spawned helper for 150ms and treats a
still-running child as the selection owner. That heuristic is the only thing that
separates "exited nonzero" from "owns the selection", so a helper that exits
nonzero *after* the window closes is reported as a copy.

`Build & Test (desk-linux)` in run 41547128038 failed
`helper_that_exits_nonzero_falls_through` with
`!copy_via_clipboard_helper("false", &[], "hello")` after ~154ms, i.e. the child
was not observed exiting inside the 150ms budget and the owner branch won.

The window is now a parameter (`copy_via_clipboard_helper_within`) with the
production value kept at 150ms via `HELPER_FAIL_FAST_WINDOW`. Tests pass their
own window so they assert the contract instead of racing the scheduler:

- settle window (30s) for every "exits nonzero" / "exits zero" case, so the exit
  is always observed;
- 10ms live-owner window, so `sleep 30` is deterministically still running.

Adds `helper_that_exits_nonzero_late_still_falls_through`, which fails against
the old fixed-window code and passes now. Ordering tests use the same settle
window for the same reason.

tx-agent: jcode
tx-validated: manual
tx-scope: crates/jcode-tui/src/tui/app/helpers/clipboard_helper.rs
tx-intent: remove the scheduler race in the clipboard helper tests and document the window contract
Copilot AI balanced review requested due to automatic review settings November 3, 2026 04:44
@codeant-ai

codeant-ai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

CodeAnt  CodeAnt Review Status

✅  Review completed

Status Commit Started (UTC) Finished (UTC)
✅  #5635a Reviewed your PR 63d49fa Nov 03, 2026 · 04:44 04:47

@codeant-ai

codeant-ai Bot commented Nov 3, 2026

Copy link
Copy Markdown

Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@coderabbitai

coderabbitai Bot commented Nov 3, 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 31 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 98d38163-2dae-4ac9-b080-75e00f317694
Commits

Reviewing files that changed from the base of the PR and between ac34906 and 63d49fa.

Files selected for processing: 1
  • crates/jcode-tui/src/tui/app/helpers/clipboard_helper.rs
  • 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

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.

@codeant-ai codeant-ai Bot added the size:M This PR changes 30-99 lines, ignoring generated files label Nov 3, 2026
@kilo-code-bot

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

Copy link
Copy Markdown

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (1 file)
  • crates/jcode-tui/src/tui/app/helpers/clipboard_helper.rs

Reviewed by free · Input: 27.3K · Output: 985 · Cached: 107.7K

@sonarqubecloud

sonarqubecloud Bot commented Nov 3, 2026

Copy link
Copy Markdown

@codeant-ai

codeant-ai Bot commented Nov 3, 2026

Copy link
Copy Markdown

CodeAnt  CodeAnt PR Risk

🟢  Low Risk

  • The PR appears safe to merge; no actionable issues were identified in the review.

Assessed commit: 63d49fae22be

@KooshaPari

Copy link
Copy Markdown
Owner Author

FYI — this and #227 were opened concurrently for the same failure. Yours is the better change to land, so I am closing #227 and keeping your approach as the test-determinism fix.

Context that may be useful:

Your Build & Test passing in 53m58s is the confirmation that matters — it shows parameterising the window is sufficient to make helper_that_exits_nonzero_falls_through deterministic without touching production behaviour.

The production behaviour is unchanged by design in your patch, and that is a legitimate call, but it leaves a real user-facing gap: a helper that is going to fail but has not been scheduled yet is still reported as a successful copy. I filed #231 for that, with a deterministic reproduction (sh -c 'sleep 0.25; exit 1' → old logic reports true). It deliberately includes your _within parameterisation as the tool for the acceptance test, so the two are complementary rather than competing.

Why my PR also touched part_02.rs and yours does not need to: because I changed production behaviour, the two image tests that assert status == "Image size: large" exactly started seeing "Image size: large · Could not copy image". Those assertions were only passing because of the false positive. With your patch leaving production alone, they keep passing — so do not take that file change; it is only required if #231 is resolved by adding a wait.

One note on your current run: Security preflight (Linux) failed with The self-hosted runner lost communication with the server, not a code problem. The desk host's WSL instance restarted (SSH was also down; sshd was stopped and has since been started). That job should be re-run rather than investigated as a regression.

@KooshaPari

Copy link
Copy Markdown
Owner Author

Closing under the host-ops closure audit (2026-11-11): conflicts with master. The branch fix/clipboard-helper-fail-fast-window is preserved on the remote, so the work is recoverable with git fetch origin fix/clipboard-helper-fail-fast-window or by reopening this PR. Nothing was deleted.

@KooshaPari KooshaPari closed this Nov 11, 2026
KooshaPari added a commit that referenced this pull request Nov 27, 2026
…ship (#231) (#386)

Issue #231 is that a helper still running at the 150 ms fail-fast deadline is
reported as a successful copy. The only sound facts a helper provides are
exit 0 (accepted) and nonzero (failed); "still running" is unknown, and the
resident-helper case on a healthy Linux desktop never produces an exit. There is
no honest mapping of that unknown into a `bool`.

Records the verified starting state (HEAD 63d49fa, parent and live
origin/master ac34906, clean tree, PR #228 open), the exact defect site, all
eight call sites that consume the boolean, the existing status-notice and
handle_tick plumbing that a late correction would use, and the three candidate
contracts. Recommends a deferred-notice contract plus optional read-back
verification as the only genuine observation of "what does paste give me".

Does not change production code: every candidate contract needs a product
decision on what the UI shows while a copy is unconfirmed, and the only honest
resolution (read-back) cannot be measured here because the module is
Linux-only while this workstation is macOS and the build host is Windows/MSYS.

Blockers B1 (unconfirmed-copy wording), B2 (read-back in scope?), B3 (no Linux
desktop to validate real helper behaviour), B4 (depends on PR #228's
parameterised window), B5 (image copy paths share the defect).

tx-agent: jcode
tx-validated: none
tx-scope: docs/design/clipboard-helper-ownership.md
tx-intent: give issue #231 a decision-ready, evidence-backed design without shipping a time-based success claim
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ci: clipboard_helper nonzero-exit test depends on scheduler timing (fixed by #228)

2 participants