Skip to content

insert edit text mvp - #54

Merged
ataibarkai merged 6 commits into
mainfrom
atai/0831/insertText
Oct 12, 2023
Merged

ataibarkai merged 6 commits into
mainfrom
atai/0831/insertText

Conversation

@ataibarkai

Copy link
Copy Markdown
Contributor

No description provided.

@ataibarkai
ataibarkai enabled auto-merge October 12, 2023 00:54
@ataibarkai
ataibarkai merged commit f04fcf3 into main Oct 12, 2023
@ataibarkai
ataibarkai deleted the atai/0831/insertText branch October 12, 2023 00:55
jpr5 added a commit that referenced this pull request Jun 18, 2026
…0 reservation, bin/showcase slots) (#5543)

## Summary

Fixes the `--isolate` slot picker in `showcase/scripts/cli/_common.sh`
and adds a new `bin/showcase slots` inspector subcommand. Resolves five
compounding bugs that made multi-agent local testing unreliable.

## Bugs fixed

1. **`SHOWCASE_ISO_SLOT=<N>` env var was ignored.** The picker walked
0→N regardless. Now: validates input (positive integer, `1 ≤ N ≤ 45`,
slot 0 rejected as base stack), tries exactly that slot, fails loudly on
conflict.
2. **No port-probe before commit.** Picker `mkdir`'d a slot dir without
checking whether the slot's host ports were free. A slot whose dir was
absent but whose ports were taken (foreign Docker project, host service
like macOS AirPlay on 5000) was picked then failed at `docker compose
up`. Now: `lsof`-probe every candidate port before committing the claim;
rmdir + try next on conflict.
3. **Slot 8 / port 5000 collision on macOS.** Base dashboard port `3200`
+ slot 8 offset `+1800` = `5000`, permanently bound by macOS Control
Center's AirPlay Receiver. Shifted dashboard base port `3200 → 3210`
across `docker-compose.local.yml` and `showcase/harness/src/cli/*.ts` so
slot 8 → port `5010` (free).
4. **Slot ownership desync across 3+ independent owners.** Picker
checked only the dir; sweeper checked dir+pid+containers; neither
checked foreign ports. New unified `_slot_state` returns all 4 axes
(dir/pid/liveness/ports/offset/project); new `bin/showcase slots`
exposes the state via table / `--json` / `--free --brief` filters.
5. **Parallel pre-claim deadlock dissolved** by bugs 1+2+4 — per-session
pinning via env var + accurate port-probe + atomic `mkdir` lock
self-resolves contention.

## Implementation

- New helpers in `_common.sh`: `_slot_offset_ports`, `_slot_liveness`
(extracted from sweeper), `_slot_ports_free` (with own-project
docker-listener filter), `_slot_state` (composite axis report).
- Rewritten `_claim_isolate_slot`: pinned-path (validate / try / die
loudly) and auto-pick-path (1..MAX_SLOT, rmdir + skip on port-held).
Slot 0 reserved with explicit die message.
- `ISOLATE_MAX_SLOT=45` centralized as a constant.
- Dashboard host port shift `3200 → 3210` across 6 files (compose + 4
harness TS + comment updates).
- New `cmd-slots.sh` plugin (auto-discovered by `bin/showcase`): default
table, `--json` (JSONL), `--free` (filter to claimable slots), `--brief`
(numeric IDs only).

## Tests

**Bats — 54/54 GREEN** in `showcase/scripts/__tests__/isolate.bats`:

- 12 pre-existing tests updated for slot-0-reservation contract
(reap-evidence assertions preserved; only slot-number / port-offset
expectations updated).
- 11 new tests added:
  - lsof stub + foundation smoke (test #0)
- Pinning behavior tests #1-3 (success, live-die, validation incl.
0/foo/99)
- Port-probe tests #4-7 (stale-reap, `_slot_offset_ports 8 → 5010 ≠
5000`, foreign-process skip, own-project no-skip)
- Composite tests #8-10 (`_slot_state` 5 axes, `bin/showcase slots`
output, concurrent claim distinct slots)
- lsof-graceful test (#54): `_slot_state emits ports=? when lsof is
unavailable`

**Vitest — 17/17 GREEN** in
`showcase/harness/src/cli/control-plane-run.test.ts` (port-shift stub
consistency).

**Value-test (live local, plan §6 scenarios) — all 3 PASS:**

- **Scenario A:** On the test host Docker was holding slot 9's ports, so
the picker correctly REFUSED `SHOWCASE_ISO_SLOT=9` with per-port
diagnostics (proving the fail-loud half of the contract). Re-ran with
`SHOWCASE_ISO_SLOT=15` (first free slot) and the pin was honored
cleanly: `ISOLATE_SLOT=15`, `OFFSET=3200`. Both halves of the pin
contract verified.
- **Scenario B:** Slots 1-7 pre-occupied with live pids + Python
listener on `127.0.0.1:5010` (slot 8's dashboard port) → picker logged
"Slot N ports held" + "trying next" for each conflict, walked past 9..13
(Docker-held), and landed on slot 14 with `OFFSET=3000`. No silent
collision.
- **Scenario C:** `bin/showcase slots` matches reality: slot 0 →
`OFFSET=+0 PROJECT=showcase (base)`; pre-claimed slot 5 → `DIR=present
PID=<pid> LIVE=live PORTS=held OFFSET=+1200 PROJECT=showcase-iso5-test`.
`--free --brief` outputs only fully-claimable slot IDs (44 in this run,
slot 5 excluded).

## Code review

Full 7-agent cr-loop with `pr-review-toolkit` reviewers (Round 1 +
confirmation round). 4 subject-scope load-bearing findings fixed:
- `_reap_isolate_slot` arg shape in pinned-path retry
- `_slot_state` base-stack offset (slot 0 → `+0`, not `+200`)
- TESTING.md item 8/9 column-name accuracy (matches actual `SLOT DIR PID
LIVE PORTS OFFSET PROJECT` header)
- `bin/showcase slots` lsof-graceful degradation (inspector reports
`PORTS=?` instead of dying when `lsof` is missing)

Plus 1 trivial comment-phrasing fix (race-comment wording). ~50
pre-existing harness/compose findings partitioned out-of-subject and
deferred to follow-up PRs (see below). Procedure 3 bucket-(c) promotion
audit returned zero PROMOTE_TO_A items — full convergence.

## Follow-up PRs (out-of-subject, separate subjects)

These coherent subjects surfaced during CR but belong to distinct PRs
(the diff merely brushed against them for the `3200→3210` shift):

- **d1** — Harness `up()` / `doctor` should health-check
`harness-control-plane` (port 8081). `_slot_offset_ports` includes 8081;
`INFRA_PORTS` in `doctor.ts` / `lifecycle.ts` does not.
- **d2** — `doctor.ts` port + image diagnostic loud-failure pass
(`checkStaleImages`, `checkPorts`, `isPortListening`,
`checkDepotInterception` swallow errors).
- **d3** — `lifecycle.ts` error-surfacing pass (broad catches in
`loadPortsFile`, `isRunning`, `compose`, `healthCheck`, `diffLogs`,
etc.).
- **d4** — `docker-compose.local.yml` healthcheck error visibility
(`.catch(() => process.exit(1))` swallows; dashboard `/` returns 307).
- **d5** — `apply_isolation` Python rewriter fail-loud pass (no
`re.subn` count checks, hand-rolled YAML demos parser).
- **d6** — Centralize infra port literals (currently duplicated in 4
places).
- **d7** — `lifecycle.ts:11-13` stale `ops/` path comment (file lives at
`harness/`).
- **d8** — `cmd_slots --json` `pid` field typing (string vs number) —
settle when first JSON consumer appears.

## Test plan

- [x] `bats showcase/scripts/__tests__/isolate.bats` → 54/0
- [x] `pnpm vitest run src/cli/control-plane-run.test.ts` (in
`showcase/harness/`) → 17/0
- [x] `pnpm exec tsc --noEmit` (in `showcase/harness/`) → clean
- [x] `oxfmt --check showcase/` → clean
- [x] `docker compose -f showcase/docker-compose.local.yml config` →
valid YAML
- [x] Local value-test scenarios A/B/C from plan §6 → PASS
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