Skip to content

fix(preview): honor allocated project ports - #119

Merged
iamjr15 merged 1 commit into
mainfrom
fix/preview-port-recovery
Aug 3, 2026
Merged

fix(preview): honor allocated project ports#119
iamjr15 merged 1 commit into
mainfrom
fix/preview-port-recovery

Conversation

@iamjr15

@iamjr15 iamjr15 commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Remap a requested dev-server port inside argv and shell payloads to the project stable allocated port.
  • Make code_start_dev_server the explicit Computer-preview contract and distinguish generic shell processes.
  • Unmount stale cross-origin preview content during a real wake so the new handoff remounts cleanly.
  • Preserve the live iframe during silent eight-minute capability rotation.

Production QA on the first recovery release exposed both cases: the affected project owns 5174 because an old allocation occupies 5173, and a long-hidden iframe retained an expired auth document after the sandbox was force-stopped and restored.

Architecture

The dynamic allocator remains authoritative. Models may request the familiar 5173, but prepared process commands and readiness probes now always target the same allocated port. Only the canonical app-preview:<workspaceSlug> process is Computer-visible and idle-recoverable.

Verification notes

  • pnpm lint
  • pnpm typecheck
  • pnpm turbo build --force
  • pnpm deadcode
  • pnpm architecture:check
  • pnpm turbo skills:build

The forced production build completed uncached for all 19 packages and every Worker dry-run. Architecture analysis reported 847 modules and 1,752 dependencies with no violations. Knip exited cleanly with only four existing configuration hints.

Direct production browser QA already reproduced the port mismatch, created the canonical 5174 process, rendered the VOLTA site, force-stopped the exact Daytona sandbox, and confirmed the same process recovered. Final acceptance after deployment will repeat the hard stop and verify the new automatic iframe remount.

Review focus

  1. remapRequestedDevServerPort keeps command binding aligned with the allocator and readiness probe.
  2. Real wakeups clear stale capability state before booting; silent refreshes do not.
  3. Shell and system guidance prevents untracked user-facing preview processes.

No Linear issue or plan document exists; this follows a directly reproduced production incident.

Remap requested dev-server ports to each project stable slot.
Require managed preview tools and remount stale iframes only after
real sandbox wakeups.
@iamjr15
iamjr15 merged commit 2e35bd2 into main Aug 3, 2026
4 checks passed
@iamjr15
iamjr15 deleted the fix/preview-port-recovery branch August 3, 2026 09:55
iamjr15 added a commit that referenced this pull request Aug 3, 2026
## Summary

- Route high-confidence first-run web/mobile build imperatives through
the managed app-builder path.
- Treat `/workspace` as a virtual project root across file, shell,
inline-code, and preview commands.
- Run genuinely projectless calculations and environment probes from
`/tmp` so they cannot leave orphaned durable files.
- Persist the resolved builder mode when lazy project materialization
creates the project.

## Context

A production DeepSeek run wrote a complete site into
`/workspace/beautiful-site` without attaching a project or registering a
managed preview, then claimed the result was available in Computer.
Files therefore had no project to open and Browser had no preview
record.

No Linear issue or standalone plan document is linked; this is a
production QA follow-up to the preview recovery work in #118 and #119.

## Architecture

A narrowly matched imperative first message (for example, “build a
website”) is promoted from general mode into the existing app-builder
path before model execution. The builder creates the canonical project
and managed preview first. Tool execution then remaps the model-facing
virtual `/workspace` namespace into that project root. Commands with no
workspace intent remain projectless and use `/tmp`.

## Decisions Made

| Decision | Choice | Alternatives considered | Reasoning |
| --- | --- | --- | --- |
| Model variance | Enforce the invariant in runtime code | More prompt
wording | Weaker models may ignore descriptions; project/preview
correctness cannot depend on compliance. |
| Build inference | Only first-run, projectless, imperative web/mobile
prompts | Classify every website mention | Avoids creating projects for
informational questions or existing-project follow-ups. |
| Projectless cwd | `/tmp` | Shared `/workspace` root | Environment
probes stay ephemeral and cannot create unindexed durable files. |
| Workspace paths | Remap virtual paths into the canonical project |
Reject common `/workspace/*` inputs | Keeps models compatible while
preventing sibling-project writes. |

## Edge Cases Handled

| Scenario | Handling |
| --- | --- |
| DeepSeek writes an absolute `/workspace/*` path in argv or inline code
| The path binds and remaps to the active project. |
| A throwaway calculation uses no project path | It runs in `/tmp`
without creating a project. |
| A model requests a familiar preview port | Workspace remapping happens
before stable port remapping. |
| A project already exists or the run is a follow-up | No inferred
builder bootstrap occurs. |
| UI explicitly selected app-builder mode | Explicit mode remains
authoritative. |

## How to Review

1. Start with `agent-run-path.ts` for the high-confidence first-run
builder routing.
2. Review `workspace-paths.ts` and the code-tool adapters for
confinement/remapping.
3. Review `runs.ts` for persisted resolved project mode.
4. Skim README updates for the documented runtime contract.

## Test Plan

- [x] Full monorepo typecheck, including scripts
- [x] Full monorepo lint
- [x] Forced production build for all 19 packages and Worker dry-runs
- [x] Dependency architecture check
- [x] Dead-code check
- [ ] Production DeepSeek first-run build after merge/deploy
- [ ] Confirm Files and Browser both open the materialized project and
managed preview
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