# Explicit Continuation Done-Gate Bypass

## Current Design

- Jira is the canonical source for issue update time, comment visibility,
  author identity, body, and structured ADF mention account IDs.
- The continuation poller builds a JQL query over recently updated issues, then
  fetches the complete paginated JSM/platform comment timeline for each result.
- The JQL currently contains `statusCategory != Done`, so comments added after
  an issue is resolved or closed are never fetched and cannot become jobs.
- For comments that are fetched, `evaluateContinuationComment` accepts only an
  internal, non-bot-authored, bounded comment with an exact structured mention
  of the authenticated bot account.
- `auto_oncall_jobs` is the canonical queue and deduplicates continuation turns
  by source comment ID. The worker already bypasses L1 Oncaller and Enabled
  Coverage filtering for a valid continuation and writes only an internal Jira
  response.

## Risks

- Removing the Done filter broadens discovery to recently updated closed issues;
  invalid comments must still fail trigger validation before enqueue.
- A plain-text `@name`, public comment, wrong-account mention, bot-authored
  comment, empty comment, or oversized comment must not gain a bypass.
- Overlap polling must remain idempotent so one source comment cannot create
  duplicate jobs or Jira responses.
- Explicit invocation must not bypass safety classification, internal-only
  delivery, payload bounds, or the prohibition on production operations.

## Target Contract

- An exact internal ADF `@bot` mention is an explicit human invocation on both
  active and Done issues.
- Continuation discovery is based on the configured project scope and issue
  update time; it does not filter by Jira status category or the autonomous
  issue allowlist.
- Autonomous initial polling keeps its existing Done Gate and all other poller
  and worker gates unchanged.
- A continuation bypasses autonomous business gates only after trigger validity
  checks pass. Trigger validity, safety classification, bounded context,
  idempotency, internal-only delivery, and no-production-operation invariants
  remain mandatory.
- No alternate mention parser, webhook, status transition, customer-visible
  reply, or compatibility fallback is introduced.

## Implementation Steps

1. Add a local JQL contract test proving continuation discovery has no Done or
   issue-allowlist filter while initial discovery still has both.
2. Extend the continuation poller test with a resolved issue and prove its exact
   internal ADF mention enqueues once across overlapping polls.
3. Remove only the continuation status-category clause and update the repository
   continuation contract documentation.
4. Run focused tests, typecheck/build, full tests, and diff checks.
5. Open and merge the repository PR after CI passes.
6. Build the merged staging image, merge the generated app-delivery image PR,
   and wait for the staging Deployment to run the merged image.
7. Add one non-bot internal ADF mention to ST-2817 and verify Jira, DB, logs,
   and the live image end to end.

## Verification Checklist

- [x] Initial JQL still contains `statusCategory != Done`.
- [x] Continuation JQL does not contain a status-category filter.
- [x] Continuation JQL ignores the autonomous issue allowlist.
- [x] A resolved issue with an exact internal ADF mention enqueues one
      continuation job.
- [x] Repeated polling does not duplicate the resolved-issue continuation job.
- [x] Public, text-only, wrong-account, bot-authored, empty, and oversized
      comments remain ineligible.
- [x] Worker continuation still preserves safety classification and writes
      internal-only after autonomous business-gate bypass.
- [x] Focused tests, typecheck/build, full tests, and `git diff --check` pass.
- [x] Repository PR is merged after CI passes.
- [x] Staging Deployment runs the merged image and remains Ready while prod
      automation remains disabled.
- [x] A new ST-2817 internal ADF mention creates one continuation job and one
      internal Jira response, verified by source comment ID.

## Rollout Evidence

- Repository PR: `tidbcloud/aisupport#356`, merge commit
  `5a1e0af35f11aa08d61e3d1f8a947971c37637f6`.
- Staging app-delivery PR: `tidbcloud/app-delivery#74824`, merge commit
  `f84a1bacf58591c6c56e9d0fd668079b4f9e9b09`.
- Staging Deployment reached Ready with image
  `aisupport/staging/auto-oncall-services:5a1e0af35f11aa08d61e3d1f8a947971c37637f6`.
- ST-2817 remained `Resolved`; non-bot internal ADF mention `23202470`
  automatically created continuation job `60101`, succeeded once, and wrote
  bot internal response `23202484` with DB idempotency key
  `auto-live:v1:ST-2817:continuation:23202470`.
- The prod template remains `AUTO_ONCALL_AUTOMATION_ROLE=disabled`,
  `AUTO_ONCALL_POLL_ENABLED=false`, and
  `AUTO_ONCALL_CONTINUATION_ENABLED=false`; no prod Deployment was present.

## Out of Scope

- No production cutover, customer-visible reply, Jira transition, production
  operation, secret-model change, persistence schema change, or report change.
- No change to initial-job gates or fallback mention matching.
