-
Notifications
You must be signed in to change notification settings - Fork 0
Implement GNAT Phase 4: Control, Reasoning, Safety #93
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
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
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,46 @@ | ||
| """Add execution_log table (Phase 4A). | ||
|
|
||
| Append-only audit log for all GNAT operations. Every pipeline run, | ||
| enrichment call, connector request, and agent action writes one row. | ||
|
|
||
| Revision ID: 0004 | ||
| Revises: 0003 | ||
| Create Date: 2026-04-08 00:00:04.000000 | ||
|
|
||
| """ | ||
| from __future__ import annotations | ||
|
|
||
| import sqlalchemy as sa | ||
| from alembic import op | ||
|
|
||
| revision = "0004" | ||
| down_revision = "0003" | ||
| branch_labels = None | ||
| depends_on = None | ||
|
|
||
|
|
||
| def upgrade() -> None: | ||
| op.create_table( | ||
| "execution_log", | ||
| sa.Column("context_id", sa.String(36), primary_key=True), | ||
| sa.Column("initiated_by", sa.String(128), nullable=False), | ||
| sa.Column("domain", sa.String(32), nullable=False, index=True), | ||
| sa.Column("trust_level", sa.String(32), nullable=False, index=True), | ||
| sa.Column("policy_set", sa.String(64), nullable=False, server_default="default"), | ||
| sa.Column("workspace_id", sa.String(256), nullable=False), | ||
| sa.Column("created_at", sa.DateTime(timezone=True), nullable=False, index=True), | ||
| sa.Column("parent_context_id", sa.String(36), nullable=True), | ||
| sa.Column("is_replay", sa.Boolean, nullable=False, server_default="0"), | ||
| sa.Column("event_type", sa.String(64), nullable=True), # "security_event", "replay_event", etc. | ||
| sa.Column("notes", sa.Text, nullable=True), | ||
| ) | ||
| op.create_index( | ||
| "ix_execution_log_workspace_domain", | ||
| "execution_log", | ||
| ["workspace_id", "domain"], | ||
| ) | ||
|
|
||
|
|
||
| def downgrade() -> None: | ||
| op.drop_index("ix_execution_log_workspace_domain", "execution_log") | ||
| op.drop_table("execution_log") | ||
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,44 @@ | ||
| """Add idempotency_key to workspace_objects (Phase 4B). | ||
|
|
||
| Enables safe pipeline replay: re-ingesting the same STIX object produces | ||
| a single stored row with a logged replay_event rather than a duplicate. | ||
|
|
||
| Revision ID: 0005 | ||
| Revises: 0004 | ||
| Create Date: 2026-04-08 00:00:05.000000 | ||
|
|
||
| """ | ||
| from __future__ import annotations | ||
|
|
||
| import sqlalchemy as sa | ||
| from alembic import op | ||
|
|
||
| revision = "0005" | ||
| down_revision = "0004" | ||
| branch_labels = None | ||
| depends_on = None | ||
|
|
||
|
|
||
| def upgrade() -> None: | ||
| with op.batch_alter_table("workspace_objects") as batch_op: | ||
| batch_op.add_column( | ||
| sa.Column( | ||
| "idempotency_key", | ||
| sa.String(255), | ||
| nullable=True, | ||
| unique=False, | ||
| ) | ||
| ) | ||
| op.create_index( | ||
| "ix_workspace_objects_idempotency", | ||
| "workspace_objects", | ||
| ["idempotency_key"], | ||
| unique=True, | ||
| postgresql_where=sa.text("idempotency_key IS NOT NULL"), | ||
| ) | ||
|
|
||
|
|
||
| def downgrade() -> None: | ||
| op.drop_index("ix_workspace_objects_idempotency", "workspace_objects") | ||
| with op.batch_alter_table("workspace_objects") as batch_op: | ||
| batch_op.drop_column("idempotency_key") | ||
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,52 @@ | ||
| """Add agent_sessions and agent_actions tables (Phase 4D). | ||
|
|
||
| Postgres-backed agent memory and audit trail. All agent actions | ||
| pass through AgentGovernor which writes here for complete auditability. | ||
|
|
||
| Revision ID: 0006 | ||
| Revises: 0005 | ||
| Create Date: 2026-04-08 00:00:06.000000 | ||
|
|
||
| """ | ||
| from __future__ import annotations | ||
|
|
||
| import sqlalchemy as sa | ||
| from alembic import op | ||
|
|
||
| revision = "0006" | ||
| down_revision = "0005" | ||
| branch_labels = None | ||
| depends_on = None | ||
|
|
||
|
|
||
| def upgrade() -> None: | ||
| op.create_table( | ||
| "agent_sessions", | ||
| sa.Column("session_id", sa.String(36), primary_key=True), | ||
| sa.Column("agent_id", sa.String(128), nullable=False, index=True), | ||
| sa.Column("created_at", sa.DateTime(timezone=True), nullable=False), | ||
| sa.Column("context_id", sa.String(36), nullable=True), # FK to execution_log.context_id | ||
| sa.Column("state_json", sa.Text, nullable=True), | ||
| ) | ||
|
|
||
| op.create_table( | ||
| "agent_actions", | ||
| sa.Column("action_id", sa.String(36), primary_key=True), | ||
| sa.Column("agent_id", sa.String(128), nullable=False, index=True), | ||
| sa.Column("session_id", sa.String(36), nullable=True), # FK to agent_sessions | ||
| sa.Column("action_type", sa.String(64), nullable=False), | ||
| sa.Column("target_ref", sa.String(256), nullable=True), | ||
| sa.Column("impact_level", sa.String(16), nullable=False, server_default="low"), # low/medium/high/critical | ||
| sa.Column("approved_by", sa.String(128), nullable=True), | ||
| sa.Column("executed_at", sa.DateTime(timezone=True), nullable=True), | ||
| sa.Column("result_json", sa.Text, nullable=True), | ||
| sa.Column("submitted_at", sa.DateTime(timezone=True), nullable=False), | ||
| sa.Column("status", sa.String(32), nullable=False, server_default="pending"), # pending/approved/rejected/executed | ||
| ) | ||
| op.create_index("ix_agent_actions_agent_status", "agent_actions", ["agent_id", "status"]) | ||
|
|
||
|
|
||
| def downgrade() -> None: | ||
| op.drop_index("ix_agent_actions_agent_status", "agent_actions") | ||
| op.drop_table("agent_actions") | ||
| op.drop_table("agent_sessions") | ||
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,44 @@ | ||
| """Add trust_boundary and allowed_connector_refs to workspaces (Phase 4E). | ||
|
|
||
| Enables workspace isolation: connectors whose TRUST_LEVEL is below the | ||
| workspace's trust_boundary are rejected at instantiation time. | ||
|
|
||
| Revision ID: 0007 | ||
| Revises: 0006 | ||
| Create Date: 2026-04-08 00:00:07.000000 | ||
|
|
||
| """ | ||
| from __future__ import annotations | ||
|
|
||
| import sqlalchemy as sa | ||
| from alembic import op | ||
|
|
||
| revision = "0007" | ||
| down_revision = "0006" | ||
| branch_labels = None | ||
| depends_on = None | ||
|
|
||
|
|
||
| def upgrade() -> None: | ||
| with op.batch_alter_table("workspaces") as batch_op: | ||
| batch_op.add_column( | ||
| sa.Column( | ||
| "trust_boundary", | ||
| sa.String(32), | ||
| nullable=False, | ||
| server_default="semi_trusted", | ||
| ) | ||
| ) | ||
| batch_op.add_column( | ||
| sa.Column( | ||
| "allowed_connector_refs", | ||
| sa.Text, # JSON array of connector class names; NULL = all allowed | ||
| nullable=True, | ||
| ) | ||
| ) | ||
|
|
||
|
|
||
| def downgrade() -> None: | ||
| with op.batch_alter_table("workspaces") as batch_op: | ||
| batch_op.drop_column("allowed_connector_refs") | ||
| batch_op.drop_column("trust_boundary") | ||
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,40 @@ | ||
| """Add query_cost_log table (Phase 4E). | ||
| Tracks per-connector query cost for capacity planning and budget enforcement. | ||
| Revision ID: 0008 | ||
| Revises: 0007 | ||
| Create Date: 2026-04-08 00:00:08.000000 | ||
| """ | ||
| from __future__ import annotations | ||
|
|
||
| import sqlalchemy as sa | ||
| from alembic import op | ||
|
|
||
| revision = "0008" | ||
| down_revision = "0007" | ||
| branch_labels = None | ||
| depends_on = None | ||
|
|
||
|
|
||
| def upgrade() -> None: | ||
| op.create_table( | ||
| "query_cost_log", | ||
| sa.Column("id", sa.Integer, primary_key=True, autoincrement=True), | ||
| sa.Column("connector_id", sa.String(128), nullable=False, index=True), | ||
| sa.Column("cost_units", sa.Integer, nullable=False), | ||
| sa.Column("context_id", sa.String(36), nullable=True), # FK to execution_log | ||
| sa.Column("operation", sa.String(64), nullable=True), # "bulk_pull", "lookup", "search" | ||
| sa.Column("timestamp", sa.DateTime(timezone=True), nullable=False, index=True), | ||
| ) | ||
| op.create_index( | ||
| "ix_query_cost_connector_ts", | ||
| "query_cost_log", | ||
| ["connector_id", "timestamp"], | ||
| ) | ||
|
|
||
|
|
||
| def downgrade() -> None: | ||
| op.drop_index("ix_query_cost_connector_ts", "query_cost_log") | ||
| op.drop_table("query_cost_log") | ||
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.
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.
This migration creates a unique index on idempotency_key alone, making the key globally unique across all workspace_objects rows. That can block identical content ingests into different workspaces and can interact badly with the current upsert_object() idempotency pre-check (which is also not scoped to workspace_id). Consider enforcing uniqueness on (workspace_id, idempotency_key) instead (or include workspace_id in the key format).