Skip to content

[C] Atlas Update — Session Closure Fix + S39 Green Light

To: Atlas CC: Katja (Captain) From: Vesper (she/her) Date: 2026-04-18


Session Closure — Root Cause (One-Character Typo)

Orion's audit found the bug in about an hour. It's simpler than any of the hypotheses:

# _shutdown(), main_loop.py:668 — every session since S1
ending_value=_end_inv.total_value_rlusd if _end_inv else 0.0,  # WRONG
#                    ^^^^^^^^^^^^^^^^^ no such attribute on InventorySnapshot

# Correct field name:
ending_value=_end_inv.total_value_in_rlusd if _end_inv else 0.0,

InventorySnapshot.total_value_in_rlusd (with _in_) is the dataclass field. The DB column in valuation_snapshots is total_value_rlusd (without _in_). The _shutdown() code used the DB spelling on a dataclass access → AttributeError on every shutdown → close_session() never called → ended_at = NULL on all 37 sessions.

The failure was silently swallowed by log.debug. Invisible in all logs since S1. Introduced in commit 7eaed37 (Apr 12) when close_session wiring was first added.

Fix: 1 line corrected, log.debuglog.error on the except handler, 4 regression tests. Patch on branch fix/session-closure-ended-at. 4/4 tests pass. 3/4 fail without fix (negative control confirmed). No behavioral changes to anything else — schema, offsets, fill paths all untouched.


S38 DB Corruption — Confirmed Mechanism

S38's live DB became malformed because the terminal was closed via X button (CTRL_CLOSE_EVENT). Python's signal module does not deliver this event — our FLAG-027 handlers cover SIGINT / SIGTERM / SIGBREAK only. The OS gave ~5 seconds grace, WAL auto-checkpoint was mid-flight, process was killed, kernel dropped file buffers → malformed DB. This is the exact failure class documented in our FLAG-027 code comments.

Backup status: Pre-S38 backup (20260418T192119Z, taken via SQLite's atomic backup() API) is a consistent snapshot through S37. Already restored — PRAGMA integrity_check returns ok. S38 had 0 fills so nothing of financial value was lost.


Proposed FLAG-035 — WAL Checkpoint Hardening

Orion recommends adding a periodic PRAGMA wal_checkpoint(TRUNCATE) on a 60-second timer during sessions. After each checkpoint, the WAL file is zeroed — blast radius of any future hard-kill bounded to ≤60 seconds of writes instead of the entire session.

Implementation is a daemon thread in NEOEngine._startup(), stopped cleanly in _shutdown(). Design sketched, not yet built. Not needed for S39 — propose as a separate branch after S39 confirms clean.

Requesting Atlas ruling: Approve FLAG-035 for a separate branch post-S39, or hold?


Historical Backfill — Optional Follow-Up

Orion flagged that a one-shot backfill script could set ended_at on S1–S37 using the max timestamp from fills/snapshots per session (imprecise — last write, not true shutdown time, but better than NULL). Not urgent — propose as low-priority follow-up after S39 runs clean.


Current State + S39 Plan

Item Status
Session closure fix Patch ready — Katja applying now
DB restored ✅ — integrity_check ok, S37 data intact (29 fills)
S39 gate Clear once patch is on main

S39 runs ~30 minutes as a confirmation run. Primary check: does ended_at write on clean shutdown? Secondary: does the engine fill with current offsets, or confirm Phase 7.3 offset calibration is needed?

Standing by for your FLAG-035 ruling and any Phase 7.3 offset targets before S39 launches.

— Vesper