Public: anyone can read this; the crew can change it.

forge.json validates a service app's ports and refuses a clash with another app #16778

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

A service whose declared port is already held by another running service is now refused at deploy. The refusal names both, for example "port 25565 is already held by mc; proxy cannot declare it".

Notes

opened this

A service whose declared port is already held by another running service is now refused at deploy. The refusal names both, for example "port 25565 is already held by mc; proxy cannot declare it". I ran bun test test/service-ports.test.ts test/service-run.test.ts (10 pass), bun x tsc --noEmit and bun scripts/gate.ts, all clean. I did not boot the app or try a real deploy.

  • Already there: parseService in src/apps/service.ts already refused ports that weren't integers 1024–65535 and any port named twice in one app. I left that alone.
  • Added: portClash(mine, ports, holders) in src/apps/service.ts is a pure function that returns the refusal text or null. bringUp in src/apps/runtime_bringup.ts calls it for service manifests only, before the checkout, against every other environment with a live service. The cell's own port is not touched.
  • Tests: test/service-ports.test.ts covers valid ports, out of range (including fractional and non-number), duplicates, and the cross-app clash.
  • Preview vs production: A preview and its own production also clash, since they share one host. I counted that as a clash on purpose.
  • Holders: Only environments live in this process count as holders, not ones that are asleep or stopped. That means the check misses a service that is down at the moment, and it isn't a stored claim on the port.
  • Pull page and push check: I did not add the check to the pull page or the push check. It only runs at deploy.
  • Docs: No docs/features entry or src/tui change, because no page, API route or tool changed.

To try it, deploy two service apps that declare the same port. The second deploy fails with the refusal above.

🤖 Generated with Claude Code

Closes #15078

2 earlier comments
commented

A service whose declared port is already held by another running service is now refused at deploy. The refusal names both, for example "port 25565 is already held by mc; proxy cannot declare it". I ran bun test test/service-ports.test.ts test/service-run.test.ts (10 pass), bun x tsc --noEmit and bun scripts/gate.ts, all clean. I did not boot the app or try a real deploy.

  • Already there: parseService in src/apps/service.ts already refused ports that weren't integers 1024–65535 and any port named twice in one app. I left that alone.
  • Added: portClash(mine, ports, holders) in src/apps/service.ts is a pure function that returns the refusal text or null. bringUp in src/apps/runtime_bringup.ts calls it for service manifests only, before the checkout, against every other environment with a live service. The cell's own port is not touched.
  • Tests: test/service-ports.test.ts covers valid ports, out of range (including fractional and non-number), duplicates, and the cross-app clash.
  • Preview vs production: A preview and its own production also clash, since they share one host. I counted that as a clash on purpose.
  • Holders: Only environments live in this process count as holders, not ones that are asleep or stopped. That means the check misses a service that is down at the moment, and it isn't a stored claim on the port.
  • Pull page and push check: I did not add the check to the pull page or the push check. It only runs at deploy.
  • Docs: No docs/features entry or src/tui change, because no page, API route or tool changed.

To try it, deploy two service apps that declare the same port. The second deploy fails with the refusal above.

🤖 Generated with Claude Code

commented

Both points are fixed and pushed. bun test test/service-ports.test.ts passes (7), bun x tsc --noEmit is clean, and bun scripts/gate.ts printed nothing. I did not boot a real deploy.

  • Previews of a service app: the check now skips every environment with the same app id as the one deploying. A preview, or a redeploy of a changed branch, is no longer refused for its own production's ports. Only another app's live service counts as a holder.
  • Holder loop moved and tested: it is now portHolders and deployPortRefusal in src/apps/service.ts, beside portClash. bringUp just calls deployPortRefusal and returns its text as the error. test/service-ports.test.ts now covers these cases:
    • A preview whose production holds the same port is allowed.
    • A different app's holder is refused, with the exact message and the environment name, for example mc (pull-9).
    • A service that is not live, and a web app, hold nothing.
  • Valid, out-of-range and duplicate tests: I kept them, and agree they only cover parseService, which was already there. The new tests are the ones for this change.
  • Documented limit: docs/APPS.md now says that only services live in this forge process hold ports. A stopped or asleep service holds none, so the answer depends on what is awake.

One thing left as it was: two previews of different apps that declare the same port are still refused while both are live. That matches the issue's cross-app rule.

🤖 Generated with Claude Code

commented

This push fixes the failed gate check: test/service-ports.test.ts no longer uses as never.

The pull itself is unchanged: a service's declared port that another app already holds is refused at deploy, and the message names both apps.

The two casts were in the svc helper and in the web record that has no service. To drop them I narrowed PortEnv.live.manifest.service in src/apps/service.ts to Pick<ServiceSpec, "ports">. The port check only reads ports, so the tests can now build plain records that type-check.

Verification:

  • bun scripts/gate.ts is clean.
  • bun x tsc --noEmit is clean.
  • bun test test/service-ports.test.ts passes (7 tests).

I didn't run the rest of the suite; the forge runs the full check on this push.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs