-
Notifications
You must be signed in to change notification settings - Fork 0
Add atomic agent turn finalization #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
5d7499a
c74734c
7eb0db8
f41a68f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| ALTER TABLE turns ADD COLUMN reserved_response_id text; | ||
|
|
||
| -- Preserve response IDs already assigned to active turns before this | ||
| -- migration. Legacy active turns without one can reserve their response ID | ||
| -- during their first transactional finalization. | ||
| UPDATE turns | ||
| SET reserved_response_id = response_id | ||
| WHERE status IN ('pending', 'streaming') AND response_id IS NOT NULL; | ||
|
|
||
| CREATE TABLE turn_finalizations ( | ||
| turn_id text PRIMARY KEY REFERENCES turns(id) ON DELETE CASCADE, | ||
| tenant_id text NOT NULL, | ||
| owner_ref text NOT NULL, | ||
| agent_ref text NOT NULL, | ||
| idempotency_key text NOT NULL, | ||
| response_id text NOT NULL, | ||
| request_version smallint NOT NULL CHECK (request_version > 0), | ||
| request_digest bytea NOT NULL CHECK (octet_length(request_digest) = 32), | ||
| response jsonb NOT NULL, | ||
| response_digest bytea NOT NULL CHECK (octet_length(response_digest) = 32), | ||
| first_seq bigint NOT NULL CHECK (first_seq > 0), | ||
| last_seq bigint NOT NULL CHECK (last_seq >= first_seq - 1), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This foreign key uses the default |
||
| continuation_id text NOT NULL REFERENCES continuations(id) ON DELETE CASCADE, | ||
| created_at timestamptz NOT NULL DEFAULT now(), | ||
| UNIQUE (tenant_id, owner_ref, agent_ref, idempotency_key), | ||
| UNIQUE (tenant_id, agent_ref, response_id) | ||
| ); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Existing turns get
NULLhere, butfinalize_turnnow requiresreserved_response_idto equal the request response ID and PATCH no longer permits terminal statuses. Consequently, any pending/streaming turn already in production at migration time cannot be finalized or otherwise terminally transitioned, so it permanently occupies the active-turn slot. Please backfill/reserve response IDs for existing active turns or retain a compatible path for them.