Skip to content

fix(stack): preserve lazy lifecycle in detached mode - #6046

Open
jgoux wants to merge 7 commits into
lazy-stack/05-port-leasesfrom
lazy-stack/06-detached-parity
Open

fix(stack): preserve lazy lifecycle in detached mode#6046
jgoux wants to merge 7 commits into
lazy-stack/05-port-leasesfrom
lazy-stack/06-detached-parity

Conversation

@jgoux

@jgoux jgoux commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Stack layer 6 of 7, based on #6045.

Makes daemon-backed stacks preserve foreground lazy lifecycle semantics:

  • tracks the real activated dependency closure and clears it across restarts
  • fails readiness checks immediately outside the running phase or for dormant lazy services
  • delegates remote readiness to dedicated daemon endpoints
  • preserves typed lifecycle errors across the HTTP boundary
  • validates and bounds the parent-child startup handshake

@jgoux
jgoux force-pushed the lazy-stack/05-port-leases branch from e273d2d to 706b171 Compare August 4, 2026 07:43
@jgoux
jgoux force-pushed the lazy-stack/06-detached-parity branch from f1e0c43 to 64bea19 Compare August 4, 2026 07:43
@jgoux
jgoux marked this pull request as ready for review August 4, 2026 07:51
@jgoux
jgoux requested a review from a team as a code owner August 4, 2026 07:51

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 64bea19f14

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/stack/src/StackLifecycleCoordinator.ts Outdated
Comment thread packages/stack/src/layers.ts Outdated
Comment thread packages/stack/src/RemoteStack.ts Outdated
@jgoux
jgoux force-pushed the lazy-stack/05-port-leases branch from 706b171 to a6e0729 Compare August 4, 2026 08:05
@jgoux
jgoux force-pushed the lazy-stack/06-detached-parity branch from 64bea19 to 89af0f2 Compare August 4, 2026 08:05
@jgoux
jgoux force-pushed the lazy-stack/05-port-leases branch from a6e0729 to fad354d Compare August 4, 2026 08:48
@jgoux
jgoux force-pushed the lazy-stack/06-detached-parity branch from 89af0f2 to e2dd44f Compare August 4, 2026 08:48

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e2dd44f795

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/stack/src/DaemonServer.ts Outdated
@jgoux
jgoux force-pushed the lazy-stack/05-port-leases branch from fad354d to 4265a74 Compare August 4, 2026 09:32
@jgoux
jgoux force-pushed the lazy-stack/06-detached-parity branch from e2dd44f to f130bfd Compare August 4, 2026 09:32

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f130bfd263

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/stack/src/DaemonServer.ts Outdated
Comment thread packages/stack/src/StackLifecycleCoordinator.ts Outdated
Comment thread packages/stack/src/RemoteStack.ts Outdated
@jgoux
jgoux force-pushed the lazy-stack/05-port-leases branch from 4265a74 to c2cdb81 Compare August 4, 2026 09:41
@jgoux
jgoux force-pushed the lazy-stack/06-detached-parity branch 2 times, most recently from ce21004 to fb58086 Compare August 4, 2026 10:20
@jgoux
jgoux force-pushed the lazy-stack/05-port-leases branch from c2cdb81 to ac00e70 Compare August 4, 2026 10:20

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fb580862d7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/stack/docs/detach-mode.md
Comment thread packages/stack/src/DaemonServer.ts Outdated
@jgoux
jgoux force-pushed the lazy-stack/05-port-leases branch from ac00e70 to 3ea143a Compare August 4, 2026 10:37
@jgoux
jgoux force-pushed the lazy-stack/06-detached-parity branch from fb58086 to e4738fa Compare August 4, 2026 10:37

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e4738fa597

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/stack/src/StackLifecycleCoordinator.ts
@jgoux
jgoux force-pushed the lazy-stack/05-port-leases branch from 3ea143a to 1f4a18a Compare August 4, 2026 11:07
@jgoux
jgoux force-pushed the lazy-stack/06-detached-parity branch from e4738fa to d958c83 Compare August 4, 2026 11:07
@jgoux
jgoux force-pushed the lazy-stack/05-port-leases branch from 1f4a18a to 2bd9fd1 Compare August 4, 2026 11:25
@jgoux
jgoux force-pushed the lazy-stack/06-detached-parity branch from d958c83 to 67ad946 Compare August 4, 2026 11:25

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 67ad946444

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/stack/src/daemon.ts Outdated
Comment thread packages/stack/src/StackLifecycleCoordinator.ts Outdated
@jgoux
jgoux force-pushed the lazy-stack/05-port-leases branch from 2bd9fd1 to d96ca0e Compare August 4, 2026 11:35
@jgoux
jgoux force-pushed the lazy-stack/06-detached-parity branch from 67ad946 to b9891e0 Compare August 4, 2026 11:35
@jgoux
jgoux force-pushed the lazy-stack/05-port-leases branch from d96ca0e to 86c6a70 Compare August 4, 2026 11:46
@jgoux
jgoux force-pushed the lazy-stack/06-detached-parity branch from b9891e0 to 6b836fd Compare August 4, 2026 11:46
Comment thread packages/stack/src/daemon.ts Outdated
@jgoux
jgoux force-pushed the lazy-stack/05-port-leases branch from 86c6a70 to 9f2f7d4 Compare August 4, 2026 12:03
@jgoux
jgoux force-pushed the lazy-stack/06-detached-parity branch from 6b836fd to e1d2245 Compare August 4, 2026 12:03

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e1d2245753

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/stack/src/StackLifecycleCoordinator.ts Outdated
@jgoux
jgoux force-pushed the lazy-stack/05-port-leases branch from 9f2f7d4 to 868f236 Compare August 4, 2026 12:12
@jgoux
jgoux force-pushed the lazy-stack/06-detached-parity branch from e1d2245 to f1319ef Compare August 4, 2026 12:12

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f1319efa81

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/stack/src/StateManager.ts Outdated
Comment thread packages/stack/src/RemoteStack.ts
@jgoux
jgoux force-pushed the lazy-stack/05-port-leases branch from 868f236 to 1ebb475 Compare August 4, 2026 12:48
@jgoux
jgoux force-pushed the lazy-stack/06-detached-parity branch from f1319ef to e532be6 Compare August 4, 2026 12:48
Comment thread packages/stack/src/StateManager.ts Outdated
@jgoux
jgoux force-pushed the lazy-stack/05-port-leases branch from 1ebb475 to cc5effc Compare August 4, 2026 12:58
@jgoux
jgoux force-pushed the lazy-stack/06-detached-parity branch from eb66904 to 938ee92 Compare August 4, 2026 12:58

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 938ee92d68

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/stack/src/DaemonServer.ts Outdated
@jgoux
jgoux force-pushed the lazy-stack/05-port-leases branch from cc5effc to 9639149 Compare August 4, 2026 13:20
@jgoux
jgoux force-pushed the lazy-stack/06-detached-parity branch from 938ee92 to 038fc01 Compare August 4, 2026 13:20

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 038fc012de

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/stack/src/ManagedPortLock.ts Outdated
Comment thread packages/stack/src/daemon.ts
@jgoux
jgoux force-pushed the lazy-stack/05-port-leases branch from 9639149 to 8d6ede9 Compare August 4, 2026 14:06
@jgoux
jgoux force-pushed the lazy-stack/06-detached-parity branch from 038fc01 to d486dd6 Compare August 4, 2026 14:06

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d486dd6436

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

process.platform === "win32" ? tmpdir() : "/tmp",
"supabase-stack-managed-port-locks",
);
const PRIVATE_LOCK_ROOT = join(homedir(), ".supabase", "stack-state-locks");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Derive state-lock storage from the configured root

When $HOME is read-only or unavailable but the caller supplies a writable cacheRoot/state root, every detached state write or removal now attempts to create ~/.supabase/stack-state-locks and defects before touching the configured storage. This breaks daemon registration in container and system-service environments that intentionally redirect all writable state away from the home directory; derive the private lock directory from the corresponding configured state/runtime root instead.

Useful? React with 👍 / 👎.

Comment on lines +426 to +427
sseStream<LogEntry>(socketPath, `/logs/${encodeURIComponent(name)}`, (data) =>
decodeLogEntryEvent(data),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Reject dot-only names before building log URLs

In detached Bun mode, subscribeLogs("..") and logHistory("..") still do not address the dot-segment case because encodeURIComponent("..") remains ..; the Bun client constructs a fetch() URL that normalizes these paths to / or /history, so the methods die on an unmatched-route response instead of streaming or returning the literal service's empty log set as the foreground implementation does. Validate dot-only segments or use a transport that does not embed arbitrary log names in URL paths.

Useful? React with 👍 / 👎.

// A daemon generation owns its socket pathname for its entire lifetime.
// Reusing a fixed pathname lets a delayed shutdown unlink a replacement
// daemon's socket after the replacement has already bound it.
const socketPath = join(runtimeDir, `daemon-${randomUUID().slice(0, 12)}.sock`);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Remove the obsolete fixed socket-path API

After this switches each daemon to daemon-<generation>.sock, the exported Effect API StateManager.socketPath(name) still returns <runtimeDir>/daemon.sock, and the detach-mode documentation and state example advertise that same fixed pathname. Any Effect consumer using the path helper now receives a socket that no daemon binds; remove or reshape the inaccurate helper and update the socket lifecycle documentation to direct consumers to the persisted generation-owned StackState.socketPath.

AGENTS.md reference: AGENTS.md:L124-L126

Useful? React with 👍 / 👎.

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