Repository navigation
Conversation
This branch has not been deployed
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.
Summary
Preserve previously recorded workflow token/timing statistics if appending a new record fails partway through a file write.
append_statscurrently opens the cumulative history withwbefore dumping JSON. A short write (for example ENOSPC) truncates the previous history and leaves invalid JSON. The agent tool logs the write failure; the next append then resets the unreadable history to an empty list. A serialization failure can damage the same history too.Use the existing
atomic_write_jsonhelper under the existing per-path asyncio lock. Preserveensure_ascii=Trueandindent=2; a temporary file is replaced only after a complete write. No new dependencies or schema changes.Validation
6d90d84e55d508fcb52ea19f3912de6f6a477e38: serialization and injected one-byte-then-ENOSPC regressions damage the old file as expected. The new replace-failure test also fails on baseline because the old implementation does not use replacement.python -m pytest tests/utils/test_stats.py tests/utils/test_atomic_file.py -q: 9 passed.python -m pytest tests/utils -q: 151 passed, 30 subtests passed, 1 failed. The failure is the existing transcript-path expectation inTestAgentToolTranscript::test_save_transcript_writes_message_objects_and_dicts; independently reproduced with unchanged stats.py. It expects<output>/subagents/...rather than the implementation's.ms_agent/subagents/....git diff --check: passed.Tests use real temporary files and call production
append_stats; the ENOSPC fault wraps both legacyopenand atomic-helperfdopenwriters, writes one actual byte and then raises. They verify the old file remains byte-for-byte unchanged, temporary files are removed, and the next successful append preserves previous records.Limits
No live agent/model calls or full project suite. Existing datetime.utcnow deprecation warnings remain. This does not add multi-process locking or fsync/power-loss durability guarantees; it retains the helper's existing behavior. Existing unreadable-history reset behavior is unchanged.
AI-assisted implementation and automated review; draft for maintainer review, without a claim of human review.
Checklist
The final local commit did not rerun hooks: the default cache was read-only, so it used the already-passing explicit cached changed-file check. An initial mistyped cache path began environment initialization and was stopped; it is not a passing check. No new dependency or workflow configuration is included.