Skip to content

fix(cli): respect project scope on TUI session refresh#1587

Merged
mergify[bot] merged 3 commits into
mainfrom
fix/tui-project-filter-on-refresh-v2
May 14, 2026
Merged

fix(cli): respect project scope on TUI session refresh#1587
mergify[bot] merged 3 commits into
mainfrom
fix/tui-project-filter-on-refresh-v2

Conversation

@jsell-rh
Copy link
Copy Markdown
Contributor

@jsell-rh jsell-rh commented May 14, 2026

Summary

  • Fix session list reverting to "all sessions" on every poll tick when a project is selected via number keys

Problem

When a user presses a number key (1-9) to switch projects in the TUI, currentAgentID is cleared (correct — you're not drilling into a specific agent). The initial fetch correctly calls FetchSessions(projectName). But on the next 5-second poll tick, fetchActiveView() checked currentAgentID != "" && currentProject != "" — since currentAgentID is empty, it fell through to FetchAllSessions(), replacing the project-filtered view with all sessions across all projects.

The same issue existed in the :sessions command handler (CmdSessions).

Fix

  • fetchActiveView(): check currentProject alone — if set, fetch project-scoped sessions regardless of agent context
  • CmdSessions: add a currentProject-only branch between the agent-scoped and global paths

The TUI spec (docs/internal/design/tui.spec.md) correctly describes this behavior: ":sessions is also accessible globally (all sessions across all projects) or scoped when drilled in." The spec was right, the implementation didn't match.

Test plan

  • go build ./... passes
  • go vet ./... passes
  • Manual: press number key to switch project → sessions stay filtered after multiple poll cycles

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Sessions view now prioritizes project-scoped session fetching when viewing sessions within a project context
    • Improved navigation and polling behavior for sessions management aligned with project context

The sessions view only used project-scoped fetching when both
currentProject and currentAgentID were set. When a user switched
projects via number keys (which clears currentAgentID), the initial
fetch was correctly scoped but every subsequent poll tick fell through
to FetchAllSessions(), replacing the filtered view with all sessions.

Fix fetchActiveView() and CmdSessions to check currentProject
independently of currentAgentID. This matches the spec: "`:sessions`
is also accessible globally or scoped when drilled in."

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@netlify
Copy link
Copy Markdown

netlify Bot commented May 14, 2026

Deploy Preview for cheerful-kitten-f556a0 canceled.

Name Link
🔨 Latest commit ac9a5e7
🔍 Latest deploy log https://app.netlify.com/projects/cheerful-kitten-f556a0/deploys/6a05e618346b370008c55238

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 14, 2026

Warning

Rate limit exceeded

@jsell-rh has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 53 minutes and 14 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 5bbab48b-5bf0-4d84-b732-0fa970e97126

📥 Commits

Reviewing files that changed from the base of the PR and between f9bb313 and ac9a5e7.

📒 Files selected for processing (2)
  • components/ambient-cli/cmd/acpctl/ambient/tui/fetch_scope_test.go
  • components/ambient-cli/cmd/acpctl/ambient/tui/model_new.go
📝 Walkthrough

Walkthrough

Sessions view now prioritizes project-scoped fetching in fetchActiveView and adds project-scoped command branch in executeCommand, routing through projects→sessions navigation.

Changes

Project-Scoped Sessions View

Layer / File(s) Summary
Sessions fetch and navigation strategy
components/ambient-cli/cmd/acpctl/ambient/tui/model_new.go
fetchActiveView for sessions now checks currentProject first and calls FetchSessions(m.currentProject), falling back to global only when no project context exists. executeCommand for CmdSessions adds explicit project-only branch that sets scope, rebuilds navigation to projects→sessions, and fetches project-specific sessions before defaulting to agent-scoped or global fallback.

Possibly related PRs

  • ambient-code/platform#895: Implements complementary API-side project-scoped session filtering via X-Ambient-Project header validation in sessionHandler.List.

Suggested labels

ambient-code:self-reviewed

🚥 Pre-merge checks | ✅ 8
✅ Passed checks (8 passed)
Check name Status Explanation
Title check ✅ Passed The title follows Conventional Commits format (fix(cli): ...) and accurately describes the main change: respecting project scope during TUI session polling.
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.
Performance And Algorithmic Complexity ✅ Passed No performance regressions. Changes are conditional branches reducing unnecessary fan-out API calls. No loops, N+1 patterns, unbounded growth, or blocking concerns identified.
Security And Secret Handling ✅ Passed No secrets hardcoded, no injection vulnerabilities, proper authentication via ClientFactory.ForProject(), no K8s Secrets handling, no service account misuse.
Kubernetes Resource Safety ✅ Passed PR modifies Go CLI code (model_new.go) for TUI session filtering. Kubernetes Resource Safety check targets manifests/RBAC configs. Check not applicable to this PR scope.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/tui-project-filter-on-refresh-v2
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch fix/tui-project-filter-on-refresh-v2

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 and usage tips.

@jsell-rh jsell-rh self-assigned this May 14, 2026
Add dataFetcher interface and scopeTrackingClient fake to verify
fetchActiveView() dispatches the correct fetch method based on
currentProject state. Tests cover:

- Project set via number key (no agent) → must use FetchSessions
- Project + agent set (drill-down) → must use FetchSessions
- No project (global) → must use FetchAllSessions
- Scheduled sessions and agents scoping

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@mergify mergify Bot added the queued label May 14, 2026
@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented May 14, 2026

Merge Queue Status

  • Entered queue2026-05-14 15:55 UTC · Rule: default
  • Checks skipped · PR is already up-to-date
  • Merged2026-05-14 15:56 UTC · at ac9a5e78052e2af47afd942f8e28791885256bd2 · squash

This pull request spent 27 seconds in the queue, including 5 seconds running CI.

Required conditions to merge

@mergify mergify Bot merged commit 5c2c69a into main May 14, 2026
37 of 38 checks passed
@mergify mergify Bot deleted the fix/tui-project-filter-on-refresh-v2 branch May 14, 2026 15:56
@mergify mergify Bot removed the queued label May 14, 2026
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