Repository navigation
fix(sdk-pi): write the error log without blocking pi - #91
Merged
Merged
Conversation
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
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
pi's default
onErrorwrotetelemetry-dev.logwithstatSync,renameSync, andappendFileSync, so every reported error waited on the disk on pi's event loop. With a slow agent directory, such as a network mount set throughPI_CODING_AGENT_DIR, that held up pi's TUI.writeErrorLognow formats the entry and returns. The rotation and append run on one promise chain withfs/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_shutdownnow 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
appendFilenever settles and would block the shared queue for every other test inpi.test.ts.Closes #90