fix(weka): guarantee trailing-user turns; drop raw-payload re-validation + fix batch-flush shutdown loss#12
Merged
cquil11 merged 2 commits intoJun 30, 2026
Conversation
Reconstructed weka turns could end with a trailing assistant segment when a block-aligned context pull-back truncated onto an assistant block (376/98,827 turns on the 062126 corpus). A chat request must end with a user message. Add compute_asst_block_caps: a role-independent forward pass that finds every degenerate pull-back's truncation target and caps the assistant block count of the turn that created that block, so the boundary lands on a user block. The boundary is fixed at creation and never relabeled, preserving cross-turn KV-cache reuse. Wire the cap into all five reconstruction loops (serial parent/child/flat-chain + parallel parent/child). Extract compute_turn_block_geometry as the single source of truth advance_turn and the planner share; the planner mutates its block tile in place to stay O(new) per turn. Drives trailing-assistant turns to 0 across the full 393-trace corpus with no crashes; byte-exact sum(seg.tokens)==in_tokens preserved. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Anthony Casagrande <acasagrande@nvidia.com>
…sh shutdown loss Remove the per-send orjson.loads round-trip in InferenceClient and the per-record orjson.loads validation in RawRecordWriterProcessor. payload_bytes are validated at dataset-load time (or produced by orjson.dumps), so re-parsing every request/record only reintroduces the decode cost the verbatim / orjson.Fragment paths exist to avoid. Invalid bytes now forward/splice verbatim. Also fix a pre-existing shutdown data-loss race: RawRecordWriterProcessor's batch-trigger flush task was scheduled via execute_async without being registered in _flush_tasks, so _stop_all_tasks cancelled it before _close_file awaited it, losing the whole batch on stop. Register the task like the parent BufferedJSONLWriterMixin does. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Anthony Casagrande <acasagrande@nvidia.com>
Try out this PRQuick install: pip install --upgrade --force-reinstall git+https://github.com/ai-dynamo/aiperf.git@e165d787faa8ba8de34feb6e5e3525eaa33a82f0Recommended with virtual environment (using uv): uv venv --python 3.12 && source .venv/bin/activate
uv pip install --upgrade --force-reinstall git+https://github.com/ai-dynamo/aiperf.git@e165d787faa8ba8de34feb6e5e3525eaa33a82f0Last updated for commit: |
cec702b
into
SemiAnalysisAI:cquil11/agentx-v0.4-sync
1 of 2 checks passed
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.
Two independent fixes on top of
cquil11/agentx-v0.4-sync.1. Weka: guarantee trailing-user turns (
feat(weka))Reconstructed weka turns could end with a trailing
assistantsegment when a block-aligned context pull-back truncated onto an assistant block — 376 / 98,827 turns (0.38%) on the 062126 corpus. A chat request must end with a user message.compute_asst_block_caps: a role-independent forward pass that finds every degenerate pull-back's truncation target and caps the assistant block count of the turn that created that block, so the boundary lands on a user block. The boundary is fixed at creation and never relabeled → cross-turn KV-cache reuse preserved (relabel-after-emission would diverge the cached prefix).compute_turn_block_geometryas the single source of truthadvance_turnand the planner share; the planner mutates its block tile in place (O(new)/turn)._trailing_non_user_turns; none occur in the corpus.Validated on the full 393-trace corpus: trailing-assistant 376 → 0, 0 crashes, byte-exact
sum(seg.tokens) == in_tokenspreserved.2. Raw payload: drop per-record orjson re-validation + fix batch-flush shutdown loss (
fix(raw-payload))orjson.loadsround-trip inInferenceClientand the per-recordorjson.loadsvalidation inRawRecordWriterProcessor.payload_bytesare validated at dataset-load time (or produced byorjson.dumps), so re-parsing every request/record only reintroduced the decode cost the verbatim /orjson.Fragmentfast paths exist to avoid. Invalid bytes now forward/splice verbatim.RawRecordWriterProcessor's batch-trigger flush task was scheduled viaexecute_asyncwithout being registered in_flush_tasks, so_stop_all_taskscancelled it before_close_fileawaited it — losing the whole batch on stop. Now registered like the parentBufferedJSONLWriterMixin.Testing
uv run pytest tests/unit/dataset/loader/— green (new helper / cap / tool-shaping tests added).uv run pytest tests/unit/post_processors/test_raw_record_writer_adversarial.py— green (adversarial tests updated to verbatim-splice behavior; the batch-flush shutdown test now passes).uv run pytest tests/component_integration/dataset/test_raw_payload_replay_adversarial.py -m component_integration— green.Pre-existing unrelated failure, not touched here:
tests/unit/dataset/loader/test_weka_trace.py::test_flattened_fanout_logs_detection_summary(a log-string drift in code outside this change).🤖 Generated with Claude Code