Skip to content

fix(sdk-pi): write the error log without blocking pi - #91

Merged
aikins01 merged 1 commit into
mainfrom
fix/pi-async-error-log
Oct 27, 2026
Merged

aikins01 merged 1 commit into
mainfrom
fix/pi-async-error-log

Conversation

@aikins01

Copy link
Copy Markdown
Contributor

pi's default onError wrote telemetry-dev.log with statSync, renameSync, and appendFileSync, so every reported error waited on the disk on pi's event loop. With a slow agent directory, such as a network mount set through PI_CODING_AGENT_DIR, that held up pi's TUI.

writeErrorLog now formats the entry and returns. The rotation and append run on one promise chain with fs/promises, so entries keep their call order and the 5 MB rotation can't race itself within a process. While 100 entries are pending, new ones are dropped, which bounds memory when the disk stops responding.

session_shutdown now waits for that queue after the final flush, so a failure reported during shutdown still reaches the log before pi exits. The wait gives up after one second, because pi waits on each shutdown handler without a timeout and a stalled mount would otherwise keep pi from exiting or switching sessions. Entries still queued when pi crashes or is killed are lost; before this change they would already have been on disk.

The stalled-write test lives in its own file because its mocked appendFile never settles and would block the shared queue for every other test in pi.test.ts.

Closes #90

The default onError ran statSync, renameSync, and appendFileSync on
pi's event loop, so a slow agent directory, such as a network mount set
through PI_CODING_AGENT_DIR, held up pi's TUI on every reported error.

Entries now queue on one promise chain that rotates and appends with
fs/promises, in call order. New entries are dropped while 100 are
pending. session_shutdown waits up to one second for the queue, so
errors that the final flush reports still land before pi exits, and a
stalled disk cannot keep pi from shutting down.

Closes #90
@aikins01 aikins01 self-assigned this Oct 27, 2026
@aikins01
aikins01 merged commit 037c972 into main Oct 27, 2026
10 checks passed
@aikins01
aikins01 deleted the fix/pi-async-error-log branch October 27, 2026 13:52
@aikins01 aikins01 mentioned this pull request Oct 27, 2026
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.

pi: write the error log without blocking the event loop

1 participant