Files
museion/docs/devlog/20261020-issue124-cancel-ack-fake-deferred-teardown_log.md
T
AlexKucera 154bb8a114
CI / ci (push) Canceled after 0s
test(mentor): cancel-ack fake + deferred teardown
The fake ACP engine's hangOnPrompt mode slept oblivious to
session/cancel, so a cancelled turn was only observable through
teardown and the pass bar's Cancel rail was never individually
discriminated. hangOnPrompt now holds the turn reading: session/cancel
answers the hanging prompt with stopReason "cancelled" (the real
engine's contract); stdin EOF without a cancel answers end_turn so
the child exits.

New pin 'cancelling a held pass ends the turn cancelled with no
advance' (RED->GREEN; bounded polls, so an emptied cancelPass fails
the pin instead of hanging the suite). Every fake-spawning test (27
rigs across ACPClientTests + PassRunTests) tears down via defer at
rig creation — a cancelled or interrupted test cannot leak the child;
trailing happy-path teardowns removed, mechanism/bound teardowns kept
and commented. Harness docs updated to match; 316 tests green.

Closes #124
2026-10-20 19:35:17 +02:00

93 lines
6.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Mentor ACP test-harness hardening: cancel-acknowledging fake + deferred teardown
> **Date:** 2026-10-20
> **Type:** issue
> **Reference:** https://git.babylondreams.de/AlexKucera/Museion/issues/124
## Goal
Issue #124, deferred from the #24 close-out audit: two hardening pieces for
the mentor's ACP test harness. (1) A cancel-acknowledging fake engine mode —
the fake ignored `session/cancel`, so tests that cancelled a turn only
observed the outcome through teardown and the pass bar's Cancel rail was
never individually discriminated. (2) Deferred teardown as the harness
convention — tests called shutdown at the end of the happy path, so a
cancelled or interrupted test leaked a sleeping fake child for its 30 s hang
window. Scope: the ACP fake harness + pass-run suite; provisioning fakes
unaffected.
## What Was Done
- `makeFakeACP`'s `hangOnPrompt` mode upgraded from `sleep 30` to a
cancel-acknowledging hold: after streaming, the fake keeps reading; the
moment `session/cancel` arrives it answers the hanging `session/prompt`
with `stopReason "cancelled"` (the real engine's contract); stdin EOF
without a cancel (teardown) falls through to the existing `end_turn` echo
so the child exits instead of sleeping out a window. Standalone-verified
in zsh before touching the Swift file (cancel → cancelled with the pending
rid; EOF → end_turn, exit 0).
- New pin test in PassRunTests: `cancelling a held pass ends the turn
cancelled with no advance` — RED→GREEN demonstrated (old fake: poll
exhausts, 315 pass / 1 fail; new fake: green). Bounded polls mean an
emptied `cancelPass` fails the `#expect` after 5 s instead of hanging the
suite; the explicit `mentor.shutdown()` before `await run.value` is the
commented failure bound.
- Deferred teardown at rig creation across every fake-spawning test: 17 rigs
in ACPClientTests (`defer { client.close() }` / `defer { model.shutdown() }`
— both verified idempotent and nil-safe pre-start), 10 rigs in PassRunTests
(`defer { mentor.shutdown() }`). Twelve happy-path-only trailing teardown
calls deleted; six mid-test teardowns kept where they ARE the mechanism or
a documented regression bound.
- Docs: MuseionTests/AGENTS.md — both file bullets rewritten (hangOnPrompt's
new semantics incl. the only-cancel-is-answered-during-hold clause, the
defer-at-rig-creation convention, the new pin, `noStopReason` added to the
mode list, stale "through shutdown teardown" wording fixed). Two swiftlint
pragmas (file_length on ACPClientTests.swift, function_body_length wrap
around makeFakeACP) with inline rationale.
- Verification: unit suite 316/316 (three runs: RED, GREEN, final-state),
full scheme incl. UI 317/317, SwiftFormat 0 changes, SwiftLint 0
violations on touched files. SwiftFairy audit + two-axis code-review
(Standards/Spec) + finish-audit fanout (ponytail/security/general) all
clean; the one accepted audit fix (doc clause on dropped requests during
the hold) landed.
## Decisions & Rationale
| Decision | Rationale |
|----------|-----------|
| Upgrade `hangOnPrompt` in place instead of a new mode name | The acceptance criterion is behavioral; no test needs the old cancel-oblivious hold, so a parallel mode would be dead code. Spec reviewer adjudicated this satisfies "new fake mode". |
| Inner read loop instead of `sleep 30` + timeout | EOF-on-teardown already bounds the child's life; a timer would be extra machinery for a case the defer convention removes. |
| Bounded poll + explicit shutdown bound in the pin | An emptied `cancelPass` must FAIL the pin, not hang the suite; the poll exhausts in 5 s and the shutdown frees the turn so the await completes and the test reports the failure. |
| Keep 6 mid-test teardown calls | Each is the test's subject (teardown-kills, transport-failure) or a commented regression bound (fire-and-forget, second-pass, mid-reply, pin) — per the convention this change itself documents. |
| swiftlint pragmas instead of splitting the harness file | One file / one contiguous zsh script is the documented harness contract (wire-line inspectability, shared-helper home); splitting to satisfy line counts is ceremony. |
| Consciously NOT done: python-sniff dedupe in the fake, poll-budget unification (100 vs 250), `Task.sleep(for:)` style migration, client-seam cancel assertion in fire-and-forget | All match pre-existing file idiom or duplicate end-to-end coverage already pinned in PassRunTests; each is a drive-by refactor outside #124. The client-seam assert is parked: add only if that test ever regresses confusingly. |
## Gotchas & Fixes
| Problem | Root Cause | Fix |
|---------|------------|-----|
| `git diff` output mangled (per-hunk `@@` with prefixed markers, no `+++` lines) | Repo git routes diff through a custom wrapper; `-c diff.external=` does not bypass it | `git show HEAD:<file>` + plain `diff -u --label a/... --label b/...` into a scratch file; handed that file to review children |
| `write_file` with a relative path landed in the terminal's scratch cwd | Terminal cwd persists across calls; relative paths resolve against it | Rewrote with the absolute repo path; deleted the stray scratch copy |
| swiftlint `orphaned_doc_comment` after adding pragmas | A `//` line (even a `swiftlint:disable:next` directive) between a `///` block and its declaration orphans the doc comment | Wrapped instead: `// swiftlint:disable function_body_length` before the doc block, `// swiftlint:enable` after the closing brace — doc stays adjacent to the func |
| `gitnexus detect-changes` CLI errored ("Multiple repositories indexed") | The local backend needs the repo label | `--repo museion` |
## Files Changed
| File | Change Summary |
|------|----------------|
| `MuseionTests/ACPClientTests.swift` | hangOnPrompt cancel-acknowledging hold; defer teardown ×17 rigs; doc comments + mode list; 2 swiftlint pragmas; 6 trailing teardowns removed |
| `MuseionTests/PassRunTests.swift` | New Cancel-rail pin test; defer teardown ×10 rigs; 4 trailing teardowns removed; stale comments updated |
| `MuseionTests/AGENTS.md` | Both bullets rewritten: fake contract, defer convention, pin; `noStopReason` added to mode list |
| `AGENTS.md` | GitNexus index-counter refresh (3889/12468) — tool-written, not hand-edited |
## Open Items & Next Steps
- [ ] Deferred: client-seam cancelled-resolution assertion in `cancel is
fire-and-forget` (covered end-to-end by the PassRunTests pin; add only if
that test regresses confusingly)
- [ ] None — issue #124 acceptance criteria all met; suite green; audit clean
---
*Log written by write-log skill*