Skip to content

fix(session): reject ambiguous navigate targets - #900

Open
rascal-sl wants to merge 1 commit into
modem-dev:mainfrom
rascal-sl:fix-reject-ambiguous-navigation
Open

fix(session): reject ambiguous navigate targets#900
rascal-sl wants to merge 1 commit into
modem-dev:mainfrom
rascal-sl:fix-reject-ambiguous-navigation

Conversation

@rascal-sl

Copy link
Copy Markdown

Problem

hunk session navigate accepted two selectors at once and silently picked one.

  • A direction combined with an absolute target, for example --next-comment --file src/app.ts --hunk 2, let the direction win and dropped the file and hunk without a word.
  • The daemon accepted a hunk or line target with no filePath. It dispatched the command, but the live terminal cannot resolve an absolute target without the file that owns it.

Approach

Reject both combinations where each surface already validates, rather than adding a new validation layer.

  • src/app/cli.ts: the existing conflicting-selector guard now also covers a direction combined with --file, --hunk, --old-line, or --new-line, and reuses the existing error text.
  • src/session/broker/brokerServer.ts: the existing navigate guard now rejects a direction combined with an absolute target, and requires filePath for a hunk or line target.

Non-goals. The terminal bridge stays a pass-through adapter and is untouched. I left protocolSchemas.ts alone on purpose: the schema validates wire shape, and the acceptance criteria ask for CLI and broker validation. I did try the cross-field check in the schema first, and moved it out because it duplicated a guard the broker already owned.

Exact-line precedence is preserved. A raw API request carrying filePath, hunkNumber, side and line still prefers the line, and there is now a test pinning that.

Tests

Added regression tests for accepted and rejected combinations:

  • src/app/cli.test.ts: both directions against five absolute-target combinations
  • src/session/broker/brokerServer.helpers.test.ts: direction plus target, hunk and line without filePath, and the exact-line precedence case

Each new rejection test was confirmed to fail without its fix:

# with the CLI guard reverted
(fail) parseCli > rejects session navigate when a comment direction is combined with an absolute target
 133 pass, 1 fail

# with the broker guard reverted
(fail) handleSessionApiRequest > rejects a comment direction combined with another navigation target
(fail) handleSessionApiRequest > rejects a hunk or line target without a file path
 38 pass, 2 fail

Commands run

$ bun run test
 3237 pass
 25 skip
 0 fail
Ran 3262 tests across 298 files. [55.18s]

$ ./node_modules/.bin/tsc --noEmit
(exit 0)

$ ./node_modules/.bin/oxlint <changed files> --deny-warnings
Found 0 warnings and 0 errors.

One note on honesty. An earlier full run showed filesystem watch observer > observes an ordinary file write after readiness failing at about 3s. It passed on the next run with no change in between, so it looks timing dependent on this machine. It touches no navigation code.

Platform: macOS, Node 24, bun 1.3.14. Not tested on Linux or Windows.

bun install needed --ignore-scripts here because the simple-git-hooks postinstall exits 1 on this machine. No lockfile change is included.

Changeset

patch targeting hunkdiff.


Tisankan Jeyakumar
Developed and verified

@greptile-apps

greptile-apps Bot commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

PR author is not in the allowed authors list.

@vercel

vercel Bot commented Aug 29, 2026

Copy link
Copy Markdown

@rascal-sl is attempting to deploy a commit to the Modem Team on Vercel.

A member of the Team first needs to authorize it.

hunk session navigate accepted two selectors at once. A direction such as
--next-comment combined with --file, --hunk, or a line silently won, and the
absolute target was dropped without a word. The daemon also accepted a hunk or
line target with no filePath, which the live terminal cannot resolve.

Reject both combinations in the CLI parser and at the broker boundary. Keep the
documented precedence where exact line coordinates win over a hunk number on a
raw API request, and cover it with a test so the precedence stays explicit.

Closes modem-dev#897
@rascal-sl
rascal-sl force-pushed the fix-reject-ambiguous-navigation branch from 0ebb6fb to c22dd0e Compare August 31, 2026 18:11
@rascal-sl

Copy link
Copy Markdown
Author

Rebased onto main to clear the conflict with #896.

That refactor extracted resolveNavigateCommandInput and, in passing, already implemented two of the checks this PR originally carried: the commentId conflict guard and the missing-comment lookup. Re-applying the original diff would have duplicated them inside the new helper, so I rebuilt the change on top of it rather than forcing my side of the conflict back in.

What remains is only the two gaps issue #897 lists as outstanding:

  • Reject commentDirection combined with a file, hunk or line target, in the CLI and at the broker boundary.
  • Require filePath for a hunk or line target, since the live terminal cannot resolve one without the file that owns it.

The documented exact-line precedence is unchanged and still has a test. The diff is down to 5 files and 119 lines.

Verification on macOS, bun 1.3.14: bun test src/session/ src/app/cli.test.ts gives 471 pass, 0 fail. oxlint and oxfmt --check are both clean.

Two failures elsewhere are not from this branch. test/pty/harness.ts has two tsc errors, and one case in test/cli/install-vm/contract.test.ts fails on a /var versus /private/var symlink resolution. Both reproduce identically on upstream/main with this branch checked out elsewhere, so I have left them alone.


Tisankan Jeyakumar
Developed and verified

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