tooling(backfill): raise MAX_MESSAGES cap, surface truncation#37
Open
heavygee wants to merge 1 commit into
Open
tooling(backfill): raise MAX_MESSAGES cap, surface truncation#37heavygee wants to merge 1 commit into
heavygee wants to merge 1 commit into
Conversation
The old hardcoded MAX_MESSAGES=2000 silently dropped the tail of any
transcript with more than 2k records. Hit this concretely on a 2974-line
chat: 974 lines lost with zero indication in either the script output or
the wrapper script's report.
Changes:
- Default cap raised to 50_000 (covers all real chats sampled; 30MB jsonl
is well within import-once memory budget).
- Override via --max-messages <N> CLI arg on both backfill-agent-transcript.ts
and attach-agent-chat.ts (forwarded), and via HAPI_BACKFILL_MAX_MESSAGES env.
- BackfillResult now returns { rawTranscriptLines, maxMessagesApplied,
truncated } so callers can detect drops without re-parsing.
- backfill-agent-transcript.ts emits a console.warn line when truncating.
- attach-agent-chat.ts surfaces a prominent "BACKFILL TRUNCATED" warning
at the end of the report (after the JSON dump, before the prompt
returns) so the operator sees it even if buried mid-output.
- New countTranscriptRecords() helper kept exported for callers that want
the raw count without paying for full parsing.
Test coverage:
- New test: backfillSessionMessages flags truncated=true when transcript
exceeds --max-messages cap, with correct rawTranscriptLines/maxMessagesApplied.
- New test: truncated=false on a single-line transcript.
- Existing 8 tests still pass (10 total).
Co-authored-by: Cursor <cursoragent@cursor.com>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
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
The old hardcoded
MAX_MESSAGES = 2000silently dropped the tail of any transcript with more than 2k records. Hit this concretely on a 2974-line chat (jessica-story founding chat): 974 lines lost with zero indication in either the script output or the wrapper's report.Changes
50_000(covers all real chats sampled; 30MB jsonl import is well within memory budget for a one-time per-session ingest).--max-messages <N>CLI arg on bothbackfill-agent-transcript.tsandattach-agent-chat.ts(forwarded), and viaHAPI_BACKFILL_MAX_MESSAGESenv.BackfillResultnow returns{ rawTranscriptLines, maxMessagesApplied, truncated }so callers can detect drops without re-parsing.backfill-agent-transcript.tsemits aconsole.warnline when truncating.attach-agent-chat.tssurfaces a prominentBACKFILL TRUNCATEDwarning at the end of the report (after the JSON dump) so the operator sees it even if it would otherwise be buried mid-output.countTranscriptRecords()helper exported for callers that want the raw count without paying for full parsing.Why this matters for #34 (ACP migration)
A lossy backfill produces a HAPI session whose
messagestable has incomplete scrollback. If you then migrate that session to ACP via #34's transplant, the in-storestore.dbcontent is unchanged (so the agent's brain is fine), but the HAPI hub/web UI scrollback is missing the tail. Reviewers can't audit what the agent did before migration. This fix makes backfill non-lossy by default so post-migration audit is trustworthy.Test plan
backfillSessionMessages flags truncated=true when transcript exceeds --max-messages cap, with correctrawTranscriptLines/maxMessagesApplied.truncated=falseon a single-line transcript.console.warnwrites to stderr and doesn't break stdout-as-JSON parsing for any wrapper script that pipes throughjq.Companion branch
tooling/legacy-chat-acp-alignment(#36) — adds the post-attach ACP migration hint and commits the operator-authoredhapi-resurrect-session.sh. Together these two branches close the find→attach→backfill→resurrect→migrate loop for #34.Made with Cursor