Skip to content

Commit 8105ac0

Browse files
Ignore idle shells during state capture
1 parent 6d03045 commit 8105ac0

2 files changed

Lines changed: 44 additions & 2 deletions

File tree

‎scripts/ulysses-deploy‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,21 @@ def source_contract(source_root: Path) -> dict:
183183

184184

185185
def _active_production_pids(production_root: Path) -> list[int]:
186-
"""Find this user's processes whose cwd or command references production."""
186+
"""Find application processes that can mutate production state.
187+
188+
An authenticated shell may remain parked in the production directory after
189+
the server stops. Its cwd alone is not a writer and must not block cutover.
190+
Match known Odysseus launch/child-process markers as well as the checkout
191+
path so Uvicorn and bundled MCP children remain a hard gate.
192+
"""
187193
root = str(production_root.resolve())
194+
app_markers = (
195+
"uvicorn",
196+
"gunicorn",
197+
"launcher.py",
198+
"app.py",
199+
"mcp_servers/",
200+
)
188201
found: set[int] = set()
189202
proc_root = Path("/proc")
190203
if not proc_root.is_dir():
@@ -200,7 +213,8 @@ def _active_production_pids(production_root: Path) -> list[int]:
200213
)
201214
except (FileNotFoundError, PermissionError, ProcessLookupError, OSError):
202215
continue
203-
if cwd == root or cwd.startswith(root + os.sep) or root in cmdline:
216+
references_root = cwd == root or cwd.startswith(root + os.sep) or root in cmdline
217+
if references_root and any(marker in cmdline for marker in app_markers):
204218
found.add(pid)
205219
return sorted(found)
206220

‎tests/test_ulysses_deploy.py‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,34 @@ def test_capture_refuses_running_production_by_default(tmp_path, monkeypatch):
133133
)
134134

135135

136+
def test_active_process_probe_ignores_shell_parked_in_production(tmp_path, monkeypatch):
137+
deploy = _load()
138+
production = tmp_path / "odysseus"
139+
production.mkdir()
140+
proc = tmp_path / "proc"
141+
shell = proc / "100"
142+
server = proc / "101"
143+
shell.mkdir(parents=True)
144+
server.mkdir(parents=True)
145+
os.symlink(production, shell / "cwd")
146+
os.symlink(production, server / "cwd")
147+
(shell / "cmdline").write_bytes(b"-bash\0")
148+
(server / "cmdline").write_bytes(b"python\0-m\0uvicorn\0app:app\0")
149+
150+
original_path = deploy.Path
151+
152+
# Keep the production path real while redirecting only the module's /proc
153+
# lookup through a narrow wrapper.
154+
class PathProxy:
155+
def __new__(cls, value):
156+
if value == "/proc":
157+
return proc
158+
return original_path(value)
159+
160+
monkeypatch.setattr(deploy, "Path", PathProxy)
161+
assert deploy._active_production_pids(production) == [101]
162+
163+
136164
def test_prepare_is_clean_disposable_clone_and_attaches_state(tmp_path):
137165
deploy = _load()
138166
source = tmp_path / "Ulysses"

0 commit comments

Comments
 (0)