Skip to content

fix: add Token Lifetime selector to Access Keys page#1084

Merged
jeremyeder merged 4 commits intoambient-code:mainfrom
jeremyeder:fix/keys-page-token-lifetime
Mar 31, 2026
Merged

fix: add Token Lifetime selector to Access Keys page#1084
jeremyeder merged 4 commits intoambient-code:mainfrom
jeremyeder:fix/keys-page-token-lifetime

Conversation

@jeremyeder
Copy link
Copy Markdown
Contributor

Summary

  • Add Token Lifetime dropdown to the Create Key dialog on /projects/[name]/keys with 6 options (1 day, 7 days, 30 days, 90 days, 1 year, no expiration; default: 90 days)
  • Pass expirationSeconds to the backend API when creating keys — previously all tokens defaulted to 1-hour expiration
  • Remove dead KeysSection component and its tests (never imported or rendered anywhere)
  • Add .worktrees/ to .gitignore

Test plan

  • npm run build passes (0 errors, 0 warnings)
  • npx vitest run passes (no regressions from deleted tests)
  • Navigate to /projects/<name>/keys, click Create Key, confirm Token Lifetime dropdown appears with 6 options defaulting to 90 days
  • Create a key with a non-default expiration and verify expirationSeconds is sent in the API request
  • Create a key with "No expiration" and verify expirationSeconds is omitted from the request

🤖 Generated with Claude Code

jeremyeder and others added 2 commits March 27, 2026 22:55
The create key dialog was missing the expiration selector, causing all
tokens to default to 1-hour expiration. Add a Token Lifetime dropdown
with options from 1 day to no expiration (default: 90 days). Also
remove dead KeysSection component that was never rendered.

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

coderabbitai bot commented Mar 28, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 20d6e440-dfd5-46dc-863e-00a14e3b43dc

📥 Commits

Reviewing files that changed from the base of the PR and between 9c82335 and 5e5cdbc.

📒 Files selected for processing (1)
  • .gitignore

Walkthrough

Removes the KeysSection UI and its tests/exports, adds a "Token Lifetime" select to the project keys page that conditionally sends expirationSeconds, updates .gitignore to ignore .worktrees/, and refactors test formatting in ambient-runner tests. (50 words)

Changes

Cohort / File(s) Summary
Gitignore
/.gitignore
Added .worktrees/ to the ignore patterns.
Token Lifetime (UI)
components/frontend/src/app/projects/[name]/keys/page.tsx
Added newKeyExpiration state (default 90 days) and a "Token Lifetime" Select in the Create Access Key dialog; requests now include expirationSeconds unless none is selected; state reset after successful creation.
Removed KeysSection
components/frontend/src/components/workspace-sections/keys-section.tsx, components/frontend/src/components/workspace-sections/__tests__/keys-section.test.tsx, components/frontend/src/components/workspace-sections/index.ts
Deleted the KeysSection component file, its associated Vitest test suite, and removed its re-export from the workspace-sections index.
Test Formatting
components/runners/ambient-runner/tests/test_shared_session_credentials.py
Refactored test code formatting (multi-line dicts, parenthesized assertion messages, consolidated patch context managers) with no behavioral changes.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 70.83% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding a Token Lifetime selector to the Access Keys page, which aligns with the primary feature addition in the changeset.
Description check ✅ Passed The description is directly related to the changeset, covering all major changes including the Token Lifetime dropdown, API integration, removal of dead code, and .gitignore updates.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@components/frontend/src/app/projects/`[name]/keys/page.tsx:
- Around line 75-76: Reset the new key expiration whenever the create dialog is
closed (both on success and on cancel/close) rather than only after successful
creation: ensure any close handler that calls setShowCreate(false) also calls
setNewKeyExpiration(DEFAULT_EXPIRATION) (or add a centralized onClose function
used by both the success path and the cancel/close UI) so the component state
(setNewKeyExpiration and DEFAULT_EXPIRATION) is restored whenever the dialog is
dismissed.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 48cc6f2d-9bff-4f24-848b-af8ad9ad7d04

📥 Commits

Reviewing files that changed from the base of the PR and between 2bc8e00 and 9c82335.

📒 Files selected for processing (6)
  • .gitignore
  • components/frontend/src/app/projects/[name]/keys/page.tsx
  • components/frontend/src/components/workspace-sections/__tests__/keys-section.test.tsx
  • components/frontend/src/components/workspace-sections/index.ts
  • components/frontend/src/components/workspace-sections/keys-section.tsx
  • components/runners/ambient-runner/tests/test_shared_session_credentials.py
💤 Files with no reviewable changes (3)
  • components/frontend/src/components/workspace-sections/index.ts
  • components/frontend/src/components/workspace-sections/keys-section.tsx
  • components/frontend/src/components/workspace-sections/tests/keys-section.test.tsx

Comment on lines +75 to 76
setNewKeyExpiration(DEFAULT_EXPIRATION);
setShowCreate(false);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Reset token lifetime when the dialog closes, not only on success

Line 75 resets the lifetime only after a successful create. If a user selects No expiration and closes/cancels, reopening can retain that prior value, increasing risk of accidentally creating long-lived keys.

Proposed fix
+  const handleCreateDialogOpenChange = useCallback((open: boolean) => {
+    setShowCreate(open);
+    if (!open) {
+      setNewKeyExpiration(DEFAULT_EXPIRATION);
+    }
+  }, []);
+
   {/* Create Key Dialog */}
-  <Dialog open={showCreate} onOpenChange={setShowCreate}>
+  <Dialog open={showCreate} onOpenChange={handleCreateDialogOpenChange}>
     <DialogContent className="sm:max-w-[425px]">
...
             <Button
               variant="outline"
-              onClick={() => setShowCreate(false)}
+              onClick={() => handleCreateDialogOpenChange(false)}
               disabled={createKeyMutation.isPending}
             >

As per coding guidelines, "Focus on major issues impacting performance, readability, maintainability and security. Avoid nitpicks and avoid verbosity."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@components/frontend/src/app/projects/`[name]/keys/page.tsx around lines 75 -
76, Reset the new key expiration whenever the create dialog is closed (both on
success and on cancel/close) rather than only after successful creation: ensure
any close handler that calls setShowCreate(false) also calls
setNewKeyExpiration(DEFAULT_EXPIRATION) (or add a centralized onClose function
used by both the success path and the cancel/close UI) so the component state
(setNewKeyExpiration and DEFAULT_EXPIRATION) is restored whenever the dialog is
dismissed.

@jeremyeder
Copy link
Copy Markdown
Contributor Author

Addressing PR Feedback

Found 2 unaddressed item(s):

  • [Review] @coderabbitai[bot] [COMMENTED]:

    Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the ...

- **[Code comment]** @coderabbitai[bot] `components/frontend/src/app/projects/[name]/keys/page.tsx:76`:
  > _⚠️ Potential issue_ | _🟠 Major_

**Reset token lifetime when the dialog closes, not only on success**

Line 75 resets the lifetime only after a succ...

---
*Flagged for review via PR Triage Dashboard*

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 28, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@ambient-code ambient-code bot added this to the Review Queue milestone Mar 30, 2026
@jeremyeder jeremyeder merged commit 77ace72 into ambient-code:main Mar 31, 2026
29 checks passed
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