feat: add table for session inbound events - #805
heerambavi1998 wants to merge 13 commits into
Conversation
🦋 Changeset detectedLatest commit: 3c19e60 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
bf84084 to
78506cf
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want higher recall? High effort reviews run extra passes and find more bugs. A team admin can switch effort levels in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 3c19e60. Configure here.
| .where('event_id', 'in', ids) | ||
| .execute(); | ||
| return firstCollidingEventId(events, new Set(rows.map(r => r.event_id))); | ||
| } |
There was a problem hiding this comment.
Positional string helper parameters
Low Severity
resolveCollidingEventId takes sessionId and turnId as two positional strings. New functions with more than one parameter of the same type need a single options object. A TurnKeys object is already built in the same insert path for assertTurnRunning.
Additional Locations (1)
Triggered by project rule: TrueForge review rules
Reviewed by Cursor Bugbot for commit 3c19e60. Configure here.


Summary
add table for session inbound events
Changes
durable session_inbound_events inbox + ISessionStore API (Postgres / SQLite / InMemory) for the upcoming session send-event path.
Table: session_inbound_events
PK: (session_id, event_id) — caller-minted monotonic ULID (same contract as session_event)
turn_id column is nullable (reserved for future session-scoped policies)
No idempotency_key, we will add this later if needed.
Event
SendTurnEventItem = user.tool_approval | user.tool_response. We will add approval policies later.
Store
insertSessionInboundEvents / listUnconsumedSessionInboundEvents / markSessionInboundEventsConsumed
Duplicate event_id → SessionInboundEventAlreadyExistsError
Cascades with deleteSession
How was this tested?
Store contract tests.
Checklist
pnpm build,pnpm test,pnpm typecheck,pnpm lint:ci, andpnpm format:checkpass locallypackages/trueforge-sdk,python/trueforge_sdk,.github/fern/openapi/openapi.json,docs/openapi.json) — fork PRs omit SDK regen; maintainers regenerate after merge.env.exampleupdated if configuration or behavior changedNote
Medium Risk
Adds session-store schema and write paths on the agent turn lifecycle with concurrency checks; no public HTTP surface yet, but incorrect consumption semantics could affect upcoming HITL flows.
Overview
Introduces a turn-scoped durable inbox for client→harness send events during the active tip (tool approvals/responses), separate from the turn event stream log.
Store contract:
ISessionStoregainsinsertTurnInboundEvents,listUnconsumedTurnInboundEvents, andmarkTurnInboundEventsConsumed. Payloads are validatedTurnInboundEventItem(user.tool_approval|user.tool_response). Inserts require a running tip; duplicate caller-mintedevent_idper(session_id, turn_id)raisesTurnEventAlreadyExistsError. Listing returns unconsumed rows ordered byevent_id; mark-consumed is idempotent for unknown/already-consumed ids.Persistence: New
turn_inbound_eventstable (PKsession_id,turn_id,event_id,consumed, partial index for unconsumed) with Postgres and SQLite migrations, wired through InMemory, Postgres, and SQLite session stores (transaction +assertTurnRunningon insert). Rows cascade on session delete.Tests: Shared store contract suite covers ordering, duplicates, terminal-turn rejection, turn isolation, session delete, and a freeze-vs-insert race.
OpenAPI package version bumps to 0.2.1; no new HTTP routes in this diff (store-only groundwork for a future
POST …/turns/{turn_id}/eventspath).Reviewed by Cursor Bugbot for commit 3c19e60. Bugbot is set up for automated code reviews on this repo. Configure here.