Skip to content

[sentry:7850959954] A shutdown that lands while createAtomicCore is still finishing releases the instance lock (closing its FileHandle); startup then reaches `await lock.publish(control.ho - #118

Merged
Ooooze merged 3 commits into
mainfrom
codex/sentry-fix/7850959954
Nov 18, 2026
Merged

Ooooze merged 3 commits into
mainfrom
codex/sentry-fix/7850959954

Conversation

@Ooooze

@Ooooze Ooooze commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

A shutdown that lands while createAtomicCore is still finishing releases the instance lock (closing its FileHandle); startup then reaches await lock.publish(control.host, control.port) on the way out, and writeRecord's handle.truncate(0) throws EBADF ("file closed"). The throw escapes createAtomicCore into app-daemon.ts's startup catch, where the code table cannot classify EBADF, so the report becomes the generic core startup: unknown at fatal level. The fix marks the lock released in release() before the descriptor is closed, and makes publish() skip the write once released: a released lock has no record to announce, the file is gone and may belong to a new owner. The escaped await then resolves and the already-decided shutdown completes normally. Acquire, the ready-record contract for live owners, and the persisted record format are unchanged; the regression test asserts exactly that pair of behaviours.

Evidence:
Event stack: runAppDaemon -> src/core/create.ts:1613 createAtomicCore -> src/lock/instance-lock.ts:232 publish -> src/lock/instance-lock.ts:246 writeRecord -> node:fs/promises truncate -> throwEBADFIfNecessary; event facts win32/x64, host atomic-chat, owner_scope app, component core, operation startup.
src/lock/instance-lock.ts: writeRecord starts with await handle.truncate(0); InstanceLock.release() was the only closer of that handle (await this.handle.close()), so the EBADF proves release ran before publish.
acquire's own writeRecord had already succeeded on the same handle, so the descriptor was valid at lock time and died between the two writes.
The only in-process shutdown that can run while create() is in flight is the app-lease interval in src/core/create.ts (startupDeadline = arming + CLIENT_EXPIRY_MS, everRegistered false, no work => 'retire' => void core.shutdown() => await this.lock.release()); create.ts publishes only after reapOrphans, container resolve, recover() of managed/FastFlowLM operations, startupCleanup and tunnel reaps.
Pre-fix probe (saved plan): await lock.release(); await lock.publish('[redacted]', 42424) rejected with Error: file closed; control case on a never-released lock resolved.
After the patch, src/lock/instance-lock-publish.test.ts passes both cases: publish after release resolves and leaves the lock state { kind: 'free' }; publish on a live lock yields { kind: 'owned', record: { state: 'ready' } } (2/2 passed).
Release dist c21d779 vs base a66aad0 differs only in diffusion args/compat, a CLI race test, a runtime cleanup retry and version.ts; src/lock/ and src/core/create.ts are byte-identical to base, so the defect is present in the release and unrepaired in main.
Patch delta is two behaviours: a released flag set at the top of release() before handle.close(), and an early return in publish() while that flag is set.

Regression tests: src/lock/instance-lock-publish.test.ts

Full CI and human review are required.

Report: http://127.0.0.1:8080/tenants/707d0855-80ab-4e1f-a156-f1c4546cbf52/runs/b115d7d6-4c15-43ba-8ca6-cfe21461bb30

Sentry: https://atomic-chat.sentry.io/issues/7850959954/

@Ooooze
Ooooze merged commit 73ed52a into main Nov 18, 2026
15 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

Development

Successfully merging this pull request may close these issues.

1 participant