Skip to content

Simplify operational tooling and runbooks#62

Merged
BigSimmo merged 9 commits into
mainfrom
copilot/simplify-operational-tooling
Jun 26, 2026
Merged

Simplify operational tooling and runbooks#62
BigSimmo merged 9 commits into
mainfrom
copilot/simplify-operational-tooling

Conversation

Copilot AI commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Recovery scripts emitted raw JSON, required manual --apply flags with no interactive guidance, and the reindex runbook demanded 8+ hand-executed steps in strict order — all friction that increases operational error risk.

Changes

scripts/cli-utils.ts (new)

Shared confirm() utility using Node.js readline — single source for interactive yes/no prompts.

scripts/recover-ingestion-queue.ts

  • Replaces JSON dump with aligned human-readable summary (scanned jobs, resets, supersedes, retries)
  • Adds interactive confirmation prompt before any mutations when --apply is absent
  • --yes skips the prompt for CI/piped use; --apply remains backward-compatible
=== Ingestion Queue Recovery ===
Checking Supabase health...
  Supabase is healthy.

Stale-after threshold : 45 min
Action limit          : 20
Scanned jobs          : 5
Documents to reset    : 2
Jobs to supersede     : 1
Jobs to retry         : 1

Apply these changes? (y/N)

scripts/supabase-recovery-status.ts

Replaces JSON dump with a readable dashboard: status, checked-at, count table, any read errors, and a plain-English recommendation line.

scripts/reindex.ts + npm run reindex (new)

Consolidated pipeline that replaces the 8-step manual runbook:

  1. Confirms target Supabase project ref
  2. Probes Supabase health
  3. Snapshots reindex health (document/job counts)
  4. Applies queue recovery if stale/failed jobs present (interactive prompt)
  5. Runs worker:once
  6. Repeats until queue is clear or --max-rounds is reached

Flags: --yes (non-interactive), --max-rounds N (default 10), --limit N (recovery actions/round, default 20).

docs/reindex-runbook.md

Documents npm run reindex as the primary path with a flags table; retains the manual sequence for reference.

Verification

  • npm run verify:cheap
  • npm run verify:ui when UI, routing, styling, browser behavior, reduced-motion, or forced-colors behavior changed
  • npm run verify:release before release or handoff confidence claims
  • npm run format:check
  • npm run check:production-readiness when clinical workflow, privacy, environment, Supabase, source governance, or deployment behavior changed

Clinical Governance Preflight

Complete this section when the change touches ingestion, answer generation, search/ranking, source rendering, document access, privacy, production env, or clinical output.

  • Source-backed claims still require linked source verification before clinical use
  • No patient-identifiable document workflow was introduced or expanded without explicit governance approval
  • Supabase target remains Clinical KB Database (sjrfecxgysukkwxsowpy)
  • Service-role keys and private document access remain server-only
  • Demo/synthetic content remains clearly separated from real clinical sources
  • Source metadata, review status, and outdated/unknown-source behavior remain conservative
  • Deployment classification/TGA SaMD impact was checked when clinical decision-support behavior changed

Notes

  • RawJobRow type is kept inline per-script (it maps a Supabase query shape, not a domain type) rather than promoted to @/lib/ingestion-recovery
  • No mutations to core ingestion logic; all changes are to operator-facing CLI scripts

- recover-ingestion-queue.ts: replace JSON output with human-readable
  summary; add interactive confirmation prompt (--yes / --apply to skip);
  extract confirm() to shared cli-utils.ts
- supabase-recovery-status.ts: replace JSON output with readable dashboard
- scripts/reindex.ts: new consolidated pipeline command that encapsulates
  the full reindex runbook (health check, recovery, worker, repeat)
- package.json: add 'reindex' npm script
- docs/reindex-runbook.md: document the new npm run reindex command
Copilot AI changed the title [WIP] Simplify operational tooling and runbooks Simplify operational tooling and runbooks Jun 23, 2026
Copilot AI requested a review from BigSimmo June 23, 2026 04:57
@BigSimmo
BigSimmo marked this pull request as ready for review June 23, 2026 05:55

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c559343bf0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread scripts/reindex.ts
Comment thread scripts/reindex.ts Outdated
Comment thread scripts/reindex.ts Outdated
Comment thread scripts/cli-utils.ts
Copilot AI review requested due to automatic review settings June 26, 2026 05:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a7393deefb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread scripts/reindex.ts
Comment thread scripts/reindex.ts Outdated
Comment thread scripts/reindex.ts Outdated
Comment thread scripts/reindex.ts Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6735eea7fc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread scripts/reindex.ts Outdated
Comment thread scripts/reindex.ts Outdated
Copilot AI review requested due to automatic review settings June 26, 2026 06:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI review requested due to automatic review settings June 26, 2026 07:50
@BigSimmo
BigSimmo merged commit 17fb704 into main Jun 26, 2026
5 checks passed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 6 comments.

Comment thread scripts/reindex.ts
Comment on lines +41 to +44
const child = spawn("npx", ["tsx", "worker/index.ts", "--once"], {
stdio: "inherit",
shell: false,
});
Comment thread scripts/reindex.ts
Comment on lines +251 to +270
const staleAfterCutoff = new Date(staleCutoff);
const jobs = (data ?? [])
.map((job: RawJobRow) => ({
...job,
documents: Array.isArray(job.documents)
? (job.documents[0] as RecoveryDocument | undefined)
: (job.documents as RecoveryDocument | undefined),
}))
.filter((job) => {
if (job.status === "failed") {
return true;
}
if (job.status !== "processing") {
return false;
}
if (job.locked_at === null) {
return true;
}
return new Date(job.locked_at) <= staleAfterCutoff;
});
Comment thread scripts/cli-utils.ts
Comment on lines +15 to +18
rl.question(`${question} (y/N) `, (answer: string) => {
rl.close();
resolve(answer.trim().toLowerCase() === "y");
});
Comment thread eslint.config.mjs
Comment on lines +21 to +24
".claude/**",
"**/.claude/**",
".tmp-visual/**",
"**/.tmp-visual/**",
Comment thread docs/reindex-runbook.md
Comment on lines 34 to 37
3. Apply any pending local migration only after the probe succeeds.
4. Run `npm run reindex:health`.
5. If stale or failed jobs exist, run `npm run recover:ingestion -- --apply --limit 20`.
5. If stale or failed jobs exist, run `npm run recover:ingestion` and confirm the prompt.
6. Run `npm run worker:once` with the conservative defaults from `.env.example`.
Comment thread scripts/reindex.ts
Comment on lines +89 to +92
const args = parseArgs(process.argv.slice(2));
const staleAfterMinutes = env.WORKER_STALE_AFTER_MINUTES;
const limit = args.limit;

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d7d3b464dc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread scripts/reindex.ts
Comment on lines +378 to +382
if (hasActiveProcessingJobs) {
console.log(
"\n Active processing jobs detected; skipping worker run to avoid concurrency spikes.",
);
continue;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Do not spend worker rounds while waiting

When a fresh processing job exists, this new guard immediately continues into the next loop iteration and counts it against --max-rounds without sleeping or running a worker. Because the runbook documents --max-rounds as the maximum worker iterations, npm run reindex -- --yes --max-rounds 5 can burn all five rounds in seconds and exit 1 while another worker is still making normal progress. Return with an operator message, or wait/back off without consuming a worker round.

Useful? React with 👍 / 👎.

Comment thread docs/reindex-runbook.md
## Safe sequence
## Consolidated pipeline command

The quickest way to run a full reindex cycle is the consolidated pipeline command:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Queue documents before calling this a full reindex

In the common release case where all documents are already indexed and there are no open ingestion_jobs, scripts/reindex.ts hits its queue-clear check and exits successfully without enqueueing any document for the new indexing code. Since this runbook is specifically for applying RAG indexing changes, describing npm run reindex as a full reindex cycle can leave the corpus on the old chunks/enrichment while operators proceed to evals; either add an enqueue step/command or label this as draining an already queued reindex.

Useful? React with 👍 / 👎.

Comment thread scripts/reindex.ts
Comment on lines +41 to +44
const child = spawn("npx", ["tsx", "worker/index.ts", "--once"], {
stdio: "inherit",
shell: false,
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Run the worker with recovery-safe concurrency

When WORKER_CONCURRENCY is not set in the environment, the worker spawned here falls back to the code default of 8 and processes the claimed jobs concurrently, while the recovery runbook/.env.example expect concurrency 1 for this operation. In that environment, npm run reindex -- --yes can fan out eight document reindexes during a supposedly conservative recovery run; set a safe env override for this child process or fail until conservative worker settings are present.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants