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

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ed1a5af4-6303-415e-9798-8d64a6b5c72d

📥 Commits

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

📒 Files selected for processing (1)
  • src/integration/assets/grok/herdr-agent-state.ps1
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/integration/assets/grok/herdr-agent-state.ps1

📝 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
Title check ✅ Passed The title clearly identifies the main change: updating the Grok session after a new session starts.
Description check ✅ Passed The description accurately summarizes the Grok integration, session replacement, version, documentation, and test changes.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch akbash/2681-grok-session-new

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 the Grok integration so SessionStart reports carry their source and a same-owner new event can replace the pane’s prior Grok session identity.

  • Forwards Grok’s SessionStart source through Unix JSON-RPC and Windows CLI hook transports.
  • Preserves the different-owner session guard while permitting same-owner Grok new replacement.
  • Bumps the managed Grok integration to version 2 and updates tests and documentation.

Confidence Score: 5/5

The PR appears safe to merge, with the new same-owner Grok replacement path retaining the intended different-owner protection.

Both platform hook transports match the existing API and CLI contracts, the integration version is synchronized with the changed assets, and the state logic narrowly enables Grok new replacement with focused regression coverage.

Important Files Changed

Filename Overview
src/integration/assets/grok/herdr-agent-state.sh Forwards a nonempty Grok SessionStart source in the Unix JSON-RPC payload while preserving existing session-id selection.
src/integration/assets/grok/herdr-agent-state.ps1 Adds the equivalent Windows CLI argument using a safely constructed argument array.
src/terminal/state.rs Allows same-owner Grok session replacement only for new while explicitly retaining the different-owner guard.
src/integration/mod.rs Bumps the embedded Grok integration version to ensure behaviorally stale installations are reported as outdated.
src/integration/tests.rs Extends version, asset-content, and current/outdated status coverage for Grok integration v2.
tests/cli/hooks.rs Verifies that the Unix Grok hook reports both the new session id and new SessionStart source.

Sequence Diagram

sequenceDiagram
  participant Grok as Grok CLI
  participant Hook as Grok SessionStart hook
  participant API as pane.report_agent_session
  participant State as TerminalState
  participant Persist as Persisted session identity
  Grok->>Hook: "SessionStart(source="new", session id)"
  Hook->>API: "session_start_source="new""
  API->>State: set session ref for session start
  alt Existing session has same Grok owner
    State->>Persist: Replace with new Grok session id
  else Existing session has different owner
    State-->>Persist: Preserve existing owner and identity
  end
Loading

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

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants