Repository navigation
Conversation
`_clamp_verbatim()` (added with the history-import fix) only runs inside `to_evidence()`, i.e. the file-scan lane. Both live-capture lanes build `EvidenceInput` themselves and passed the source text through untouched: live_capture._hook_inputs verbatim=verbatim (hook payload) live_capture._capture_transcript verbatim=row.verbatim (host transcript) so a single pasted dump over `MAX_VERBATIM_CHARACTERS` raised `ValidationError: verbatim — String should have at most 1000000 characters` straight out of `capture_hook()`. The HTTP gate above it (`capture_handoff.MAX_PAYLOAD_BYTES`) deliberately accepts up to 8 MB, so the two limits left an ordinary-sized payload failing the turn: the hook contract is "202 whatever the gates decide, so a hook has nothing to print", and a raise here breaks it for the turn and everything the hook would have staged. Move the clamp next to `MAX_VERBATIM_CHARACTERS` in `imports/models.py` and have all three lanes call it. One function, not three copies, is also what keeps identity stable: `verbatim` is what `identity_text()` hashes, so a hook capture and the later transcript scan of the same words have to truncate to the same text or the turn is filed twice. The two remaining `EvidenceInput` sites are caller-supplied (`memory_additions` and the messages route); those should reject an oversized payload with a 4xx rather than silently keep the head, which is a separate decision and not changed here.
3 of 4 tasks
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.
这个 PR 修什么
_clamp_verbatim()是随历史导入修复一起进来的,但只挂在to_evidence()里 —— 也就是只覆盖了文件扫描这一条链路。live 采集的两条链路自己构造EvidenceInput,把源文本原样传了进去:live_capture._hook_inputsverbatim=verbatim(hook payload)live_capture._capture_transcriptverbatim=row.verbatim(宿主 transcript)于是一条超过
MAX_VERBATIM_CHARACTERS的粘贴会直接从capture_hook()里抛出来:而它上面的 HTTP 闸门(
capture_handoff.MAX_PAYLOAD_BYTES)有意放宽到 8 MB,两个限制之间就留出了一段"完全合法却不工作的输入"。hook 的契约是202 whatever the gates decide, so a hook has nothing to print—— 这里抛异常,丢掉的不止这一条 turn,还有这个 hook 本该 stage 的全部内容。改法
把截断函数从
imports/sources/common.py下沉到imports/models.py(挨着MAX_VERBATIM_CHARACTERS放),三条链路共用:common.py::to_evidence改用clamp_verbatim(本地那份_clamp_verbatim删掉,MAX_VERBATIM_CHARACTERS的导入也随之不再需要)live_capture.py的两处verbatim=各包一层为什么必须共用同一个函数,而不是各写一份:
verbatim正是identity_text()哈希的来源。hook 采集和稍后对同一段话的 transcript 扫描必须截出同一段文本,否则同一个 turn 会被当成两条记录写两次。函数的 docstring 里也写明了这一点。测试
在
tests/test_live_capture.py追加两个用例(沿用文件里已有的Home/_staged夹具):test_an_oversized_prompt_is_truncated_instead_of_failing_the_capture—— hook payload 路径test_an_oversized_transcript_line_is_truncated_instead_of_failing_the_capture—— Stop 读 transcript 路径都断言
CaptureOutcome.STAGED、len(verbatim) <= MAX_VERBATIM_CHARACTERS、且带truncated: original 1000005 chars标记。红 / 绿:
没有改的两处
memory_additions.py和memory_server/routes.py里还各有一处EvidenceInput,但它们的文本是调用方直接给的(client.add()/ messages 接口)。那里应该用一个明确的 4xx 拒绝超长输入,而不是悄悄留前半截 —— 静默截断等于替调用方丢数据。所以这次不动,留作单独决定。相关