Repository navigation
Add tasks to the store: create a session and start its first run in one transaction - #215
Merged
Merged
Conversation
…ne transaction A task is work handed to an agent config: its content becomes the first message of a new session. createTask pins the agent version, creates the session, logs the content and readies the first inference item in one transaction, so a failure never leaves an empty session behind. The task is its own row (new tasks table, new migration) pointing at the session it started, so deferral can later add tasks that wait before they start. createSession and intake's started branch become shared helpers (insertSession, startRun), so createTask reuses their checks and locks instead of copying them. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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.
First of two stacked PRs for the task API. This one is the core schema, the Store port and the pg adapter. The api routes (
POST /v1/tasks,GET /v1/tasks/:id,POST /v1/tasks/:id/cancel) follow in a PR based on this one.What a task is
A task is work handed to an agent config: its content becomes the first message of a new session. Today that is "create a session, then send it a message", but as one transaction. The current two calls can fail between them and leave an empty session behind.
A task is its own row, not an alias for its session. Deferral will let a task wait before it starts, and a task cancelled while waiting never gets a session. In this PR every task starts the moment it is created, so
sessionIdis always set.Changes
TaskRef,CreateTaskRequest(namespace, agentConfigId, agentConfigVersion?, content, metadata?),Task.createTaskandgetTask.createTaskdoes everything in one transaction: check the config, pin its version, insert the session, log the content, ready the first inference item, insert the task.createSession's body and intake's "start a run" branch become helpers (insertSession,startRun) that all three methods share, so the archive lock and the run start aren't copied.20261027225858_add_tasks: the newtaskstable, with foreign keys to the pinned config version and to the session. The test pins the migration's hash.Decisions
contentis stored on the task as well as in the session log. A task that waits to start will need it before any session exists, and adding it later would leave the earlier tasks without it.metadatastays on the task. The session gets none.cancelledAtand no deferral columns yet. They come with deferral, when a task can actually be waiting.Tests
ArchivedError; unknown or foreign configs and versions are "unknown"; an invalid request is rejected. None of these leaves a session behindgetTaskreturning undefined for an unknown or foreign taskpnpm typecheck,pnpm format:checkandpnpm testpass.pg-postgres.test.ts, 103/103).🤖 Generated with Claude Code