Skip to content

fix: update grok session after new - #2683

Open
akbash-bot wants to merge 2 commits into
masterfrom
akbash/2681-grok-session-new
Open

fix: update grok session after new#2683
akbash-bot wants to merge 2 commits into
masterfrom
akbash/2681-grok-session-new

Conversation

@akbash-bot

Copy link
Copy Markdown
Collaborator

Summary

  • forward Grok's SessionStart.source through the native session hook on Unix and Windows
  • accept only same-owner Grok new session replacements while preserving different-owner guards
  • bump the managed Grok integration to v2 and update staged docs

Checks

  • cargo test --test cli grok_hook_reports_new_session_source -- --nocapture
  • cargo test grok_new_session -- --nocapture
  • cargo test grok_v1_integration_status_is_outdated -- --nocapture
  • cargo test grok_v2_integration_status_is_current -- --nocapture
  • cargo test bundled_integration_asset_versions_match_expected_versions -- --nocapture
  • cargo test bundled_integration_assets_report_session_refs -- --nocapture
  • cargo clippy --all-targets --locked -- -D warnings
  • full nextest run: 3,416 passed; the unrelated live_server_holds_one_pty_master_fd_per_pane test failed identically on unchanged master because its replacement server did not appear

refs #2681

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Grok integration version 2 reports the session-start source. Terminal state handling updates same-owner Grok sessions after /new while preventing cross-owner replacement. Tests and localized documentation cover the new behavior and version requirement.

Changes

Grok session identity

Layer / File(s) Summary
Grok integration reporting
src/integration/assets/grok/*, src/integration/mod.rs, src/integration/tests.rs
The Grok hooks use integration version 2, read the optional source field, and include it in pane.report_agent_session. Asset and version tests cover the new marker and version status.
Grok session replacement handling
src/terminal/state.rs, tests/cli/hooks.rs
Grok sessions started with "new" can replace an existing Grok session. Cross-owner takeover remains blocked. Tests cover session IDs, sources, replacement, and ownership checks.
Version documentation alignment
docs/next/CHANGELOG.md, docs/next/website/src/content/docs/integrations.mdx, docs/next/website/src/content/docs/ja/integrations.mdx, docs/next/website/src/content/docs/session-state.mdx, docs/next/website/src/content/docs/zh-cn/integrations.mdx
The changelog and localized documentation require Grok integration version 2 for native session restore.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant GrokCLI
  participant GrokHook
  participant Herdr
  participant TerminalState
  GrokCLI->>GrokHook: Emit session payload with source "new"
  GrokHook->>Herdr: Report session ID and session_start_source
  Herdr->>TerminalState: Process session identity
  TerminalState->>TerminalState: Replace same-owner Grok session
Loading

Possibly related PRs

  • herdrdev/herdr#2455: Both changes update terminal session identity handling for CLI conversation changes, but for different integrations.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Title check ✅ Passed The title clearly summarizes the main change: updating Grok session handling after a new session starts.
Description check ✅ Passed The description accurately covers the Grok session hook, replacement logic, integration version update, documentation changes, and test results.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch akbash/2681-grok-session-new

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.

@kangal-bot kangal-bot added the ai-review Trigger automated AI reviews for pull requests admitted by the PR gate label Aug 11, 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.

🧹 Nitpick comments (1)
src/integration/assets/grok/herdr-agent-state.ps1 (1)

44-55: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Rename the argument array variable.

Line 44 overwrites PowerShell's automatic $args variable. Use a dedicated variable such as $herdrArgs. This avoids changing automatic parameter state and removes the PSScriptAnalyzer warnings on Lines 44 and 52.

Proposed fix
-$args = @(
+$herdrArgs = @(
     "pane", "report-agent-session", $env:HERDR_PANE_ID,
     "--source", "herdr:grok",
     "--agent", "grok",
     "--seq", "$seq",
     "--agent-session-id", "$sessionId"
 )
 if (-not [string]::IsNullOrWhiteSpace($sessionStartSource)) {
-    $args += @("--session-start-source", "$sessionStartSource")
+    $herdrArgs += @("--session-start-source", "$sessionStartSource")
 }
 try {
-    & $herdr `@args` 2>$null | Out-Null
+    & $herdr `@herdrArgs` 2>$null | Out-Null

Source: Linters/SAST tools


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 4400930c-fd6e-4f4d-9647-f2010500722a

📥 Commits

Reviewing files that changed from the base of the PR and between d004089 and 1767a57.

📒 Files selected for processing (11)
  • docs/next/CHANGELOG.md
  • docs/next/website/src/content/docs/integrations.mdx
  • docs/next/website/src/content/docs/ja/integrations.mdx
  • docs/next/website/src/content/docs/session-state.mdx
  • docs/next/website/src/content/docs/zh-cn/integrations.mdx
  • src/integration/assets/grok/herdr-agent-state.ps1
  • src/integration/assets/grok/herdr-agent-state.sh
  • src/integration/mod.rs
  • src/integration/tests.rs
  • src/terminal/state.rs
  • tests/cli/hooks.rs

@akbash-bot

Copy link
Copy Markdown
Collaborator Author

Agreed, renamed the PowerShell argument array to avoid shadowing the automatic $args variable in 46fb651.

@greptile-apps

greptile-apps Bot commented Aug 11, 2026

Copy link
Copy Markdown

Greptile Summary

The PR updates Grok’s managed integration so /new session-start events replace the pane’s prior Grok session identity without allowing a different agent owner to be displaced.

  • Forwards Grok’s session-start source through the Unix socket and Windows CLI hook paths.
  • Allows new to replace an existing same-owner Grok session reference while preserving different-owner rejection.
  • Bumps the managed Grok integration to version 2 and updates status tests and documentation.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
src/terminal/state.rs Adds narrowly scoped same-owner Grok new replacement while explicitly preserving the different-owner guard.
src/integration/assets/grok/herdr-agent-state.sh Forwards the Grok session-start source in the Unix socket request using the established schema field.
src/integration/assets/grok/herdr-agent-state.ps1 Forwards the session-start source through a PowerShell argument array without shadowing PowerShell’s automatic argument variable.
src/integration/mod.rs Advances the expected Grok integration version to match the changed bundled assets.
src/integration/tests.rs Covers bundled asset metadata, source reporting support, and current versus outdated Grok integration versions.
tests/cli/hooks.rs Verifies that the Unix Grok hook emits both the new session ID and new session-start source.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
    G[Grok SessionStart event] --> H[Managed Grok hook]
    H -->|session ID and source=new| R[pane.report_agent_session]
    R --> O{Existing session owner}
    O -->|Same Grok owner| U[Replace persisted Grok session ID]
    O -->|Different owner| X[Reject replacement]
    U --> P[Use current conversation for API results and restore]
Loading

Reviews (2): Last reviewed commit: "fix: avoid powershell args shadowing" | Re-trigger Greptile

@ogulcancelik

Copy link
Copy Markdown
Collaborator

@akbash-bot the implementation review is clean. the new source is limited to same-owner Grok replacement, different-owner takeover remains blocked, and v2 is the correct release-relative integration bump. please rebase onto current master, resolve the code/docs conflicts, and rerun checks and both review bots.

@akbash-bot

Copy link
Copy Markdown
Collaborator Author

Rebase is resolved locally onto current master (7d56b4c5), preserving Qwen's newer code/docs alongside Grok v2. Focused Grok tests pass; just check reached 3,520/3,521 passing, with only live_server_holds_one_pty_master_fd_per_pane failing identically on unchanged master in this VPS.

I cannot update this PR's canonical head branch: akbash-bot currently has triage-only repository permission, and the force-with-lease push to herdrdev/herdr:akbash/2681-grok-session-new returns HTTP 403. The rebased head is available at akbash-bot/herdr:akbash/2681-grok-session-new (338e692c). Please restore bot push access or force-update the canonical branch to that head; after the PR head moves I can complete CI, CodeRabbit, and Greptile review on the new SHA.

@akbash-bot akbash-bot added the maintainer-needed requires maintainer judgment or maintainer-only reproduction label Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-review Trigger automated AI reviews for pull requests admitted by the PR gate maintainer-needed requires maintainer judgment or maintainer-only reproduction

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants