-
Notifications
You must be signed in to change notification settings - Fork 601
feat(api): session attachment resource with protected mount, quotas, and sweep #5607
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ced0f87
doc(agent-workflows): add the stage 1 implementation plan and protocol
mmabrouk 9278976
feat(api): session attachment resource with protected mount, quotas, …
mmabrouk 0497a90
fix(api): harden the attachment create path and sweep after review
mmabrouk 9d2fece
chore(api): address CodeRabbit review and complete the UploadFile ali…
mmabrouk 2211563
chore(api): raise the per-session attachment count quota to 1,000
mmabrouk e1c4e5d
fix(api): raise the reference cap to 100 and harden the attachment pa…
mmabrouk 97d4367
chore(api): sync the lockfile with the puremagic cap
mmabrouk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
120 changes: 120 additions & 0 deletions
120
...s/databases/postgres/migrations/core_oss/versions/oss000000020_add_session_attachments.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| """add session attachments | ||
|
|
||
| Revision ID: oss000000020 | ||
| Revises: oss000000019 | ||
| Create Date: 2026-07-31 00:00:00.000000 | ||
|
|
||
| """ | ||
|
|
||
| from typing import Sequence, Union | ||
|
|
||
| from alembic import op | ||
| import sqlalchemy as sa | ||
|
|
||
|
|
||
| revision: str = "oss000000020" | ||
| down_revision: Union[str, None] = "oss000000019" | ||
| branch_labels: Union[str, Sequence[str], None] = None | ||
| depends_on: Union[str, Sequence[str], None] = None | ||
|
|
||
|
|
||
| def upgrade() -> None: | ||
| op.add_column( | ||
| "mounts", | ||
| sa.Column("purpose", sa.String(), nullable=True), | ||
| ) | ||
| op.create_table( | ||
| "session_attachments", | ||
| sa.Column("id", sa.UUID(as_uuid=True), nullable=False), | ||
| sa.Column("project_id", sa.UUID(as_uuid=True), nullable=False), | ||
| sa.Column("session_id", sa.String(), nullable=False), | ||
| sa.Column("mount_id", sa.UUID(as_uuid=True), nullable=False), | ||
| sa.Column("path", sa.String(), nullable=False), | ||
| sa.Column("filename", sa.String(), nullable=False), | ||
| sa.Column("media_type", sa.String(), nullable=False), | ||
| sa.Column("size", sa.BigInteger(), nullable=False), | ||
| sa.Column("kind", sa.String(), nullable=False), | ||
| sa.Column("state", sa.String(), nullable=False), | ||
| sa.Column("idempotency_key", sa.String(), nullable=False), | ||
| sa.Column("content_digest", sa.String(), nullable=False), | ||
| sa.Column("referenced_at", sa.TIMESTAMP(timezone=True), nullable=True), | ||
| sa.Column( | ||
| "created_at", | ||
| sa.TIMESTAMP(timezone=True), | ||
| server_default=sa.func.current_timestamp(), | ||
| nullable=True, | ||
| ), | ||
| sa.Column("updated_at", sa.TIMESTAMP(timezone=True), nullable=True), | ||
| sa.Column("deleted_at", sa.TIMESTAMP(timezone=True), nullable=True), | ||
| sa.Column("created_by_id", sa.UUID(as_uuid=True), nullable=True), | ||
| sa.Column("updated_by_id", sa.UUID(as_uuid=True), nullable=True), | ||
| sa.Column("deleted_by_id", sa.UUID(as_uuid=True), nullable=True), | ||
| sa.CheckConstraint( | ||
| "state IN ('pending', 'ready', 'deleting')", | ||
| name="ck_session_attachments_state", | ||
| ), | ||
| sa.CheckConstraint( | ||
| "kind IN ('image', 'audio', 'document', 'other')", | ||
| name="ck_session_attachments_kind", | ||
| ), | ||
| sa.ForeignKeyConstraint( | ||
| ["project_id"], | ||
| ["projects.id"], | ||
| ondelete="CASCADE", | ||
| ), | ||
| sa.ForeignKeyConstraint( | ||
| ["project_id", "mount_id"], | ||
| ["mounts.project_id", "mounts.id"], | ||
| ondelete="CASCADE", | ||
| ), | ||
| sa.PrimaryKeyConstraint("project_id", "id"), | ||
| sa.UniqueConstraint( | ||
| "project_id", | ||
| "session_id", | ||
| "idempotency_key", | ||
| name="uq_session_attachments_idempotency", | ||
| ), | ||
| ) | ||
| op.create_index( | ||
| "ix_session_attachments_session_state", | ||
| "session_attachments", | ||
| ["project_id", "session_id", "state"], | ||
| ) | ||
| op.create_index( | ||
| "ix_session_attachments_project_mount", | ||
| "session_attachments", | ||
| ["project_id", "mount_id"], | ||
| ) | ||
| op.create_index( | ||
| "ix_session_attachments_pending_created", | ||
| "session_attachments", | ||
| ["created_at"], | ||
| postgresql_where=sa.text("state IN ('pending', 'deleting')"), | ||
| ) | ||
| op.create_index( | ||
| "ix_session_attachments_ready_unreferenced", | ||
| "session_attachments", | ||
| ["created_at"], | ||
| postgresql_where=sa.text("state = 'ready' AND referenced_at IS NULL"), | ||
| ) | ||
|
|
||
|
|
||
| def downgrade() -> None: | ||
| op.drop_index( | ||
| "ix_session_attachments_ready_unreferenced", | ||
| table_name="session_attachments", | ||
| ) | ||
| op.drop_index( | ||
| "ix_session_attachments_pending_created", | ||
| table_name="session_attachments", | ||
| ) | ||
| op.drop_index( | ||
| "ix_session_attachments_session_state", | ||
| table_name="session_attachments", | ||
| ) | ||
| op.drop_index( | ||
| "ix_session_attachments_project_mount", | ||
| table_name="session_attachments", | ||
| ) | ||
| op.drop_table("session_attachments") | ||
| op.drop_column("mounts", "purpose") | ||
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.