2020import { RemovalPolicy } from 'aws-cdk-lib' ;
2121import * as dynamodb from 'aws-cdk-lib/aws-dynamodb' ;
2222import { Construct } from 'constructs' ;
23+ import { JIRA_ISSUE_INDEX_NAME } from './task-table-indexes' ;
24+
25+ export { JIRA_ISSUE_INDEX_NAME } from './task-table-indexes' ;
2326
2427/**
2528 * Properties for TaskTable construct.
@@ -47,13 +50,15 @@ export interface TaskTableProps {
4750/**
4851 * DynamoDB table for persisting task state across the agent lifecycle.
4952 *
50- * Schema: task_id (PK) with three GSIs for querying by user+status,
51- * by status (queue processing), and by idempotency key (dedup).
53+ * Schema: task_id (PK) with GSIs for querying by user+status, by status
54+ * (queue processing), by idempotency key (dedup), and by Jira issue .
5255 *
5356 * GSIs:
5457 * - UserStatusIndex (PK: user_id, SK: status_created_at) — "my tasks" queries
5558 * - StatusIndex (PK: status, SK: created_at) — queue processing, monitoring
5659 * - IdempotencyIndex (PK: idempotency_key) — sparse index for dedup
60+ * - JiraIssueIndex (PK: jira_issue_identity, SK: created_at) — sparse index
61+ * for resolving a Jira issue to its newest PR-producing task
5762 */
5863export class TaskTable extends Construct {
5964 /**
@@ -74,6 +79,12 @@ export class TaskTable extends Construct {
7479 */
7580 public static readonly IDEMPOTENCY_INDEX = 'IdempotencyIndex' ;
7681
82+ /**
83+ * GSI for resolving a tenant-scoped Jira issue to its newest ABCA task.
84+ * PK: jira_issue_identity (`{cloudId}#{issueKey}`), SK: created_at.
85+ */
86+ public static readonly JIRA_ISSUE_INDEX = JIRA_ISSUE_INDEX_NAME ;
87+
7788 /**
7889 * The underlying DynamoDB table. Use this to grant access or read the table name.
7990 */
@@ -118,5 +129,16 @@ export class TaskTable extends Construct {
118129 partitionKey : { name : 'idempotency_key' , type : dynamodb . AttributeType . STRING } ,
119130 projectionType : dynamodb . ProjectionType . KEYS_ONLY ,
120131 } ) ;
132+
133+ // Sparse: only Jira-origin tasks with issue metadata carry the top-level
134+ // jira_issue_identity attribute. Keep the projection limited to fields the
135+ // comment-trigger resolver needs.
136+ this . table . addGlobalSecondaryIndex ( {
137+ indexName : TaskTable . JIRA_ISSUE_INDEX ,
138+ partitionKey : { name : 'jira_issue_identity' , type : dynamodb . AttributeType . STRING } ,
139+ sortKey : { name : 'created_at' , type : dynamodb . AttributeType . STRING } ,
140+ projectionType : dynamodb . ProjectionType . INCLUDE ,
141+ nonKeyAttributes : [ 'pr_url' , 'pr_number' , 'status' , 'repo' , 'user_id' , 'channel_metadata' ] ,
142+ } ) ;
121143 }
122144}
0 commit comments