Skip to content

feat: bind Decision OS lanes to the canonical review store (dos-3ndcm) - #1883

Closed
Authentis wants to merge 2 commits into
kunchenguid:mainfrom
Authentis:fm/fm-dos-3ndcm-canonical-review-store
Closed

Authentis wants to merge 2 commits into
kunchenguid:mainfrom
Authentis:fm/fm-dos-3ndcm-canonical-review-store

Conversation

@Authentis

Copy link
Copy Markdown
Contributor

Intent

Implement Decision OS bead dos-3ndcm so every Firstmate-launched Decision OS Treehouse lane writes review evidence directly into the canonical shared data/local/reviews store. Use the canonical project path already owned by Firstmate lane allocation and bind the lane before worker launch; refuse ambiguous or wrong-project paths, missing or non-directory canonical destinations, and any conflicting real lane review directory that may contain evidence, without overwriting or hiding evidence. Preserve all behavior for projects that do not expose the Decision OS review-store symlink contract. Add public-interface regressions for clean setup, idempotent repeat, a pre-existing correct link, conflicting evidence, wrong or missing canonical target, and non-Decision-OS work. Provide the narrowest guarded one-time migration owned by Firstmate: inventory every pool copy, detect active or changing runs including rechecking activity before source retirement, copy first, verify exact path/type/byte completeness and SHA-256 manifests, refuse non-identical collisions, remove sources only after durable verification, and resume safely after interruption. Do not run the real migration during implementation or validation; report the exact guarded command and read-only preflight evidence for Firstmate to execute only after the code lands. Do not modify Decision OS project files, prune branches, broadly clean pool slots, or alter unrelated Firstmate behavior. Validate relevant backend and Treehouse behavior, pinned ShellCheck lint, documentation audiences, tests, and CI. Create a green pull request whose title contains dos-3ndcm. Delivery remains incomplete after merge: Firstmate separately owns executing the migration, verifying canonical gate visibility and reclaimability, appending the Closure-Receipt, closing dos-3ndcm, and landing that tracker close in the same shift.

What Changed

  • bin/fm-spawn.sh now binds every Decision OS Treehouse lane to the canonical shared data/local/reviews store before worker launch (symlink via the lane's canonical project path), refusing wrong-project or ambiguous paths, missing/non-directory canonical targets, and any conflicting real lane reviews directory that could hold evidence; projects without the Decision OS review-store symlink contract are untouched.
  • Added bin/fm-decision-os-review-migrate.sh, a guarded one-time migration for existing pool copies: dry-run inventory by default, defers in-use or process-bearing slots (with an activity recheck before source retirement, including the empty/missing-reviews branches per the review pass), copy-first with exact path/type/byte and SHA-256 manifest verification, refuses non-identical collisions, removes sources only after durable verification, and resumes safely after interruption. The real migration was not run; it remains a separate guarded --apply step.
  • Added regression suites tests/fm-spawn-decision-os-reviews.test.sh (5 cases) and tests/fm-decision-os-review-migrate.test.sh (8 cases), wired into bin/fm-test-run.sh, plus a docs/scripts.md entry for the migration script.

Risk Assessment

✅ Low: The follow-up commit precisely implements the requested guard — active slots are deferred before any review-path mutation, link failures degrade to per-slot refusals instead of set -e aborts, and a new public-interface regression proves --apply leaves in-use slots untouched — with no unrelated behavior changes and all prior concerns either fixed or explicitly waived.

Testing

Ran both new regression suites (13 tests, all passing) and a manual end-to-end demo driving the real fm-spawn and migration scripts against fixture Decision OS projects; the transcript shows lane evidence landing in the canonical shared store, fail-closed refusals that preserve evidence, unchanged behavior for non-contract projects, a verified mutation-free preflight, and a fixture-only guarded apply — the real migration was not executed, matching the intent's constraint.

Evidence: End-to-end CLI transcript: spawn binding, refusals, preflight, and fixture apply

=== PART A: fm-spawn binds a Decision OS lane to the canonical review store ===
-- canonical project exposes the review-store symlink contract:
$ ls -l /tmp/dos-3ndcm-demo.WdrMrO/a/decision-os/data/local
total 0
lrwxrwxrwx 1 holu holu 8 Aug  7 12:28 reviews -> .reviews
(exit 0)
-- launching a Treehouse lane via the real fm-spawn.sh:
spawn exit: 0 (full log tail below)
warning: /tmp/dos-3ndcm-demo.WdrMrO/a/home/data/demoa1/brief.md records no delivery contract line (scaffolded before ship briefs recorded one); launching on the explicit --mode no-mistakes - confirm its definition of done matches
spawned demoa1 harness=codex kind=ship mode=no-mistakes yolo=off window=firstmate:fm-demoa1 worktree=/tmp/dos-3ndcm-demo.WdrMrO/a/lane
-- lane's data/local/reviews after spawn (bound before worker launch):
$ ls -l /tmp/dos-3ndcm-demo.WdrMrO/a/lane/data/local
total 0
lrwxrwxrwx 1 holu holu 59 Aug  7 12:28 reviews -> /tmp/dos-3ndcm-demo.WdrMrO/a/decision-os/data/local/reviews
(exit 0)
-- a worker writing evidence through the LANE path...
-- ...lands in the CANONICAL shared store (read via the project path):
$ ls -l /tmp/dos-3ndcm-demo.WdrMrO/a/decision-os/data/local/.reviews
total 8
-rw-rw-r-- 1 holu holu 31 Aug  7 12:28 lane-review.md
-rw-rw-r-- 1 holu holu 27 Aug  7 12:28 prior-review.md
(exit 0)
$ cat /tmp/dos-3ndcm-demo.WdrMrO/a/decision-os/data/local/.reviews/lane-review.md
evidence written from the lane
(exit 0)

=== PART B: conflicting real lane review directory refuses without hiding evidence ===
-- spawn against a lane that already has a real reviews dir with evidence:
spawn exit: 1 (refusal expected)
error: Decision OS lane review path already exists and could contain evidence: /tmp/dos-3ndcm-demo.WdrMrO/b/lane/data/local/reviews; refusing to overwrite or hide it
-- stranded evidence is untouched:
$ cat /tmp/dos-3ndcm-demo.WdrMrO/b/lane/data/local/reviews/stranded.md
stranded evidence must not vanish
(exit 0)

=== PART C: non-Decision-OS project (no symlink contract) is unchanged ===
spawn exit: 0
-- lane data/local after spawn (no reviews link created):
ls: cannot access '/tmp/dos-3ndcm-demo.WdrMrO/c/lane/data/local': No such file or directory
(no data/local at all — historical behavior preserved)

=== PART D: guarded migration — read-only preflight on a fixture pool ===
-- read-only preflight (the exact command Firstmate runs, minus --apply):
$ fm-decision-os-review-migrate.sh /tmp/dos-3ndcm-demo.WdrMrO/m/decision-os
INVENTORY slot=1 run=run-2026-08-01 entries=2 hash=75e86ae7d28e7d32762bb6ac8763af236197b980d1ed475223d5be87281666c5
WOULD-MIGRATE slot=1 run=run-2026-08-01
EMPTY slot=2 path=/tmp/dos-3ndcm-demo.WdrMrO/m/pool/2/decision-os/data/local/reviews
PREFLIGHT complete: no files copied, removed, or linked
(exit 0)
-- verified: preflight mutated nothing (pool content hash identical before/after)

=== PART E: guarded --apply on the same fixture (never the real pool) ===
$ fm-decision-os-review-migrate.sh --apply /tmp/dos-3ndcm-demo.WdrMrO/m/decision-os
INVENTORY slot=1 run=run-2026-08-01 entries=2 hash=75e86ae7d28e7d32762bb6ac8763af236197b980d1ed475223d5be87281666c5
COPIED slot=1 run=run-2026-08-01 hash=75e86ae7d28e7d32762bb6ac8763af236197b980d1ed475223d5be87281666c5
VERIFIED slot=1 run=run-2026-08-01 hash=75e86ae7d28e7d32762bb6ac8763af236197b980d1ed475223d5be87281666c5
REMOVED slot=1 run=run-2026-08-01 source=/tmp/dos-3ndcm-demo.WdrMrO/m/pool/1/decision-os/data/local/reviews/run-2026-08-01
LINKED slot=1 target=/tmp/dos-3ndcm-demo.WdrMrO/m/decision-os/data/local/reviews
EMPTY slot=2 path=/tmp/dos-3ndcm-demo.WdrMrO/m/pool/2/decision-os/data/local/reviews
DEFER active slot=2 path=/tmp/dos-3ndcm-demo.WdrMrO/m/pool/2/decision-os/data/local/reviews status=in-use processes=1
APPLY complete: active or changing runs, if any, remain deferred
(exit 0)
-- evidence now in the canonical store; drained slot re-linked; active slot 2 deferred:
$ ls -l /tmp/dos-3ndcm-demo.WdrMrO/m/decision-os/data/local/.reviews
total 4
drwxrwxr-x 2 holu holu 4096 Aug  7 12:28 run-2026-08-01
(exit 0)
$ cat /tmp/dos-3ndcm-demo.WdrMrO/m/decision-os/data/local/.reviews/run-2026-08-01/review.md
stranded pool evidence
(exit 0)
$ ls -l /tmp/dos-3ndcm-demo.WdrMrO/m/pool/1/decision-os/data/local
total 0
lrwxrwxrwx 1 holu holu 59 Aug  7 12:28 reviews -> /tmp/dos-3ndcm-demo.WdrMrO/m/decision-os/data/local/reviews
(exit 0)

=== demo complete ===
Evidence: Demo script that produced the transcript (fixture-only, real scripts)
#!/usr/bin/env bash
# End-to-end demo of the dos-3ndcm canonical review-store change, run against
# fixture projects (never the real Decision OS checkout or real Treehouse pool).
set -u
ROOT=${1:?repo root}
DEMO=$(mktemp -d /tmp/dos-3ndcm-demo.XXXXXX)
trap 'rm -rf "$DEMO"' EXIT

say() { printf '\n=== %s ===\n' "$*"; }
run() { printf '$ %s\n' "$*"; "$@" 2>&1; printf '(exit %s)\n' "$?"; }

mk_fakebin() {
  local fb="$1"; mkdir -p "$fb"
  cat > "$fb/tmux" <<'SH'
#!/usr/bin/env bash
set -u
case "$*" in *"#{pane_current_path}"*) printf '%s\n' "${FM_FAKE_PANE_PATH:?}"; exit 0 ;; esac
case "${1:-}" in display-message) printf 'firstmate\n'; exit 0 ;; esac
exit 0
SH
  cat > "$fb/treehouse" <<'SH'
#!/usr/bin/env bash
set -u
if [ "${1:-}" = status ] && [ "${2:-}" = --json ]; then cat "${FM_MIGRATION_POOL_JSON:?}"; exit 0; fi
exit 0
SH
  cat > "$fb/sleep" <<'SH'
#!/usr/bin/env bash
exit 0
SH
  chmod +x "$fb"/tmux "$fb"/treehouse "$fb"/sleep
}

mk_home() {
  local home="$1" id="$2"
  mkdir -p "$home/data/$id" "$home/projects" "$home/state" "$home/config"
  printf 'codex\n' > "$home/config/crew-harness"
  printf 'brief for %s\n' "$id" > "$home/data/$id/brief.md"
  touch "$home/state/.last-watcher-beat"
}

mk_project() {  # <repo> <lane> <branch>
  local repo="$1" lane="$2" branch="$3"
  mkdir -p "$repo"
  git -C "$repo" init -q -b main
  git -C "$repo" -c user.email=demo@example.com -c user.name=demo commit -q --allow-empty -m init
  git -C "$repo" worktree add --quiet -b "$branch" "$lane"
}

spawn() {  # <home> <lane> <fakebin> <id> <project>
  FM_GATE_REFUSE_BYPASS=1 FM_ROOT_OVERRIDE='' FM_HOME="$1" \
    FM_STATE_OVERRIDE="$1/state" FM_DATA_OVERRIDE="$1/data" \
    FM_PROJECTS_OVERRIDE="$1/projects" FM_CONFIG_OVERRIDE="$1/config" \
    FM_SPAWN_NO_GUARD=1 TMUX="fake,1,0" FM_FAKE_PANE_PATH="$2" \
    PATH="$3:$PATH" \
    "$ROOT/bin/fm-spawn.sh" "$4" "$5" --mode no-mistakes --yolo off
}

FB="$DEMO/fakebin"; mk_fakebin "$FB"

say "PART A: fm-spawn binds a Decision OS lane to the canonical review store"
A="$DEMO/a"; mk_home "$A/home" demoa1
mk_project "$A/decision-os" "$A/lane" lane-a
mkdir -p "$A/decision-os/data/local/.reviews"
ln -s .reviews "$A/decision-os/data/local/reviews"
printf 'earlier canonical evidence\n' > "$A/decision-os/data/local/.reviews/prior-review.md"
echo "-- canonical project exposes the review-store symlink contract:"
run ls -l "$A/decision-os/data/local"
echo "-- launching a Treehouse lane via the real fm-spawn.sh:"
spawn "$A/home" "$A/lane" "$FB" demoa1 "$A/decision-os" >"$DEMO/spawn-a.log" 2>&1
echo "spawn exit: $? (full log tail below)"
tail -3 "$DEMO/spawn-a.log"
echo "-- lane's data/local/reviews after spawn (bound before worker launch):"
run ls -l "$A/lane/data/local"
echo "-- a worker writing evidence through the LANE path..."
printf 'evidence written from the lane\n' > "$A/lane/data/local/reviews/lane-review.md"
echo "-- ...lands in the CANONICAL shared store (read via the project path):"
run ls -l "$A/decision-os/data/local/.reviews"
run cat "$A/decision-os/data/local/.reviews/lane-review.md"

say "PART B: conflicting real lane review directory refuses without hiding evidence"
B="$DEMO/b"; mk_home "$B/home" demob2
mk_project "$B/decision-os" "$B/lane" lane-b
mkdir -p "$B/decision-os/data/local/.reviews"
ln -s .reviews "$B/decision-os/data/local/reviews"
mkdir -p "$B/lane/data/local/reviews"
printf 'stranded evidence must not vanish\n' > "$B/lane/data/local/reviews/stranded.md"
echo "-- spawn against a lane that already has a real reviews dir with evidence:"
spawn "$B/home" "$B/lane" "$FB" demob2 "$B/decision-os" >"$DEMO/spawn-b.log" 2>&1
echo "spawn exit: $? (refusal expected)"
grep -i 'error:' "$DEMO/spawn-b.log"
echo "-- stranded evidence is untouched:"
run cat "$B/lane/data/local/reviews/stranded.md"

say "PART C: non-Decision-OS project (no symlink contract) is unchanged"
C="$DEMO/c"; mk_home "$C/home" democ3
mk_project "$C/plainproj" "$C/lane" lane-c
spawn "$C/home" "$C/lane" "$FB" democ3 "$C/plainproj" >"$DEMO/spawn-c.log" 2>&1
echo "spawn exit: $?"
echo "-- lane data/local after spawn (no reviews link created):"
ls -la "$C/lane/data/local" 2>&1 || echo "(no data/local at all — historical behavior preserved)"

say "PART D: guarded migration — read-only preflight on a fixture pool"
M="$DEMO/m"
mk_project "$M/decision-os" "$M/pool/1/decision-os" slot-1
git -C "$M/decision-os" worktree add --quiet -b slot-2 "$M/pool/2/decision-os"
mkdir -p "$M/decision-os/data/local/.reviews"
ln -s .reviews "$M/decision-os/data/local/reviews"
mkdir -p "$M/pool/1/decision-os/data/local/reviews/run-2026-08-01"
printf 'stranded pool evidence\n' > "$M/pool/1/decision-os/data/local/reviews/run-2026-08-01/review.md"
POOL_JSON="$M/pool.json"
jq -n --arg p1 "$M/pool/1/decision-os" --arg p2 "$M/pool/2/decision-os" \
  '[{name:"1",path:$p1,status:"available",processes:[]},
    {name:"2",path:$p2,status:"in-use",processes:[{"pid":456,"name":"worker"}]}]' > "$POOL_JSON"
BEFORE=$(find "$M/pool" -type f | sort | xargs sha256sum | sha256sum)
echo "-- read-only preflight (the exact command Firstmate runs, minus --apply):"
printf '$ fm-decision-os-review-migrate.sh %s\n' "$M/decision-os"
FM_MIGRATION_POOL_JSON="$POOL_JSON" PATH="$FB:$PATH" \
  "$ROOT/bin/fm-decision-os-review-migrate.sh" "$M/decision-os" 2>&1
echo "(exit $?)"
AFTER=$(find "$M/pool" -type f | sort | xargs sha256sum | sha256sum)
if [ "$BEFORE" = "$AFTER" ]; then
  echo "-- verified: preflight mutated nothing (pool content hash identical before/after)"
else
  echo "-- FAILURE: preflight mutated pool contents"; exit 1
fi

say "PART E: guarded --apply on the same fixture (never the real pool)"
printf '$ fm-decision-os-review-migrate.sh --apply %s\n' "$M/decision-os"
FM_MIGRATION_POOL_JSON="$POOL_JSON" PATH="$FB:$PATH" \
  "$ROOT/bin/fm-decision-os-review-migrate.sh" --apply "$M/decision-os" 2>&1
echo "(exit $?)"
echo "-- evidence now in the canonical store; drained slot re-linked; active slot 2 deferred:"
run ls -l "$M/decision-os/data/local/.reviews"
run cat "$M/decision-os/data/local/.reviews/run-2026-08-01/review.md"
run ls -l "$M/pool/1/decision-os/data/local"

say "demo complete"
Evidence: Key transcript excerpt: lane write-through and guarded apply
$ ls -l a/lane/data/local
reviews -> a/decision-os/data/local/reviews
$ cat a/decision-os/data/local/.reviews/lane-review.md
evidence written from the lane

(conflicting lane dir) error: Decision OS lane review path already exists and could contain evidence: b/lane/data/local/reviews; refusing to overwrite or hide it
$ cat b/lane/data/local/reviews/stranded.md
stranded evidence must not vanish

$ fm-decision-os-review-migrate.sh <project> # read-only preflight
INVENTORY slot=1 run=run-2026-08-01 entries=2 hash=75e86ae7...
WOULD-MIGRATE slot=1 run=run-2026-08-01
PREFLIGHT complete: no files copied, removed, or linked
-- verified: preflight mutated nothing (pool content hash identical before/after)

$ fm-decision-os-review-migrate.sh --apply <project> # fixture pool only
COPIED → VERIFIED → REMOVED → LINKED slot=1; DEFER active slot=2 status=in-use processes=1

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 3 issues found → auto-fixed ✅
  • ⚠️ bin/fm-decision-os-review-migrate.sh:245 - Under --apply, the reviews-path-missing branch (lines 243–250) and empty-reviews-dir branch (lines 266–274) execute mkdir/rmdir/ln -s before the slot activity check at line 278, so an in-use, process-bearing slot with a missing or empty reviews directory is mutated while its worker runs. This contradicts the script's own header contract ('Apply defers every in-use or process-bearing slot'), and because rmdir/ln -s are unguarded under set -eu, a racing worker that recreates or populates the directory between the check and the mutation aborts the entire migration mid-run. No evidence can be destroyed (only empty/absent directories are touched), but the deferral invariant and whole-run robustness are compromised. Fix: gate the LINKED action in both branches on the same status==available && processes==0 condition (or a slot_still_available recheck), and guard the rmdir/ln failures as a per-slot REFUSE instead of a set -e abort.
  • ℹ️ bin/fm-decision-os-review-migrate.sh:195 - Successful migration leaves empty residue directories behind: the staging tree $PROJECT/data/local/.dos-3ndcm-review-migration/<slot>/<run_key>/ (stage entries are moved out but parents never removed, and STAGE_ROOT is never cleaned at exit) and per-slot $slot/data/local/.dos-3ndcm-review-migrated/<run>/ parents after rm -rf of the hash-keyed leaf. Harmless to correctness, but visible clutter during Firstmate's later canonical-visibility and reclaimability verification.
  • ℹ️ bin/fm-spawn.sh:1500 - bind_project_review_store creates the lane symlink data/local/reviews without adding it to git info/exclude, unlike other spawn-created worktree artifacts that use the exclude_path helper (defined later at line 1980). If the target project does not gitignore data/, the lane worktree gains untracked state that could trip teardown's dirty checks or leak into a worker commit. Likely moot because the Decision OS contract presumes data/local is local-only (a tracked symlink would resolve lane-locally and refuse every spawn), but excluding it would be cheap hardening.

🔧 Fix: guard empty-lane review linking behind slot activity check
✅ Re-checked - no issues remain.

✅ **Test** - passed

✅ No issues found.

  • bash tests/fm-spawn-decision-os-reviews.test.sh — all 5 public-interface regressions pass (clean setup + idempotent repeat, pre-existing correct link, conflicting evidence refusal, missing/wrong canonical target refusal, non-Decision-OS unchanged)
  • bash tests/fm-decision-os-review-migrate.test.sh — all 8 migration-guard regressions pass (dry-run inventory, active-lane deferral, activity recheck before retirement, copy/verify/remove/link idempotent apply, non-identical collision refusal, changing-source deferral, interrupted-copy resume, wrong-project/invalid-store refusal)
  • Manual end-to-end demo (e2e-demo.sh) running the real bin/fm-spawn.sh and bin/fm-decision-os-review-migrate.sh against fixture git worktrees: lane review link created before launch, write-through of lane evidence into the canonical store, refusal transcript for a conflicting lane reviews directory with evidence left intact, non-Decision-OS project untouched, read-only preflight verified mutation-free via before/after content hashing, and a fixture-only guarded --apply showing INVENTORY→COPIED→VERIFIED→REMOVED→LINKED with the in-use slot deferred
✅ **Document** - passed

✅ No issues found.

⚠️ **Lint** - 1 warning
  • ⚠️ linter found issues (exit code 127)
✅ **Push** - passed

✅ No issues found.

@Authentis Authentis closed this Aug 7, 2026

@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: b4730c26be

ℹ️ 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".

echo "error: staged copy changed after sync for slot=$slot run=$run; source preserved" >&2
exit 1
fi
mv -n "$stage_entry" "$destination"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Publish to the exact destination path

Captain, if another process creates $destination as a directory after the existence check, the mv --help SOURCE... DIRECTORY form means this command moves the staged entry to $destination/item rather than leaving it unpublished; -n only prevents overwriting an existing file. The subsequent check sees $stage_entry gone and reports COPIED, so this collision mutates the canonical run before later verification merely defers source cleanup. Use an atomic no-replace operation that treats $destination as the exact target path.

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