Skip to content

feat: add runtime per session - #338

Merged
pedronauck merged 2 commits into
mainfrom
session-runtime
Jul 26, 2026
Merged

feat: add runtime per session#338
pedronauck merged 2 commits into
mainfrom
session-runtime

Conversation

@pedronauck

@pedronauck pedronauck commented Jul 25, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • New Features
    • Added support for providing an initial prompt when creating a session (durably staged for the starting flow).
    • Added a --prompt option to the session creation command.
    • Updated the session creation dialog with a first-message prompt composer (keyboard submission, validation, accessible send controls).
    • Added a “composer” variant to the runtime selector.
  • Bug Fixes
    • Trimmed and validated prompts, omitted prompt when empty, and rejected whitespace-only drafts.
    • Ensured initial prompt dispatch and preservation during retries, preventing duplicate submissions.
  • Tests
    • Expanded API, CLI, integration, and UI coverage for durable starting and prompt behavior.

@pedronauck pedronauck self-assigned this Jul 25, 2026
@vercel

vercel Bot commented Jul 25, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
agh-site Ready Ready Preview, Comment Jul 26, 2026 2:18am

Request Review

@compozyrabbit

compozyrabbit Bot commented Jul 25, 2026

Copy link
Copy Markdown

Code Review Could Not Complete ⚠️

The review failed before suggestions could be generated.

Reason: Unexpected error while running the code review (open_router).

After fixing the issue, comment @kody review on this PR to re-run the review.

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the @kody start-review command at the root of your PR.

  • Validate Business Logic: Ask Kody to validate your code against business rules by adding a comment with the @kody -v business-logic command.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug
Performance
Security
Business Logic

Access your configuration settings here.

@coderabbitai

coderabbitai Bot commented Jul 25, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 806d1203-de71-422a-b326-65d48ae5ec0b

📥 Commits

Reviewing files that changed from the base of the PR and between 95b3086 and bd5fd86.

📒 Files selected for processing (5)
  • internal/extension/host_api_test.go
  • internal/session/manager_create_accepted.go
  • web/src/systems/session/components/session-create-prompt-composer.tsx
  • web/src/systems/session/hooks/__tests__/use-session-create-dialog.test.tsx
  • web/src/systems/session/hooks/use-session-create-dialog.ts

Disabled knowledge base sources:

  • Linear integration is disabled

You can enable these sources in your CodeRabbit configuration.


Walkthrough

Session creation now accepts an optional initial prompt across API contracts, durable session startup, CLI commands, host APIs, transport tests, and the web session-creation dialog with integrated runtime control.

Changes

Initial prompt session creation

Layer / File(s) Summary
Prompt contracts and API wiring
internal/api/contract/*, internal/api/core/*, internal/api/testutil/*, internal/session/manager_types.go
CreateSessionRequest and accepted-session interfaces now carry an optional initial prompt; test stubs validate trimmed prompts and updated CreateAcceptedOpts shape.
Durable accepted-session lifecycle
internal/session/manager_create_accepted.go, internal/session/manager_start*.go, internal/session/manager_delete_staging.go, internal/session/manager_start_test.go
Accepted sessions stage and dispatch the initial prompt after startup; failure paths discard or retain sessions using staged-delete rollback; tests cover activation, resume, queue failure, and catalog-deletion recovery.
Host API and command entry points
internal/extension/*, internal/cli/session_create.go, internal/cli/session_test.go
Host API creation uses atomic CreateAccepted for non-empty prompts (requiring manager support) or falls back to standard create; session new adds a trimmed --prompt flag with CLI examples and tests.
Transport and mock validation
internal/api/udsapi/transport_parity_integration_test.go, web/src/systems/session/mocks/*
Integration tests verify prompt propagation, durable starting responses, session activation, and delegated-task transcript output.
Runtime selector composer variant
web/src/systems/runtime/components/runtime-selector/*
Runtime selector adds a composer variant with refactored trigger styling, inert-state handling, and test coverage for in-dialog presentation.
Web session dialog and prompt composer
web/src/systems/session/components/*, web/src/systems/session/hooks/*, web/src/systems/session/adapters/*, web/src/systems/os/components/desktop-shell.tsx
Session dialog integrates a new prompt composer with keyboard submission (Enter sends, Shift+Enter inserts newline), validation (rejects whitespace-only), and runtime control; draft state manages prompt lifecycle (preserved across workspace boundaries, reset on agent/workspace change, cleared after durable acceptance).

Estimated code review effort: 4 (Complex) | ~65 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Dialog as SessionCreateDialog
  participant Hook as useSessionCreateDialog
  participant API as createSession
  participant Handler as SessionAcceptanceManager
  participant Manager as SessionManager
  Dialog->>Hook: onPromptChange(text), submit()
  Hook->>Hook: trim prompt, validate non-empty
  Hook->>API: createSession(agentName, prompt, ...)
  API->>Handler: CreateAccepted(InitialPrompt: trimmed)
  Handler->>Manager: stage prompt + start session
  Manager->>Manager: dispatch prompt to input queue
  Manager-->>Handler: return starting session
  Handler-->>API: session.state = starting
  API-->>Dialog: session created
  Hook->>Hook: reset draft to EMPTY_DRAFT
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 8.82% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is related to the changeset: it reflects the new per-session runtime selection and related session creation flow, even if it omits the prompt-focused details.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch session-runtime

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.

@github-actions

github-actions Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

React Doctor found no new issues. 🎉

Reviewed by React Doctor for commit bd5fd86.

@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.

Actionable comments posted: 1

🧹 Nitpick comments (3)
internal/session/manager_create_accepted.go (1)

27-29: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Stage the prompt on a cancellation-detached context.

The session is already durably accepted when stageAcceptedInitialPrompt runs, but it enqueues on the caller's request context. A client disconnect between acceptance and enqueue turns into a staging error and rolls the whole accepted session back, even though the durable record already exists. Detaching with a bounded deadline keeps the post-acceptance work independent of the request lifetime.

As per coding guidelines, "Work that outlives an HTTP or UDS request must use context.WithoutCancel(ctx) and reattach a deadline when needed".

♻️ Proposed change
 func (m *Manager) stageAcceptedInitialPrompt(ctx context.Context, sessionID string, prompt string) error {
 	message := strings.TrimSpace(prompt)
 	if message == "" {
 		return nil
 	}
 	if m.inputQueue == nil {
 		return errors.New("session: input queue is not configured")
 	}
-	generation, err := m.currentInputGeneration(ctx, sessionID)
+	stageCtx, cancel := context.WithTimeout(context.WithoutCancel(ctx), defaultLifecycleTimeout)
+	defer cancel()
+	generation, err := m.currentInputGeneration(stageCtx, sessionID)
 	if err != nil {
 		return fmt.Errorf("session: read initial prompt queue generation for %q: %w", sessionID, err)
 	}
-	if _, _, err := m.inputQueue.Enqueue(ctx, sessionID, message, generation); err != nil {
+	if _, _, err := m.inputQueue.Enqueue(stageCtx, sessionID, message, generation); err != nil {
 		return fmt.Errorf("session: stage initial prompt for %q: %w", sessionID, err)
 	}
 	return nil
 }

Also applies to: 44-58

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/session/manager_create_accepted.go` around lines 27 - 29, Update the
accepted-session flow around stageAcceptedInitialPrompt to use a context
detached from request cancellation via context.WithoutCancel(ctx), while
preserving or reattaching an appropriate bounded deadline for the
post-acceptance enqueue. Pass this derived context to stageAcceptedInitialPrompt
so client disconnects do not roll back an already durable session; apply the
same change to the other referenced accepted-session path.

Source: Coding guidelines

web/src/systems/session/hooks/use-session-create-dialog.ts (1)

330-337: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Empty-prompt submit returns silently.

submit returns without setting submitError when the trimmed prompt is empty. The dialog's canSubmit currently blocks that path, so it is unreachable from the UI, but any other caller (or a future keyboard shortcut bypassing canSubmit) gets no feedback. Consider surfacing a message like the other validation branches below.

♻️ Optional: surface the validation failure
     if (agentName.length === 0) return;
-    if (prompt.length === 0) return;
+    if (prompt.length === 0) {
+      setSubmitError("Write the first message before starting the session.");
+      return;
+    }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@web/src/systems/session/hooks/use-session-create-dialog.ts` around lines 330
- 337, Update the empty-prompt validation in submit to set submitError before
returning, matching the feedback behavior of the other validation branches. Keep
the trimmed prompt check and existing early-return flow unchanged.
web/src/systems/session/components/session-create-prompt-composer.tsx (1)

77-94: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Prefer the shared Button primitive over a hand-rolled submit button.

The send control re-implements sizing, hover, focus-ring, and disabled styling inline. Using the @agh/ui Button (icon size + accent variant) keeps this composer aligned with the design system as those tokens evolve.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@web/src/systems/session/components/session-create-prompt-composer.tsx` around
lines 77 - 94, The session-create send control should use the shared `@agh/ui`
Button primitive instead of the hand-rolled button. Update the button in the
session creation prompt composer to use the primitive’s submit behavior with its
icon size and accent variant, while preserving data-testid,
disabled={!canSubmit}, loading icon content, and accessibility labeling.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/extension/host_api_test.go`:
- Around line 137-174: Wrap the body of
TestHostAPIHandlerSessionsCreateUsesAtomicAcceptedPrompt in a t.Run subtest
named with the “Should ...” convention, keeping the existing setup, handler
invocation, and assertions inside that subtest.

---

Nitpick comments:
In `@internal/session/manager_create_accepted.go`:
- Around line 27-29: Update the accepted-session flow around
stageAcceptedInitialPrompt to use a context detached from request cancellation
via context.WithoutCancel(ctx), while preserving or reattaching an appropriate
bounded deadline for the post-acceptance enqueue. Pass this derived context to
stageAcceptedInitialPrompt so client disconnects do not roll back an already
durable session; apply the same change to the other referenced accepted-session
path.

In `@web/src/systems/session/components/session-create-prompt-composer.tsx`:
- Around line 77-94: The session-create send control should use the shared
`@agh/ui` Button primitive instead of the hand-rolled button. Update the button in
the session creation prompt composer to use the primitive’s submit behavior with
its icon size and accent variant, while preserving data-testid,
disabled={!canSubmit}, loading icon content, and accessibility labeling.

In `@web/src/systems/session/hooks/use-session-create-dialog.ts`:
- Around line 330-337: Update the empty-prompt validation in submit to set
submitError before returning, matching the feedback behavior of the other
validation branches. Keep the trimmed prompt check and existing early-return
flow unchanged.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: fb608e32-1c81-4436-b3e4-b3597499397f

📥 Commits

Reviewing files that changed from the base of the PR and between 0f445fe and 95b3086.

⛔ Files ignored due to path filters (18)
  • docs/qa/scenarios/RT-010.md is excluded by !**/*.md
  • docs/qa/scenarios/RT-063.md is excluded by !**/*.md
  • docs/qa/scenarios/RT-072.md is excluded by !**/*.md
  • docs/qa/scenarios/RT-new-session-fast-feedback.md is excluded by !**/*.md
  • openapi/agh.json is excluded by !**/*.json
  • packages/site/content/runtime/cli-reference/session/new.mdx is excluded by !**/*.mdx
  • packages/site/content/runtime/core/sessions/lifecycle.mdx is excluded by !**/*.mdx
  • skills/agh/references/runtime-operations.md is excluded by !**/*.md
  • web/e2e/__tests__/agent-categories.spec.ts is excluded by !web/e2e/**
  • web/e2e/__tests__/knowledge.spec.ts is excluded by !web/e2e/**
  • web/e2e/__tests__/marketplace.spec.ts is excluded by !web/e2e/**
  • web/e2e/__tests__/session-onboarding.spec.ts is excluded by !web/e2e/**
  • web/e2e/__tests__/session-provider-override.spec.ts is excluded by !web/e2e/**
  • web/e2e/__tests__/tasks-coordinator-handoff.spec.ts is excluded by !web/e2e/**
  • web/e2e/fixtures/selectors.ts is excluded by !**/fixtures/**, !web/e2e/**
  • web/src/generated/agh-openapi.d.ts is excluded by !**/generated/**, !**/generated/**, !**/*.d.ts
  • web/src/systems/runtime/components/stories/runtime-selector.stories.tsx is excluded by !**/*.stories.tsx
  • web/src/systems/session/components/stories/session-create-dialog.stories.tsx is excluded by !**/*.stories.tsx
📒 Files selected for processing (30)
  • internal/api/contract/contract_test.go
  • internal/api/contract/session_runtime_payloads.go
  • internal/api/core/handlers.go
  • internal/api/core/handlers_test.go
  • internal/api/core/interfaces.go
  • internal/api/testutil/session_stub.go
  • internal/api/udsapi/transport_parity_integration_test.go
  • internal/cli/session_create.go
  • internal/cli/session_test.go
  • internal/extension/host_api.go
  • internal/extension/host_api_sessions.go
  • internal/extension/host_api_test.go
  • internal/session/manager_create_accepted.go
  • internal/session/manager_delete_staging.go
  • internal/session/manager_start.go
  • internal/session/manager_start_launch_accepted.go
  • internal/session/manager_start_test.go
  • internal/session/manager_types.go
  • web/src/systems/os/components/desktop-shell.tsx
  • web/src/systems/runtime/components/runtime-selector/__tests__/runtime-selector.test.tsx
  • web/src/systems/runtime/components/runtime-selector/trigger.tsx
  • web/src/systems/runtime/components/runtime-selector/types.ts
  • web/src/systems/session/adapters/__tests__/session-api.test.ts
  • web/src/systems/session/components/__tests__/session-create-dialog.test.tsx
  • web/src/systems/session/components/session-create-dialog.tsx
  • web/src/systems/session/components/session-create-prompt-composer.tsx
  • web/src/systems/session/hooks/__tests__/use-session-create-dialog.test.tsx
  • web/src/systems/session/hooks/use-session-create-dialog.ts
  • web/src/systems/session/mocks/__tests__/handlers.test.ts
  • web/src/systems/session/mocks/handlers.ts

Comment thread internal/extension/host_api_test.go
@compozyrabbit

compozyrabbit Bot commented Jul 26, 2026

Copy link
Copy Markdown

Code Review Could Not Complete ⚠️

The review failed before suggestions could be generated.

Reason: Unexpected error while running the code review (open_router).

After fixing the issue, comment @kody review on this PR to re-run the review.

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the @kody start-review command at the root of your PR.

  • Validate Business Logic: Ask Kody to validate your code against business rules by adding a comment with the @kody -v business-logic command.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug
Performance
Security
Business Logic

Access your configuration settings here.

@pedronauck
pedronauck merged commit 49fbc39 into main Jul 26, 2026
7 of 9 checks passed
@pedronauck
pedronauck deleted the session-runtime branch July 26, 2026 02:14
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