Skip to content

[Feature]message level forking#504

Open
riturajFi wants to merge 19 commits intomemodb-io:devfrom
riturajFi:feat/message_level_forking
Open

[Feature]message level forking#504
riturajFi wants to merge 19 commits intomemodb-io:devfrom
riturajFi:feat/message_level_forking

Conversation

@riturajFi
Copy link
Copy Markdown
Contributor

@riturajFi riturajFi commented Mar 27, 2026

Why we need this PR?

This should close Issue (#317 )

This PR adds branch-aware session message handling so Acontext can represent and read message forks correctly across the API, Core service, and SDKs. It enables storing a message with an explicit parent, retrieving a single root-to-leaf branch path, and defaulting session reads to the latest branch when a session has forked history.

Describe your solution

  • Added parent_id support when storing messages through the Python and TypeScript SDKs.
  • Added leaf_id support when reading messages so clients can request a single branch path from root to a chosen leaf message.
  • Updated the API session service and repository to resolve branch paths with a recursive parent-chain query.
  • Changed the default session read behavior to prefer the latest leaf branch when a session contains forks.
  • Updated Core message processing to operate on branch paths instead of whole-session message lists.
  • Added branch-aware locking, buffering, and flush logic so concurrent inserts are serialized per branch rather than per session.
  • Extended task-context packing so the LLM sees parent linkage and branch metadata.
  • Added and updated tests across API, Core, Python SDK, and TypeScript SDK to cover the new branch behavior.

Implementation Tasks

Please ensure your pull request meets the following requirements:

  • Add parent_id support to message creation in the Python SDK and TypeScript SDK.
  • Add leaf_id support to message retrieval in the Python SDK and TypeScript SDK, including validation for invalid option combinations.
  • Implement branch-path lookup in the API repository and use it in session message reads.
  • Update Core message ingestion and flush handling to process branch paths instead of whole-session pending queues.
  • Propagate parent/branch metadata into task context and prompt packing.
  • Add or update tests for API, Core, Python SDK, and TypeScript SDK behavior.

Impact Areas

Which part of Acontext would this feature affect?

  • Client SDK (Python)
  • Client SDK (TypeScript)
  • Core Service
  • API Server
  • Dashboard
  • CLI Tool
  • Documentation
  • Other: message branching and session history semantics

Checklist

  • Open your pull request against the dev branch.
  • All tests pass in available continuous integration systems (e.g., GitHub Actions).
  • Tests are added or modified as needed to cover code changes.

@riturajFi riturajFi marked this pull request as ready for review March 27, 2026 10:58
@riturajFi riturajFi requested a review from a team as a code owner March 27, 2026 10:58
@riturajFi riturajFi marked this pull request as draft March 27, 2026 10:59
@riturajFi riturajFi changed the base branch from main to dev March 27, 2026 10:59
@riturajFi riturajFi force-pushed the feat/message_level_forking branch 3 times, most recently from 9cc627f to 94914c0 Compare March 31, 2026 17:26
@riturajFi riturajFi marked this pull request as ready for review April 1, 2026 12:01
@riturajFi
Copy link
Copy Markdown
Contributor Author

riturajFi commented Apr 1, 2026

@GenerQAQ @claude @gusye1234 I Would like your review on this

@riturajFi riturajFi changed the title Feat/message level forking [Feat]message level forking Apr 1, 2026
@riturajFi riturajFi changed the title [Feat]message level forking [Feature]message level forking Apr 1, 2026
@riturajFi riturajFi force-pushed the feat/message_level_forking branch from 94914c0 to b57c833 Compare April 1, 2026 19:34
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.

1 participant