#14 (CRIT): ContextBuilder.selfAwarePreamble names search_memory + forget_fact with explicit cue 'call search_memory FIRST. Never claim to remember without searching.'
#16 (HIGH): MemoryQueries.sanitizeFTS5Query strips non-alphanumeric, quotes tokens; HybridSearch.searchFacts calls it before binding to MATCH ?. Embedding still runs on raw query.
#12 (CRIT): MemoryStore.init accepts optional embedder; insertNewFact writes facts_vec after the facts commit. Vec failures log + leave FTS row (no rollback). installMemory shares one embedder between writer + reader.
#15 (HIGH): drop stableHash; pass sentinel 0 as sourceTurnId (option 1 per audit — smaller change surface than threading real rowid through 5 files). Schema comment updated.
#13 (CRIT): two-layer fix. Layer 1: AppDelegate owns a per-process sentinel TurnID; installAgent writes the matching turns row after beginSession; AppDelegateMemoryReplaySink attributes events to it. Layer 2: ReplayLog.flushPending retries failed batches event-by-event so one poisoned row only drops itself.
Memory 98 + Replay 34 + AgentCore 243 tests pass; all 18 boundary gates green.
The 2026-05-03 INT-3 smoke test surfaced three latent runtime bugs the
unit-level GSD verifications all missed because the audits were source-
grep, not runtime-trace:
1. **F-E-RACE-1** — `agentInstallTask` awaited memory + vision installs
but NOT the MCP runtime build task. MCPRuntime build is ~1s due to
helper child-process spawn, so installAgent ALWAYS short-circuited on
`mcpRuntime == nil` and the orchestrator + broadcaster + ALL six
broadcaster subscribers stayed dormant for the entire process
lifetime. Fix: capture `mcpInstallTask` Task handle and await it
before calling installAgent. The v0.12.0 milestone audit's claim of
"5 broadcaster subscribers wired" was accurate at source-grep level
and false at runtime.
2. **F-E-FK-1** — installAgent constructed the orchestrator with a
fresh SessionID but never called `replayLog.beginSession(...)`.
Every `startTurn` violated the FK and returned
`SubmitOutcome.rejected(reason: .configError)` — surfacing in the
chat panel as "Config error — see ~/Library/Logs/Jarvis/system.log."
Production code only ever called beginSession in tests
(MCPRuntimeWiringTests). Fix: installAgent now reads
CFBundleShortVersionString + CFBundleVersion from Info.plist, calls
beginSession, and passes the returned SessionID to the orchestrator.
3. **F-E-WIRE-1** — `OutboundBatcher` was constructed only inside
`installVoice`, AFTER OpenWakeWord/Silero models loaded. Voice DAG
short-circuit on missing models in Debug builds left
`self.outboundBatcher == nil`, and every `outboundBatcher?...`
chained-optional in the .bus subscriber silently dropped tokenDelta
/ turnStarted / turnEnded / submitRejected. The chat panel got
nothing back from the orchestrator. Fix: hoist batcher construction
into installAgent (only depends on webviewBridge, not voice models);
installVoice reuses self.outboundBatcher rather than overwriting.
In addition, the .bus subscriber's translation logic — including
StopReason → TurnTerminator mapping, turnStarted synthesis on first
emission for a fresh TurnID, error → submitRejected forwarding for
mid-stream failures — was inline in AppDelegate and therefore
impossible to unit-test (App target xctest harness is upstream-broken
on Xcode 26). Extracted to `BusForwarder` in AgentOrchestrator with a
sink protocol; App provides `AppBusForwarderSink` (~50 LOC) as the
glue. Every translation branch now has unit coverage.
Files:
- packages/AgentCore/Sources/AgentOrchestrator/BusForwarder.swift —
Pure logic. `BusForwarderSink` protocol; `BusForwarder.terminator(for:)`
StopReason mapping; `BusForwarder.drain(events:sink:)` async loop with
per-turn lastEmittedTurnId state. No Bus package dep — keeps the
layering clean.
- packages/AgentCore/Tests/AgentOrchestratorTests/BusForwarderTests.swift
— 16 cases covering every branch: terminator mapping (5, exhaustive
on StopReason), tokenDelta forwarding (3 — synthesize start, dedupe
start across same-turn deltas, two-turn handoff), turnEnd forwarding
(4 — mapped terminator, synthesize-start-on-bare-turnEnd,
streamTruncated→errored, state reset), error forwarding (2), ignored
events (1), malformed-id guard (1).
- packages/Replay/Tests/ReplayTests/SessionForeignKeyTests.swift —
3 cases (FK1: startTurn-without-beginSession-throws; FK2: post-
beginSession-succeeds; FK3: multiple-startTurns-share-one-session).
Closes the bug class regardless of any future AppDelegate refactor.
- App/AppBusForwarderSink.swift — thin transport adapter. Translates
`BusForwarder.Terminator` to wire-format `Bus.TurnTerminator` and
dispatches across OutboundBatcher actor.
- App/AppDelegate.swift — race fix, beginSession call, batcher hoist,
inline subscriber replaced with `BusForwarder.drain(events: sink:)`.
- Jarvis.xcodeproj/project.pbxproj — xcodegen regen picks up new App
source file.
- .planning/AUDIT-FINDINGS.md — three new findings (F-E-RACE-1,
F-E-FK-1, F-E-WIRE-1) documented and marked closed; refactor
rationale recorded; carry-forward items called out
(streamTruncatedFinal cause unverified without Keychain access; F1
chat-turn end-to-end test is next).
Verification:
- AgentCore 194/194 (was 178; +16 BusForwarder).
- Replay 33/33 (was 30; +3 SessionFK).
- Bus 55/56 (F-A2-01 pre-existing).
- All 15 boundary grep gates PASS.
- scripts/check-app-builds.sh PASS.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
L3 ("buffer below chunk threshold remains unflushed") relied on the
production 50ms batch-window timer not having fired by the time the
assertion ran. Under CI load the timer could race ahead of the
assertion and L3 would observe `count == 50` instead of `0`, failing
spuriously.
Add an injectable `batchWindowMs` parameter to `ReplayLog.init` (defaults
to `Self.batchWindowMs = 50` so production behavior is unchanged). The
init reads the override into a per-instance `batchWindowMsValue` that
gates the windowed-flush Task.sleep duration.
Update L3 to construct `ReplayLog(databaseURL:, batchWindowMs: 60_000)`
so the 60-second window cannot fire within the test's lifetime. The
only flush trigger that could plausibly fire is the 64-event chunk
threshold, which 50 events doesn't reach. L3 is now deterministic.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Pre-fix, a transaction failure inside `flushPending` cleared `pending`
before the transaction began. On rollback the entire batch was lost
with no breadcrumb beyond `batch_size` + raw error. This violated
OBS-02's durability claim — silent truncation of the authoritative
byte record on disk-pressure / locked-WAL conditions.
Three changes:
1. On rollback, re-buffer the dropped batch at the FRONT of `pending`
so the next flush attempt can retry. Successful flushes reset the
failure counter.
2. Capture the affected `turn_ids` in the error metadata so a forensic
reader can identify which turns lost which events. Redact the
error message (defense-in-depth alongside HI-01).
3. After 3 consecutive failures, escalate from `error` to `critical`
log severity so chronic data-loss conditions surface to the
DevOverlay / log scrapers. Don't `fatalError` — OBS-02 says replay
is best-effort and must never propagate into orchestrator turn
semantics.
Add ReplayLogTests.test_L9_flushFailureRebuffersEvents — happy-path
control verifies the re-buffer path doesn't drop events when flushes
succeed.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Pre-fix `send` for a non-dropTag element awaited a continuation, then
called `await send(element)` after resume. Swift does not guarantee
tail-call elimination across `await` suspension points, so each
backpressure cycle could add a stack frame. Under pathological consumer
stalls (slow drainer + many protected sends) the producer's stack would
grow proportional to retry depth.
Convert to a `while true` loop. Same shape as `BoundedAsyncChannel.send`
(no recursion). On resume the loop re-checks `finished`, re-tries the
fast paths, and re-attempts the enqueue at the same stack frame.
Add T7 stress test: 5000 protected (toolCall) sends through a capacity-1
channel with a serial drainer. Every send suspends until the previous
element is consumed. Pre-fix this would have recursed 5000 frames deep
in the actor's send invocation chain. Post-fix it stays O(1).
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- ReplayLog actor: opens replay.db with WAL pragmas + DDL + meta seed; beginSession/startTurn/record/endTurn/close. Writes batched in 50ms window OR 64-event chunks. endTurn appends a turn_end event, flushes, UPDATEs ended_at + stop_reason, then PRAGMA wal_checkpoint(TRUNCATE) for the per-turn fsync. Failures logged via JarvisLogChannel.replay; never propagated.
- OrphanDetector actor: opens its own connection, increments meta.crash_count, runs the OBS-07 query (ended_at IS NULL AND turn_id NOT IN (turn_end events)), stamps each orphan with stop_reason='orphan_recovered' + recovery_marker='detected_at_launch:crash_count=N'.
- 12 new tests: L1-L8 (session/turn/buffering/window/chunk/large-blob/nothing-masked) + O1-O4 (orphan vs non-orphan, race window, crash_count increment, end-to-end SIGKILL parity).
- Adds JarvisLogChannel.replay + .devoverlay (additive — Logging test updated to assert 7 cases). The full Task 3 channel-tests file lands next commit.