Skip to content

refactor(opencode): retire session Hono route source - #1427

Merged
Astro-Han merged 2 commits into
devfrom
codex/i936-session-hono-retire
Jun 20, 2026
Merged

refactor(opencode): retire session Hono route source#1427
Astro-Han merged 2 commits into
devfrom
codex/i936-session-hono-retire

Conversation

@Astro-Han

@Astro-Han Astro-Han commented Jun 20, 2026

Copy link
Copy Markdown
Owner

Summary

Retire the legacy session Hono route source now that production /session* traffic is handled by the Effect HttpApi dispatcher and shared SessionRouteEffects.

  • Remove SessionRoutes() from the instance Hono tree and delete the stale route re-export.
  • Keep SessionRouteEffects as the shared implementation used by the HttpApi session handlers.
  • Update route inventory tests so /session* rows are no longer Hono-backed while PawWork-owned session rows keep their classification.
  • Move remaining tests away from direct SessionRoutes() construction and onto the production dispatcher or HttpApi handlers.
  • Tighten the home submit smoke to wait for the composer send action to become ready before pressing Enter, matching the app's submit readiness gate.

Why

The session owner had already moved its production source of truth to Effect HttpApi handlers, but packages/opencode/src/server/instance/session.ts still exported and built a large legacy Hono route tree. This kept session rows marked as Hono sources in the inventory and left tests coupled to an implementation that production no longer uses.

Related Issue

Related to #936

Human Review Status

  • Pending — waiting for a human reviewer to approve.

Review Focus

Please focus on whether all legacy SessionRoutes() entrypoints are gone without losing /session* OpenAPI, v2 SDK, local HttpApi, production dispatcher routing, or PawWork-owned inventory coverage.

Risk Notes

Behavior risk is low because production /session* traffic already routes through production-httpapi.ts and sessionHandlers. The main risk is test or inventory drift, covered by the focused session route tests, production boundary tests, route inventory harness, route:inventory, typecheck, and the home submit E2E smoke.

Skipped checklist items:

  • Visible UI/manual screenshot: not applicable; the app behavior did not change, only the E2E smoke now waits for the existing send readiness gate.
  • Platform/packaging manual check: not applicable; this only changes server route source retirement and tests.
  • Docs/release/dependency/generated content: not applicable; route:inventory was run for verification, but the local-only generated report is not part of this PR.

Fresh-eye result: no P0/P1 findings. I considered renaming the internal Effect.fn("SessionRoutes.*") trace labels, but left them unchanged because they do not export or build the Hono route tree and changing trace names would add observability churn without improving the migration boundary. The CI follow-up tightened an over-specific inventory classification assertion for ordinary upstream-covered /session rows while preserving the PawWork-owned classification checks, and added production dispatcher coverage for header-scoped POST /session creation.

How To Verify

Home E2E smoke: 5 passed
Command: CI=true PLAYWRIGHT_BROWSER_CHANNEL=chrome PLAYWRIGHT_VIDEO=off bun run test:e2e:local:smoke -- e2e/app/home.spec.ts

Focused session/server tests: 88 passed
Command: bun test test/server/session-e2e-routes.test.ts test/server/permission-routes.test.ts test/server/session-messages.test.ts test/server/session-httpapi-routes.test.ts test/server/session-core-routes.test.ts test/server/session-list.test.ts test/server/session-actions.test.ts test/server/session-runtime-routes.test.ts test/server/production-boundary.test.ts test/server/route-inventory-harness.test.ts

Route inventory: ok
Command: bun run route:inventory
Result: Hono source routes dropped to 71; checked-in OpenAPI stayed 128; v2 SDK stayed 128; local HttpApi stayed 125. `/session*` rows are Hono=no, and PawWork-owned session rows remain classified as `pawwork-owned`.

Typecheck: ok
Command: GOMAXPROCS=2 bun run typecheck

Diff check: ok
Command: git diff --check

Screenshots or Recordings

Not applicable; no visible UI changes.

Checklist

How to use this checklist:

  • Tick a box by replacing [ ] with [x]. Do not edit, add, or remove items.
  • The bot-applied label items can only be honestly ticked AFTER the PR is opened and the labeler / priority-triage bots have run — return to the PR description and tick them then.
  • Most items are required. The few that are conditional are explicitly marked (conditional); for those, leave unticked if they truly do not apply and explain why in Risk Notes. All other items must be ticked before requesting human review.
  • Type label — this PR carries exactly one of bug, enhancement, task, documentation. Type labels are author-added; the labeler bot does NOT assign them. Add the label in the GitHub UI, then tick this.
  • Routing labels — this PR carries at least one of app, ui, platform, harness, ci. The labeler bot assigns these on PR open based on changed paths. Confirm the bot's choice (or override if wrong), then tick this.
  • Priority label — this PR carries exactly one of P0, P1, P2, P3. The priority-triage bot suggests one on PR open. Confirm or override, then tick this.
  • Human Review Status above is set to Pending, Approved by @<reviewer>, or Not required: <reason> (default is Pending; "not required" is restricted to bot-authored low-risk PRs).
  • I linked the related issue, or stated in Summary why there is no issue.
  • I described the review focus and any meaningful risks.
  • I replaced the example block in How To Verify with the real verification steps and the key result for each.
  • I did not introduce unrelated refactors, dependencies, generated files, or file changes beyond the stated scope.
  • (conditional) I manually checked visible UI or copy changes when needed, with screenshots or recordings. Leave unticked only if no visible UI or copy changed.
  • (conditional) I considered macOS and Windows impact for platform, packaging, updater, signing, paths, shell, or permissions changes. Leave unticked only if no platform/packaging surface was touched.
  • (conditional) I called out docs, release notes, dependencies, permissions, credentials, deletion behavior, generated content, or local file changes when relevant. Leave unticked only if none of those surfaces was touched.
  • I reviewed the final diff for unrelated changes and suspicious dependency changes.
  • I am targeting dev, and my PR title and commit messages use Conventional Commits in English.

Summary by CodeRabbit

  • Tests

    • Improved test coverage for prompt submit button validation before sending.
    • Updated session endpoint tests with streamlined routing patterns.
    • Added comprehensive coverage validation for session creation and HTTP API interactions.
  • Refactor

    • Reorganized session routing architecture across server modules.

@Astro-Han Astro-Han added P2 Medium priority harness Model harness, prompts, tool descriptions, and session mechanics task Narrow execution, audit, spike, migration, tracking, or upstream follow-up work tech-debt Supplemental cleanup, maintainability, architecture, test, or quality debt context labels Jun 20, 2026
@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The PR retires the legacy Hono-based SessionRoutes from the instance router and route-inventory scanner, cleans up session.ts by removing inlined route helpers, and migrates affected tests to use SessionApi/HttpApi-based routing. Separately, two home composer E2E smoke tests gain explicit submit button enabled-state assertions before prompt submission.

Changes

Legacy Hono SessionRoutes Retirement

Layer / File(s) Summary
Remove SessionRoutes from instance router and inventory script
packages/opencode/script/route-inventory.ts, packages/opencode/src/server/instance/session.ts
Removes /session entry from honoRouteSources and strips SessionRoutes from session.ts, deleting runHttpPrompt, inlined Zod route helpers, and adjusting the export boundary.
Permission routes test: migrate to SessionApi/HttpApi
packages/opencode/test/server/permission-routes.test.ts
Replaces SessionRoutes Hono import with SessionApi and sessionHandlers, introduces requestSessionHttpApi helper, and rewires the deprecated permission route test to use it.
Session e2e and messages tests migrated off SessionRoutes
packages/opencode/test/server/session-e2e-routes.test.ts, packages/opencode/test/server/session-messages.test.ts
E2E test replaces SessionRoutes/Instance.provide construction with Server.Default().app and directory query param; messages test updates source-file inspection to the new HttpApi handler path and expected error-handling signal names.
Production boundary and route inventory harness updates
packages/opencode/test/server/production-boundary.test.ts, packages/opencode/test/server/route-inventory-harness.test.ts
Adds production-boundary tests for /session POST and for verifying SessionRoutes absence; flips hono presence flags for retired routes, adds retired-route exclusion assertions, and updates the Windows path-separator test reference.

Home Composer E2E Submit Button Assertions

Layer / File(s) Summary
Assert prompt submit button enabled
packages/app/e2e/app/home.spec.ts
Both the hero prompt and slash-prefixed fallback path tests now locate [data-action="prompt-submit"] and assert it is enabled after typing, before pressing Enter.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • Astro-Han/pawwork#657: Modifies the same home composer Playwright smoke tests in packages/app/e2e/app/home.spec.ts around prompt-submit readiness and slash-fallback submission flow.
  • Astro-Han/pawwork#949: Introduces the route inventory harness/script that this PR updates to reflect the removal of legacy session Hono routes.
  • Astro-Han/pawwork#1385: Updates session HttpApi coverage expectations in the same route-inventory-harness.test.ts file, directly related to the session endpoint migration tracked here.

Suggested labels

upstream

🐇 Hono session routes? Gone today!
HttpApi paths now lead the way.
Submit buttons checked before the send,
Inventory scripts updated — trend!
Old exports stripped, new tests in place,
A cleaner routing interface. 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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
Title check ✅ Passed The title clearly and concisely describes the main change: retiring the legacy session Hono route source from the codebase.
Description check ✅ Passed The description follows the template structure with all major sections completed: Summary, Why, Related Issue, Human Review Status, Review Focus, Risk Notes, How To Verify, and a properly filled Checklist.
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.

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

✨ 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 codex/i936-session-hono-retire

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration.


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.

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

Suggested priority: P2 (includes non-doc, non-test paths outside the low-risk bucket).

P1/P0 are reserved for maintainer confirmation. Please relabel manually if this is a release blocker, security issue, data-loss risk, or updater/runtime failure.

@github-actions github-actions Bot added the app Application behavior and product flows label Jun 20, 2026

@coderabbitai coderabbitai Bot left a comment

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.

🧹 Nitpick comments (1)
packages/opencode/test/server/permission-routes.test.ts (1)

50-65: 💤 Low value

Consider extracting shared helper logic.

The requestSessionHttpApi helper duplicates most of the logic from requestPermissionHttpApi (lines 32-48). Both follow the identical pattern: build HttpRouter, provide handlers and platform layers, construct and route the request.

While acceptable for this migration PR, consolidating into a parameterized factory would reduce duplication:

function requestHttpApi<A>(api: HttpApi.HttpApi<any, any>, handlers: Layer.Layer<any, any, any>) {
  return (path: string, init?: RequestInit) =>
    AppRuntime.runPromise(
      Effect.scoped(
        Effect.gen(function* () {
          const router = yield* HttpRouter.toHttpEffect(
            HttpApiBuilder.layer(api).pipe(
              Layer.provide(handlers),
              Layer.provide(Layer.mergeAll(NodeFileSystem.layer, NodeHttpPlatform.layer, NodePath.layer, Etag.layer)),
            ),
          )
          const request = HttpServerRequest.fromWeb(new Request(`http://localhost${path}`, init))
          const response = yield* router.pipe(Effect.provideService(HttpServerRequest.HttpServerRequest, request), Effect.orDie)
          return HttpServerResponse.toWeb(response)
        }),
      ) as Effect.Effect<Response>,
    )
}
🤖 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 `@packages/opencode/test/server/permission-routes.test.ts` around lines 50 -
65, The requestSessionHttpApi and requestPermissionHttpApi functions contain
duplicated logic that differs only in the api and handlers parameters. Extract
this shared logic into a single parameterized factory function that accepts the
HttpApi and handlers as parameters, then have both requestSessionHttpApi and
requestPermissionHttpApi call this factory with their respective api and
handlers arguments to eliminate the duplication.
🤖 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.

Nitpick comments:
In `@packages/opencode/test/server/permission-routes.test.ts`:
- Around line 50-65: The requestSessionHttpApi and requestPermissionHttpApi
functions contain duplicated logic that differs only in the api and handlers
parameters. Extract this shared logic into a single parameterized factory
function that accepts the HttpApi and handlers as parameters, then have both
requestSessionHttpApi and requestPermissionHttpApi call this factory with their
respective api and handlers arguments to eliminate the duplication.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: f7a51567-0264-4351-aca2-f214b9379c13

📥 Commits

Reviewing files that changed from the base of the PR and between 284d411 and 6f5d77c.

📒 Files selected for processing (10)
  • packages/app/e2e/app/home.spec.ts
  • packages/opencode/script/route-inventory.ts
  • packages/opencode/src/server/instance/index.ts
  • packages/opencode/src/server/instance/session.ts
  • packages/opencode/src/server/routes/instance/session.ts
  • packages/opencode/test/server/permission-routes.test.ts
  • packages/opencode/test/server/production-boundary.test.ts
  • packages/opencode/test/server/route-inventory-harness.test.ts
  • packages/opencode/test/server/session-e2e-routes.test.ts
  • packages/opencode/test/server/session-messages.test.ts
💤 Files with no reviewable changes (4)
  • packages/opencode/src/server/routes/instance/session.ts
  • packages/opencode/src/server/instance/index.ts
  • packages/opencode/script/route-inventory.ts
  • packages/opencode/src/server/instance/session.ts

@Astro-Han
Astro-Han merged commit 08d1079 into dev Jun 20, 2026
44 checks passed
@Astro-Han
Astro-Han deleted the codex/i936-session-hono-retire branch June 20, 2026 05:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app Application behavior and product flows harness Model harness, prompts, tool descriptions, and session mechanics P2 Medium priority task Narrow execution, audit, spike, migration, tracking, or upstream follow-up work tech-debt Supplemental cleanup, maintainability, architecture, test, or quality debt context

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant