Skip to content

v1.92.69.0 fix: lock developer-profile writers so overlapping derives keep every session (#3437, #3435) - #3738

Merged
capy-ai[bot] merged 10 commits into
mainfrom
garrytan/gsta216-plan-tune-profile-lock
Nov 2, 2026
Merged

capy-ai[bot] merged 10 commits into
mainfrom
garrytan/gsta216-plan-tune-profile-lock

Conversation

@garrytan

@garrytan garrytan commented Oct 31, 2026 •

Copy link
Copy Markdown
Owner
{
  "schema_version": 1,
  "pr": 3738,
  "head": "022210eed20110ad89e7d5685bdb20ae3a8cff5e",
  "version": "1.91.378.0",
  "base": "main",
  "gate": {
    "focused": {
      "pass": 157,
      "fail": 0,
      "skip": 0
    }
  },
  "session_kind": "unattended",
  "head_tree": "47fa1a2dd585fcc604de19eb0756e1c720cf0b4e",
  "product_patch_id": "9b102ac5adc19a958a0a93c703dd6dfd13dafa86",
  "gstack_version": "1.91.378.0",
  "review_depth": {
    "depth": "full",
    "class": "gate",
    "runtime_lines": 180,
    "rules": "150435b0a543019a",
    "base": "2d1b55d7621df1a71e02037c79b63b7ee2fdc64f",
    "registry": "2d1b55d7621df1a71e02037c79b63b7ee2fdc64f",
    "gate_scan": {
      "tagged": 1,
      "head": "022210eed20110ad89e7d5685bdb20ae3a8cff5e"
    },
    "reasons": [
      "gate-class",
      "runtime=180>50"
    ]
  },
  "pregate": "requires-remote cleared @47fa1a2dd585 (1 checks, current for 022210eed201)",
  "requires_remote": [
    "free-tests.yml/macos-named-regressions: https://github.com/garrytan/gstack/actions/runs/41237822717",
    "windows-free-tests.yml/windows-free-shard: https://github.com/garrytan/gstack/actions/runs/41237822659",
    "pregate.json/remote_gate: remote-gate tree=47fa1a2dd585 tests=3851"
  ],
  "issues": {
    "fixes": [
      3435,
      3437
    ],
    "refs": [],
    "flakes": []
  },
  "docs": {
    "status": "blocked",
    "scope": "docs/, README.md, AGENTS.md, CLAUDE.md, CONTRIBUTING.md, plan-tune/, office-hours/ templates; changelog.d fragment reviewed",
    "exception": {
      "accepted_by": "GStack Minder (Captain)",
      "date": "2026-10-31",
      "via": "GSTA-216 Captain reply: Do it: docs risk accepted",
      "reason": "Docs audit gsta216-docs-2 covered the diff before 022210e; the only later change is a one-line test type fix that no doc references."
    }
  },
  "review_loop": {
    "passes": 2,
    "blocking_found": 1,
    "deferred": 0,
    "noted": 7,
    "fixed": 6,
    "scope": "frozen",
    "fix_checks": 4,
    "dispatches": {
      "specialist": 6
    }
  },
  "review_targeted": {
    "classes": [
      "gate",
      "secret"
    ],
    "rules": "baeb8f7ef7da92d0",
    "brief_sha": "7f92a0d0a8319c3c0e076fb3b1a4689c45120b2be2c14dfc7d4cb03aafa9d6a5",
    "product_patch_id": "9b102ac5adc19a958a0a93c703dd6dfd13dafa86",
    "status": "done",
    "findings": 0,
    "raised_by": "targeted"
  }
}

What changed

Overlapping background --derive runs no longer drop /office-hours sessions or fail with ENOENT (#3437). gstack-question-log starts a background gstack-developer-profile --derive after every append, and a multi-question AskUserQuestion logs several rows at once. Every derive wrote the same fixed developer-profile.json.tmp and rewrote the profile without a lock.

  • --derive, --log-session, --reconcile and --migrate now hold developer-profile.json.lock from before they read the profile until after the rename, and each writes its own mktemp file.
  • The owner file names the holder's pid; release is ownership-checked. A lock is taken over when its holder is gone, or once it is 5 minutes old whatever the pid says (pid reuse). Takeovers are serialized under developer-profile.json.lock.takeover, and interrupt cleanup removes a takeover dir the process holds.
  • A writer that can't get the lock in 10 seconds writes nothing and exits 5; an unwritable state dir fails fast. A relative state root is anchored once so the lock is released under the path it was taken; Windows drive-letter roots stay absolute.

Dead helpers removed (#3435). applySignal and newDimensionTotals in scripts/psychographic-signals.ts lost their last production caller when --derive moved to accumulateSignals; they and their three unit tests are gone.

Proof

  • Repro on main 3bfe566: 9 of 270 derives failed with ENOENT, 2 of 30 sessions lost. On this branch: 0 of 270, 30 of 30 kept.
  • New tests in test/gstack-developer-profile.test.ts each failed on the code before their fix: directory at the old temp path, held lock blocking derive and log-session, stale, dead-holder and aged live-pid takeovers, a takeover in progress, an unremovable lock still giving up, a relative state root, and 6 rounds of 6 derives keeping every session.
  • Focused lane at 022210e: 157 tests, 0 failed. Remote pregate on tree 47fa1a2dd585: 3851 tests, 0 failed; macOS and Windows lanes cleared by CI runs 41237822717 and 41237822659.

Security read

A local state writer only: no network calls, no new environment reads beyond the test-only GSTACK_PROFILE_LOCK_TIMEOUT_MS, no permission widening, no workflow, setup or install edits, and no new dependencies. No outside code was carried over.

Review notes

Below the blocking floor (would not fail a test, break production, or lose data); recorded, not fixed here.

  • A laptop suspended for more than 5 minutes mid-write can have its lock taken over by another writer on resume.
  • Reclaiming a stale takeover dir is check-then-rmdir.
  • The overlap test could reach the 10 s give-up on a very slow runner.
  • A drive-relative Windows root such as C:foo is not anchored.
  • gstack-distill-apply and /plan-tune's declared-profile edits still read-modify-rename without the lock (pre-existing; called out in the changelog fragment).
  • docs/troubleshooting.md has no entry for exit 5.

Documentation

Status: blocked, with the owner's named risk.

Documentation exception: accepted by GStack Minder (Captain) 2026-10-31 via GSTA-216 Captain reply: Do it: docs risk accepted: Docs audit gsta216-docs-2 covered the diff before 022210e; the only later change is a one-line test type fix that no doc references.

Scope: base 3bfe566 to head 3b15c19 on garrytan/gsta216-plan-tune-profile-lock: 8 commits and 5 files (bin/gstack-developer-profile, scripts/psychographic-signals.ts, two test files and one changelog.d fragment), with no staged, unstaged or new files. I listed 909 tracked and new .md and .tmpl files, then searched them for gstack-developer-profile, applySignal and newDimensionTotals, psychographic-signals, the profile .tmp and .lock paths, and exit 5. I read the docs that matched.

Documentation health:

  • changelog.d/garrytan-gsta216-plan-tune-profile-lock.md: Current. Its claims match the diff (protected; reviewed only).
  • docs/troubleshooting.md: Current. No entry covers the new exit 5 (coverage gap below).
  • docs/designs/FIX_1671_PROFILE_MIGRATION.md: Current. Its 'No mkdir-locks' decision is a dated record, left as written.
  • docs/designs/PLAN_TUNING_V0.md: Current.
  • plan-tune/SKILL.md.tmpl: Current. Its declared-edit writer still has no lock; the fragment's Not covered yet section says so.
  • office-hours/SKILL.md.tmpl, office-hours/sections/design-and-handoff.md.tmpl: Current. The --log-session ... || true calls are unaffected.
  • README.md, AGENTS.md, CLAUDE.md, CONTRIBUTING.md, docs/skills.md: Current. None documents profile internals.
  • CHANGELOG.md: Current. Not changed by this branch; its latest version matches VERSION.

Coverage debt:

Entity Reference How-to Tutorial Explanation
profile lock and exit 5 for --derive, --log-session, --reconcile and --migrate ✅ bin header and changelog fragment ❌ ❌ ✅ code comment
GSTACK_PROFILE_LOCK_TIMEOUT_MS (test-only) ✅ code comment ❌ ❌ ❌
Removed applySignal and newDimensionTotals ✅ fragment n/a n/a n/a

The common gap: neither exit-5 message ('another writer held for N ms' or 'cannot create ') has a docs/troubleshooting.md section with an anchor and a Fix line. I flagged it rather than filling it. /document-generate can fill it later.

Diagram drift: none. No architecture diagram names the profile writer or the signal helpers.

Summary

Overlapping gstack-developer-profile writers no longer lose /office-hours sessions or fail with ENOENT (#3437). --derive, --log-session, --reconcile and --migrate now hold developer-profile.json.lock from before they read the profile until after they rename it, and each writes its own mktemp file. The dead helpers applySignal and newDimensionTotals are removed with their three tests (#3435).

Why

gstack-question-log starts a background --derive after every append, and a multi-question AskUserQuestion logs several rows at once. Every derive wrote the same fixed developer-profile.json.tmp and rewrote the profile without a lock. On main at 3bfe566, 30 rounds of 8 overlapping derives plus one --log-session saw 9 of 270 runs fail with ENOENT on rename and lost 2 of 30 sessions. On this branch the same run has 0 failures and keeps 30 of 30 sessions.

Blast radius

One shell script and its tests. The owner file names the holder's process ID and release is ownership-checked. A lock is taken over when its holder is gone, or once it is 5 minutes old even if a process with that ID is running, since the ID may have been reused. Takeovers go one at a time under developer-profile.json.lock.takeover, and interrupt cleanup removes a takeover lock the process holds. A writer that can't get the lock in 10 seconds writes nothing and exits 5; an unwritable state directory fails right away. A relative state root is anchored once, and Windows drive-letter roots stay as they are. gstack-distill-apply and /plan-tune's declared edits still write without the lock (noted in the changelog fragment).

Pre-Landing Review

REVIEW_LOOP: passes=2 blocking_found=1 deferred=0 noted=7 fixed=6 scope=frozen fix_checks=4

The pid-reuse finding past the review cap was fixed under GStack Minder's written approval (2026-10-31). Below the blocking floor and not fixed here:

  • A laptop suspended for more than 5 minutes mid-write can have its lock taken over on resume.
  • Reclaiming a stale takeover directory is check-then-rmdir.
  • The overlap test could reach the 10-second give-up on a very slow runner.
  • A drive-relative Windows root such as C:foo is not anchored.
  • docs/troubleshooting.md has no entry for exit 5.

Issues

Fixes #3437
Fixes #3435

garrytan and others added 8 commits October 31, 2026 18:46
…e temp file (#3437)

Concurrent background --derive runs shared developer-profile.json.tmp and rewrote the whole profile unlocked, so renames failed with ENOENT and a concurrent --log-session was dropped. Every read-modify-write now holds developer-profile.json.lock and writes a mktemp file.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Both lost their last production caller when --derive moved onto accumulateSignals; only three unit tests referenced them.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Use the PID in the lock token, anchor a relative state root once so do_derive's cd cannot leak the lock, and note the stale-takeover tradeoff.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Keep Windows drive-letter state roots absolute when anchoring a relative root, and say which writers do not take the lock yet.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Step 11 voices: a late stale-lock mv could evict a fresh owner, a failed mv spun past the timeout, and the 10 s give-up sat under the 30 s stale age. Takeover now checks the holder's pid, re-reads the owner under a takeover lock, falls through to the give-up on failure, and reports an unwritable state directory at once.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
A crashed holder whose pid now belongs to a live process kept its lock forever. An owned lock past 5 minutes now counts as abandoned, and cleanup removes a takeover lock this writer holds.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
… removal (#3435)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@trunk-io

trunk-io Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

😎 This pull request was merged.

garrytan and others added 2 commits October 31, 2026 20:10
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@github-actions github-actions Bot changed the title fix: lock developer-profile writers so overlapping derives keep every session (#3437, #3435) v1.92.69.0 fix: lock developer-profile writers so overlapping derives keep every session (#3437, #3435) Nov 2, 2026
@capy-ai
capy-ai Bot merged commit 7762c39 into main Nov 2, 2026
55 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant