[PR #4274] [MERGED] fix(lifecycle): preserve observations and cleanup ownership #6153

Closed
opened 2026-10-31 01:12:16 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/4274
Author: @morluto
Created: 10/15/2026
Status: ✅ Merged
Merged: 10/16/2026
Merged by: @N0zoM1z0

Base: main ← Head: fix/codebase-lifecycle-audit


📝 Commits (10+)

  • 5ece846 fix(application): retain completed evidence through cancellation
  • 9b5f4aa fix(wasm): retain final observations through cancellation
  • 49afbc7 fix(browser): retain final observations and forward cancellation
  • e33a461 fix(ghidra): isolate cancellation of shared startup waiters
  • e97e740 fix(mcp): keep shutdown registrations until cleanup succeeds
  • f4fbdde fix(adb): own transfer snapshots and stage screen publication
  • b60a5bc fix(verification): report ADB cleanup failures
  • 62d2fc0 fix(runner): stop owned Windows commands on cancellation
  • ba26ea7 fix(website): canonicalize link containment boundaries
  • 474da80 docs(testing): cover completion races and cleanup retry

📊 Changes

157 files changed (+11502 additions, -2863 deletions)

View changed files

📝 .github/workflows/ci.yml (+3 -1)
📝 .github/workflows/real-packet-capture.yml (+1 -1)
📝 CONTRIBUTING.md (+4 -1)
📝 docs/mcp-contracts.md (+22 -8)
📝 docs/testing.md (+56 -0)
📝 docs/tool-design.md (+26 -1)
📝 licenses/npm-dependencies.txt (+141 -1)
📝 package-lock.json (+504 -0)
📝 package.json (+1 -0)
📝 scripts/ci/scopes.mjs (+4 -0)
📝 scripts/lib/kuna-native-reference-verifier.mjs (+10 -4)
📝 scripts/lib/kuna-string-verifier.mjs (+11 -4)
📝 scripts/lib/verifier-cleanup.mjs (+1 -0)
➕ scripts/lib/verifier-file-resources.d.mts (+7 -0)
➕ scripts/lib/verifier-file-resources.mjs (+10 -0)
➕ scripts/lib/windows-owned-command.d.mts (+51 -0)
➕ scripts/lib/windows-owned-command.mjs (+173 -0)
📝 scripts/run-exclusive-command.mjs (+56 -11)
📝 scripts/test-website.py (+38 -3)
📝 scripts/verify-adb.mjs (+34 -18)

...and 80 more files

📄 Description

Summary

Preserve completed observations, primary failures, and cleanup ownership when cancellation or a failed close races finalization. Fixes #3923, #3927, #3983, #4255, #4256, #4257, #4258, #4260, #4261, #4264, #4266, #4277, and #4289. Related audit: #4227. Raw-partial recovery design follow-up: #4276.

Changes

  • Shared CLI/MCP completion preserves Evidence, typed partial outcomes, original failures, abort reasons, and cleanup ownership through cancellation and finalization. Browser scenario cancellation retains the exact abort reason and validated partial capture after both interrupted actions and final cleanup.
  • Descriptor reads and immutable snapshots retain exact cleanup capabilities. Cleanup leases resolve originating errors after confirmed release, including release before binding. ADB drains children before roots, retains acquisition/publication receipts, and preserves recovered snapshot failure history.
  • Kuna command/export outcomes carry descriptor cleanup explicitly. Cache lookup retries retained owners before reading, blocks unresolved admission, and keeps bounded retry causes. Profile and session inspection share an owner adapter; the file-close port accepts the close capability it actually needs.
  • Artifact analysis errors bind to their retained roots and descriptor scope. TShark/sigrok recovery updates the original returned error, preserves primary causes and partial observations, and skips confirmed process cleanup while retrying snapshots. JADX retirement resolves its reported errors after full release.
  • Main's shared startup owner serves Ghidra/Hopper. Peer cancellation, last-waiter cleanup, owner closure, retry cancellation, queued deadlines, and final-lineage cleanup retain their distinct semantics.
  • Linux publisher helpers borrow operation child scopes and preserve cleanup_failed through admission and launcher status. Windows runners keep native Job Object ownership and command locks through failed tree cleanup; POSIX-only fault controls are platform-scoped.
  • Lifecycle guidance covers explicit cleanup capabilities, blocked admission, late binding, mixed outcomes, and recovery. Website containment and repeated shutdown-event recovery remain included.

Validation

Local toolchain: Node 24.18.0 on macOS arm64. Native CI is identified below.

  • Static checks, cached runtime build, and generated documentation checks passed. The latest publisher/runner selection passed 17 tests with 7 Windows-only skips; publisher cleanup recovery uses the exact retained descriptor and the public Result contract.
  • JADX/Kuna/ADB cleanup retry controls passed 134 tests with 26 platform skips. Separate controls passed 28 Kuna cache tests, 6 uninstall cleanup tests, and 17 shared-transport/build-fixture tests. These selections overlap.
  • Before-fix controls reproduced the retained PCAP errors, second JADX retry error, Kuna mixed-owner and late-binding errors, ADB admission wrapper, Windows executable resolution, and uninstall primary-cause failures.
  • Focused native Windows verification passed 13 tests with 4 POSIX-only skips. This exercised real Job Object retention after leader exit, message/disconnect cancellation, protocol-stdin closure, bare executable resolution, and command shims. Supervisor tests join process exit, pipe closure, and IPC disconnection separately because parent-initiated IPC disconnect can omit Node's aggregate child close event.
  • Browser cancellation controls passed 28 tests across the provider, actual CLI signal subprocesses, MCP, and SDK probe lifecycle. The active-cancellation assertion failed against the prior merge result, which reported success. Freshly compiled artifacts were used for the CLI tests; schema validation and cleanup-failure precedence remain before cancellation classification.
  • Shared application cancellation controls passed 33 tests, including exact Error/object abort-reason identity at completion/admission, retained Evidence, and invalid-output precedence. Both new reason assertions failed against the prior helper. Publisher recovery assertions now check ownership phases rather than fixed retry counts and verify the exact SHA-256 digest; all 7 file-ownership tests passed.
  • Fresh stdio MCP exercise against the current build validated 207 unique tools and 414 schemas. Typed-error recovery, SQLite/blob values, retained Evidence, archive/plist routing, close, and shutdown passed. Runtime identity reports a null commit, so this verifies checkout content rather than hash attestation.
  • JADX cancellation controls passed 38 tests; two failed before the cause fix. Strengthened controls confirm both exact abort/close causes and actual descriptor release. ADB cancellation/publication controls passed 101 tests; four before-fix controls failed. Its shared finalization now constructs cancellation Evidence once and composes it with retained cleanup failures.
  • The macOS session MCP file passed all 9 tests locally. Its multi-roundtrip workflow took about 2 seconds alone but hit a bespoke 10-second CI cap during concurrent native suites; it now inherits the existing 30-second suite budget with all lifecycle assertions retained. The final Apple CI lane passed.
  • Linux PCAP controls passed 47 tests with one Windows-only skip. The real capture lane selects the provider regressions as well as snapshot/descriptor controls.

Historical real Ghidra 12.1.4/JDK21 verification at ea790d43b passed 373 CLI/MCP calls and 52 expected refusals; it was not rerun at the final revision.

Fault-injection regressions use controlled processes and filesystem faults. Native Kuna/JADX and physical ADB were not exercised locally. No complete token/CPU/process-family-memory benchmark was performed. Final-head CI for 9b58709f8 passed all 36 jobs, including all five boundary shards, source/static/docs checks, real browser/Apple workflows, and Windows/macOS/Linux package lanes. The separate real packet-capture, signal-recording, and Go-metadata workflows also passed.

Author readiness

Human owner: @morluto

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • Human readiness and required CI/platform checks completed.
  • Final diff and validation limitations reviewed by the human owner.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/4274 **Author:** [@morluto](https://github.com/morluto) **Created:** 10/15/2026 **Status:** ✅ Merged **Merged:** 10/16/2026 **Merged by:** [@N0zoM1z0](https://github.com/N0zoM1z0) **Base:** `main` ← **Head:** `fix/codebase-lifecycle-audit` --- ### 📝 Commits (10+) - [`5ece846`](https://github.com/morluto/rea/commit/5ece84632a1b86dc88aea7ef153ec4d9190c149b) fix(application): retain completed evidence through cancellation - [`9b5f4aa`](https://github.com/morluto/rea/commit/9b5f4aa41d61e627ae1734f2501f3c9e44d0c049) fix(wasm): retain final observations through cancellation - [`49afbc7`](https://github.com/morluto/rea/commit/49afbc7cd1d1f24068da7d609ffbbf93b76cb736) fix(browser): retain final observations and forward cancellation - [`e33a461`](https://github.com/morluto/rea/commit/e33a461cefa452438677cb56ba51e42410966c99) fix(ghidra): isolate cancellation of shared startup waiters - [`e97e740`](https://github.com/morluto/rea/commit/e97e740e1f3b0503d0195b56ca20fe272feb1b58) fix(mcp): keep shutdown registrations until cleanup succeeds - [`f4fbdde`](https://github.com/morluto/rea/commit/f4fbdde4eba6972ebc3df0759c6a98177a1f1d04) fix(adb): own transfer snapshots and stage screen publication - [`b60a5bc`](https://github.com/morluto/rea/commit/b60a5bc0cb86f2f2fbc484588295b4ce8a3516ad) fix(verification): report ADB cleanup failures - [`62d2fc0`](https://github.com/morluto/rea/commit/62d2fc0bf226d5d82e2360e98a841e5b63ed085a) fix(runner): stop owned Windows commands on cancellation - [`ba26ea7`](https://github.com/morluto/rea/commit/ba26ea7dd77326dbb699f64911c6a1bdc2b76eb3) fix(website): canonicalize link containment boundaries - [`474da80`](https://github.com/morluto/rea/commit/474da8031893f7fecf3781e2c8835552dbd0a7ad) docs(testing): cover completion races and cleanup retry ### 📊 Changes **157 files changed** (+11502 additions, -2863 deletions) <details> <summary>View changed files</summary> 📝 `.github/workflows/ci.yml` (+3 -1) 📝 `.github/workflows/real-packet-capture.yml` (+1 -1) 📝 `CONTRIBUTING.md` (+4 -1) 📝 `docs/mcp-contracts.md` (+22 -8) 📝 `docs/testing.md` (+56 -0) 📝 `docs/tool-design.md` (+26 -1) 📝 `licenses/npm-dependencies.txt` (+141 -1) 📝 `package-lock.json` (+504 -0) 📝 `package.json` (+1 -0) 📝 `scripts/ci/scopes.mjs` (+4 -0) 📝 `scripts/lib/kuna-native-reference-verifier.mjs` (+10 -4) 📝 `scripts/lib/kuna-string-verifier.mjs` (+11 -4) 📝 `scripts/lib/verifier-cleanup.mjs` (+1 -0) ➕ `scripts/lib/verifier-file-resources.d.mts` (+7 -0) ➕ `scripts/lib/verifier-file-resources.mjs` (+10 -0) ➕ `scripts/lib/windows-owned-command.d.mts` (+51 -0) ➕ `scripts/lib/windows-owned-command.mjs` (+173 -0) 📝 `scripts/run-exclusive-command.mjs` (+56 -11) 📝 `scripts/test-website.py` (+38 -3) 📝 `scripts/verify-adb.mjs` (+34 -18) _...and 80 more files_ </details> ### 📄 Description ## Summary Preserve completed observations, primary failures, and cleanup ownership when cancellation or a failed close races finalization. Fixes #3923, #3927, #3983, #4255, #4256, #4257, #4258, #4260, #4261, #4264, #4266, #4277, and #4289. Related audit: #4227. Raw-partial recovery design follow-up: #4276. ## Changes - Shared CLI/MCP completion preserves Evidence, typed partial outcomes, original failures, abort reasons, and cleanup ownership through cancellation and finalization. Browser scenario cancellation retains the exact abort reason and validated partial capture after both interrupted actions and final cleanup. - Descriptor reads and immutable snapshots retain exact cleanup capabilities. Cleanup leases resolve originating errors after confirmed release, including release before binding. ADB drains children before roots, retains acquisition/publication receipts, and preserves recovered snapshot failure history. - Kuna command/export outcomes carry descriptor cleanup explicitly. Cache lookup retries retained owners before reading, blocks unresolved admission, and keeps bounded retry causes. Profile and session inspection share an owner adapter; the file-close port accepts the close capability it actually needs. - Artifact analysis errors bind to their retained roots and descriptor scope. TShark/sigrok recovery updates the original returned error, preserves primary causes and partial observations, and skips confirmed process cleanup while retrying snapshots. JADX retirement resolves its reported errors after full release. - Main's shared startup owner serves Ghidra/Hopper. Peer cancellation, last-waiter cleanup, owner closure, retry cancellation, queued deadlines, and final-lineage cleanup retain their distinct semantics. - Linux publisher helpers borrow operation child scopes and preserve cleanup_failed through admission and launcher status. Windows runners keep native Job Object ownership and command locks through failed tree cleanup; POSIX-only fault controls are platform-scoped. - Lifecycle guidance covers explicit cleanup capabilities, blocked admission, late binding, mixed outcomes, and recovery. Website containment and repeated shutdown-event recovery remain included. ## Validation Local toolchain: Node 24.18.0 on macOS arm64. Native CI is identified below. - Static checks, cached runtime build, and generated documentation checks passed. The latest publisher/runner selection passed 17 tests with 7 Windows-only skips; publisher cleanup recovery uses the exact retained descriptor and the public `Result` contract. - JADX/Kuna/ADB cleanup retry controls passed 134 tests with 26 platform skips. Separate controls passed 28 Kuna cache tests, 6 uninstall cleanup tests, and 17 shared-transport/build-fixture tests. These selections overlap. - Before-fix controls reproduced the retained PCAP errors, second JADX retry error, Kuna mixed-owner and late-binding errors, ADB admission wrapper, Windows executable resolution, and uninstall primary-cause failures. - [Focused native Windows verification](https://github.com/morluto/rea/actions/runs/38843411084) passed 13 tests with 4 POSIX-only skips. This exercised real Job Object retention after leader exit, message/disconnect cancellation, protocol-stdin closure, bare executable resolution, and command shims. Supervisor tests join process exit, pipe closure, and IPC disconnection separately because parent-initiated IPC disconnect can omit Node's aggregate child close event. - Browser cancellation controls passed 28 tests across the provider, actual CLI signal subprocesses, MCP, and SDK probe lifecycle. The active-cancellation assertion failed against the prior merge result, which reported success. Freshly compiled artifacts were used for the CLI tests; schema validation and cleanup-failure precedence remain before cancellation classification. - Shared application cancellation controls passed 33 tests, including exact Error/object abort-reason identity at completion/admission, retained Evidence, and invalid-output precedence. Both new reason assertions failed against the prior helper. Publisher recovery assertions now check ownership phases rather than fixed retry counts and verify the exact SHA-256 digest; all 7 file-ownership tests passed. - Fresh stdio MCP exercise against the current build validated 207 unique tools and 414 schemas. Typed-error recovery, SQLite/blob values, retained Evidence, archive/plist routing, close, and shutdown passed. Runtime identity reports a null commit, so this verifies checkout content rather than hash attestation. - JADX cancellation controls passed 38 tests; two failed before the cause fix. Strengthened controls confirm both exact abort/close causes and actual descriptor release. ADB cancellation/publication controls passed 101 tests; four before-fix controls failed. Its shared finalization now constructs cancellation Evidence once and composes it with retained cleanup failures. - The macOS session MCP file passed all 9 tests locally. Its multi-roundtrip workflow took about 2 seconds alone but hit a bespoke 10-second CI cap during concurrent native suites; it now inherits the existing 30-second suite budget with all lifecycle assertions retained. The final Apple CI lane passed. - Linux PCAP controls passed 47 tests with one Windows-only skip. The real capture lane selects the provider regressions as well as snapshot/descriptor controls. Historical real Ghidra 12.1.4/JDK21 verification at `ea790d43b` passed 373 CLI/MCP calls and 52 expected refusals; it was not rerun at the final revision. Fault-injection regressions use controlled processes and filesystem faults. Native Kuna/JADX and physical ADB were not exercised locally. No complete token/CPU/process-family-memory benchmark was performed. [Final-head CI](https://github.com/morluto/rea/actions/runs/38845917971) for `9b58709f8` passed all 36 jobs, including all five boundary shards, source/static/docs checks, real browser/Apple workflows, and Windows/macOS/Linux package lanes. The separate real packet-capture, signal-recording, and Go-metadata workflows also passed. ## Author readiness Human owner: @morluto - [ ] I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work. - [ ] I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps. - [ ] I declare this PR ready for initial maintainer review. ## Before merge - [ ] Human readiness and required CI/platform checks completed. - [ ] Final diff and validation limitations reviewed by the human owner. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-31 01:12:16 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#6153
No description provided.