Skip to content

fix(chat): find Command Code's session in its own project when the shell is elsewhere - #1745

Merged
devswha merged 3 commits into
mainfrom
fix/cmd-transcript-cwd
Oct 23, 2026
Merged

devswha merged 3 commits into
mainfrom
fix/cmd-transcript-cwd

Conversation

@devswha

@devswha devswha commented Oct 23, 2026

Copy link
Copy Markdown
Owner

Change

cmdTranscriptPath (server/cmd.ts) checked the herdr-reported session only against the project store of herdr's agent.cwd. With the shell in project A and Command Code running in project B, B's reported transcript was checked against A's store and rejected, so Chat showed "Conversation unavailable".

The reported session is now checked against the project store of foreground_cwd first, then of agent.cwd. Each candidate goes through the existing session and filesystem validation, and if none validates the result is still null. Trying more than one matters because herdr's foreground_cwd falls back to another process-group member's cwd when the leader's is unreadable, so it alone does not prove the agent's project.

Item 3 of #1445, plus session-resolution tests (part of item 6). Items 1 and 2 need a real capture, and items 4 and 5 touch files other open PRs hold.

Refs #1445

Validation

  • server/cmd.test.ts: 31 pass, including shell in A with Command Code in B, an unrelated foreground_cwd in C with the session in B, and no candidate validating (null).
  • bun run check fast: pass.

Prefer a nonempty foreground cwd over the shell cwd while preserving session report and store validation. Cover written and unwritten sessions, cwd fallback, and invalid reports in an isolated home.

Refs #1445
Try argv-identified Command Code process stores before foreground and pane cwd stores. Preserve session and filesystem checks for every candidate, including helper cwd and neither-store regressions.

Refs #1445
Remove process argv matching and the extra process-info RPC. Validate the herdr-reported session against foreground cwd first, then pane cwd, returning null when neither store validates.

Refs #1445
@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
📥 Commits

Reviewing files that changed from the base of the PR and between 1356210 and 764a563.

📒 Files selected for processing: 3
  • changelog.d/cmd-transcript-cwd.md
  • server/cmd.test.ts
  • server/cmd.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 0 remain after this review.

📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • Fixed Command Code session reporting when the shell is in a different directory from the session’s project. Session lookup now checks both the foreground and process working directories.

cmdTranscriptPath now checks the reported session in the foreground cwd project store, then the process cwd project store. Tests cover valid sessions, unwritten sessions, and invalid or missing report data.

Changes: Transcript resolution

Layer / File(s) Summary
Cwd-based session lookup
server/cmd.ts, server/cmd.test.ts, changelog.d/cmd-transcript-cwd.md
The resolver checks the foreground and process cwd project stores in order and returns the first valid session. Tests cover both stores and invalid inputs. The changelog describes the updated resolution behavior.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: diegolhambi

Merge Risk: ⚪ Minimal · up to 764a5

The transcript lookup change is ready to merge after normal checks; no actionable risk remains.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main fix: resolving Command Code sessions in the correct project when the shell is elsewhere.
Description check Passed The description includes the required Change and Validation sections. It explains the problem, resulting behavior, test coverage, and check results.
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.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • 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

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

@devswha

devswha commented Oct 23, 2026

Copy link
Copy Markdown
Owner Author

Merge pass: reviewed in place of a CodeRabbit review (rate-limited). A gate reviewer on a different model than the author's confirmed:

  • the reported transcript is looked up in foreground_cwd's project store, then agent.cwd's;
  • validation uses the reported full path, so a session id shared by two projects can't pick the wrong file, and no validated candidate gives null.
    31 cmd tests pass. All required checks are green and no review thread is open.

@devswha
devswha merged commit 9f65cff into main Oct 23, 2026
17 checks passed
@devswha
devswha deleted the fix/cmd-transcript-cwd branch October 23, 2026 09:52
@coderabbitai coderabbitai Bot mentioned this pull request Oct 24, 2026
devswha added a commit that referenced this pull request Oct 25, 2026
## Change

Follow-ups from #1399's review (#1445), for Command Code (`cmd`) panes.
Per item:

- **2, the footer check was strict** (`server/dialogs/cmd.ts`,
`server/dialogs/live.ts`): a permission prompt now gets its card when
its footer wraps (split hint, word or character wrap) or uses the ctrl+e
/ ctrl+y variants. These are the shapes the published `command-code`
1.88.0 renderer draws (read statically from the npm package; the CLI was
never run or logged into). A stale or incomplete footer, or anything
drawn below it, still gives no card. Normal status chrome is hidden
while a permission dialog is open, so it cannot sit under the footer.
- **LOW, an ordinary numbered menu was labelled an approval card**: a
menu is an approval card only when its rows are Command Code's own Yes …
No choices, so a theme picker with the same footer is not one.
- **4, herdr's model stuck in the transcript cache**
(`server/conversation.ts`, cmd metadata branch only): the served model
follows the pane's current model, and the ETag changes with it. The
response is a new object, so the cached page is never mutated. herdr's
live model now also replaces a model recorded in the transcript, which
is what the item asks for. This branch is only reached where herdr
reports the pane's Command Code session, which no released herdr does
yet (#1647), so the changelog entry says so.
- **5, store validation copied from `server/pi.ts`**: both now use
`server/transcript-store.ts`. Behaviour is identical, and the old names
are re-exported.
- **6, test gaps**: tests for the cmd metadata branch, for the keys each
answer sends from every cursor position, and for refusing a stale card
over HTTP (409 `prompt_changed`, no keys sent). Session resolution and
the skills source were already covered.
- **LOW**: the unused `CmdTranscriptOptions.home` is removed.

**Not fixed**
- **1, the card id covers everything above the rows**, so a card goes
stale when output above an open dialog redraws, as before. Narrowing the
id to the dialog was tried and reverted: two review rounds showed that
command text (a heredoc) can imitate the dialog's frame, including its
real layout (rule, blank line, heading, subtitle). Then two different
commands got the same id, and a stale card could be answered. Doing this
safely needs Command Code to expose the dialog, or a capture proving a
boundary that command text cannot imitate. A test pins the safe
behaviour.
- **LOW, a multi-line command's title**: left as main draws it, for the
same reason (it would need the same boundary guess).
- **3, the shell's cwd won over the agent's**: already fixed on main by
#1745.
- **LOW, the comment saying the body is part of the id**: it is accurate
with main's id, which covers everything above the rows, the body
included.

Fixes #1445

## Verification

- New tests fail on origin/main and pass here: footer shapes, the Yes/No
menu check, the model and ETag refresh without a transcript append, and
the answer keys. Tests from the reviews are kept as regressions. Heredoc
and indentation changes give different ids, a quoted dialog frame in the
real layout gives different ids, and file-permission card bodies equal
main's. The stale-card route test gets 409 with no keys sent.
- Single-file runs after the rebase onto main: `server/cmd.test.ts` 56
pass, `server/prompt.test.ts` 357 pass,
`server/cmd-conversation.test.ts` 2 pass, `server/pi.test.ts` 31 pass,
`server/dialogs/registry.test.ts` 55 pass,
`server/dialogs/interaction-plan.test.ts` 23 pass,
`server/dialogs/claude.test.ts` 13 pass.
- Live check over HTTP, against a real headless herdr session of its own
(not a fake socket) and the server's `/api/pane/prompt` routes. A pane
reported as `cmd` drew Command Code's shell permission dialog at 80
columns, where the terminal wraps the footer mid-word (`… bypass all
perm` / `issions (Docs ↗)`):
- this branch: an approval card with Yes / Yes, don't ask again / No.
origin/main: only the generic fallback card (↑ ↓ Enter Esc).
- a theme picker with the same footer: this branch gives the generic
menu card; origin/main labels it an approval card titled "Theme".
- a line redrawn above the open dialog gives a new id; answering the old
id gets 409 `prompt_changed` and no byte reaches the pane; answering the
new id sends only Enter.
- Reviews:
- Round 1: omo-native-code-reviewer and Codex (gpt-6.1-sol, xhigh) each
found a HIGH in the narrowed card id (a heredoc hiding the command
prefix).
- Round 2: both found more ways around the narrowing, and file cards
showing the whole screen. That led to restoring main's id.
  - Round 3: both APPROVE with no HIGH or MEDIUM.
- After the rebase (one import conflict in `server/pi.ts`, where main's
#1899 added `fileURLToPath`): Codex (gpt-6.1-sol, xhigh) reviewed the
rebase against the new main (#1899's store and agent directory code,
#1893's cache ordering, #1890's dialog reader order) and APPROVED with
no findings.
- `bun run check fast` on this head: workflow syntax, generated types
and themes, typecheck, build and unit tests ok (6800 pass, 0 fail, 13
skip).

---------

Co-authored-by: mp <mp@local>
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