Skip to content

fix #441: preserve long user prompts in event stream - #527

Open
rohantiwari9573 wants to merge 1 commit into
CraftOS-dev:devfrom
rohantiwari9573:fix/issue-441-long-prompt-processing
Open

rohantiwari9573 wants to merge 1 commit into
CraftOS-dev:devfrom
rohantiwari9573:fix/issue-441-long-prompt-processing

Conversation

@rohantiwari9573

@rohantiwari9573 rohantiwari9573 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

What

Long user messages are still saved to a file behind a pointer, as before; what changes is that the agent now reliably gets the original text back.

  • The pointer for a user message is typed ("[User message saved to a file] …") instead of the misleading "Action None completed. The output is too long…".
  • Before the turn decides, CraftBot reads the saved file back into the event stream, right after its pointer, in parts of at most 15,000 characters (under the 16,000-character inline limit, so nothing collapses them back into a pointer).
  • The read-back only accepts a file inside the session's storage (symlinks, junctions and .. resolved first), opens the resolved path, and checks length and SHA-256 against what was saved.
  • The router refuses to send a request that would carry a user-message pointer whose text was not read back.
  • If the text cannot be read back, or the request cannot fit the model's context window even after a fold, the run ends with one clear message; unprocessed messages are set aside so the next message works.
  • Large tool outputs keep their existing pointers and the grep_files / read_file retrieval.
  • The query refers to a long message instead of repeating it, so a new chat sends it once.

Why

A synced session sends only new events, so for a long message the model received only the pointer, not the request. The generated pointer instructed the agent to retrieve the saved content, but the available retrieval tools could not reliably return the complete original message. read_file truncated very long lines, while grep_files returned only matching lines.

How to test

  • pytest tests/test_long_user_messages.py tests/test_context_overflow_run_end.py -q
  • ruff check . and ruff format --check . (ruff 0.16.1)
  • python -m compileall -q app agent_core agents decorators skills

A fake model behind the real LLMInterface records the messages handed to the provider. With a 26,014-character message marked at its beginning, middle and end, it received all three markers exactly once in new chats, established chats, session and stateless continuations, and batches (upstream dev: none, in an established chat).

Results: 47 new tests pass (1 symlink test skips without the privilege to create symlinks), and 14 deliberate mutations are all caught. The full suite gives 4,976 passed, 1 failed, 41 skipped. The one failure, test_mini_browser_agent_integration.py::test_agent_md_copies_identical_and_mention_mini_browser, fails identically on unmodified dev.

Notes

  • Saved-file names now get a random suffix. This also fixes two large outputs saved in the same instant (e.g. parallel actions) overwriting each other.
  • read_file's 2,000-character line cut, and its endless paging on lines over 80,000 characters, still affect tool-output pointers; I can open a separate issue.
  • Not yet checked against a real model.

@zfoong

zfoong commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

@rohantiwari9573 Thank you for the contribution! Is this PR still a draft? By the way, we still need the file pointer to avoid large output action overflowing the event stream, but without the truncation causing context lost. Open for discussion.

@rohantiwari9573

rohantiwari9573 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor Author

@rohantiwari9573 Thank you for the contribution! Is this PR still a draft? By the way, we still need the file pointer to avoid large output action overflowing the event stream, but without the truncation causing context lost. Open for discussion.

@zfoong Thanks for the feedback. I’ve revised the implementation to preserve the file-pointer mechanism rather than keeping long user messages inline.
The updated approach retrieves the original message directly from its saved file before the agent processes it, validates the file’s path, length, and SHA-256 digest, and injects the recovered content in bounded chunks. It also prevents unresolved user-message pointers from being passed to the LLM, so retrieval failures are surfaced explicitly instead of silently processing incomplete input.
I’ve updated PR #527 with this revised implementation and its tests. Could you please take another look and let me know whether this approach addresses your concern, or whether you’d prefer a different retrieval design?
Thanks again for the guidance.

@rohantiwari9573
rohantiwari9573 force-pushed the fix/issue-441-long-prompt-processing branch from 95076ad to 4761d13 Compare November 19, 2026 20:12
@rohantiwari9573
rohantiwari9573 marked this pull request as ready for review November 20, 2026 07:49
…messages

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Rohan <rohantiwari166@gmail.com>
@rohantiwari9573
rohantiwari9573 force-pushed the fix/issue-441-long-prompt-processing branch from 4761d13 to 366a3ad Compare November 21, 2026 06:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants