Skip to content

fix(discovery): retry ledger rows stranded by an AI gateway 7005 - #774

Open
harlan-github-agent[bot] wants to merge 1 commit into
mainfrom
fix/issue-772
Open

harlan-github-agent[bot] wants to merge 1 commit into
mainfrom
fix/issue-772

Conversation

@harlan-github-agent

Copy link
Copy Markdown
Contributor

🔗 Linked issue

Closes #772

❓ Type of change

  • 📖 Documentation
  • 🐞 Bug fix
  • 👌 Enhancement
  • ✨ New feature
  • 🧹 Chore
  • ⚠️ Breaking change

📚 Description

A purpose classification runs inline inside registry/repository-submission, so when the Cloudflare AI gateway is down the submission job exhausts its 5 attempts and dead-letters with the gateway's exception. reconcileLedger matched only no_supported_skill_paths, root_skill_unsupported and repository_purpose_review_required, so ghost-brief/skills sat submitted forever and alarmed as stalled nightly after the 2026-12-02T21:31Z run:

exception: "AiGatewayError: 7005: Unified billing service unavailable
    at Ai._parseError (cloudflare-internal:ai-api:220:24)
    at async Ai.run (cloudflare-internal:ai-api:198:19)
    at async classifyRepositoryPurpose (_chunks/repository-purpose-effect.mjs:81:52)
    at async refreshRepositoryPurpose (_chunks/repository-purpose-effect.mjs:208:17)
    at async checkRepositoryPurposeAdmission (_chunks/repository-purpose-effect.mjs:222:18)"
attempts: 5

7005 is the billing service being down, not a verdict about the repository, so the park branch from #605 does not fit: no reviewer action exists, and releasing a hold would re-run into the same outage. The row is judged transient infrastructure and returns to pending with submitted_at cleared, so the submit loop classifies it again once the gateway recovers. The reconcile summary names this disposition as retriedPurpose and the sync-x-mentions run log carries it.

A deterministic 7003 input error deliberately does not match. Returning it to pending would re-enqueue the same rejection every reconcile run; the scheduler owns that burn (#770, being fixed in #773), so the row stays stalled like any other unmatched dead-letter.

Open points:

  • The pattern is narrowed to the measured text AiGatewayError: 7005:, not every purpose-classification failure. Repository purpose classification failed: invalid_answer (an unparseable model answer) still stalls its row; retrying it is not obviously safe since the same evidence can produce the same unparseable answer, and it needs its own decision.
  • While the outage lasts, each recovered row can cycle pending, dead-letter and back roughly every 90 minutes. That is the normal retry clock, not the nightly stall alarm it replaces.

🤖 AI disclosure: Harlan Agent Kit modified this description. My AI open-source policy.

@harlan-github-agent harlan-github-agent Bot added harlan-agent-review Pull request triage requires an adversarial Review. Adding this label manually always forces one. and removed harlan-agent-review Pull request triage requires an adversarial Review. Adding this label manually always forces one. labels Dec 3, 2026
@harlan-github-agent

harlan-github-agent Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor Author

🟢 Ready · 85/100

Checked: reconcileLedger branch ordering and the new 7005 retry branch against the staged jobs/failed_jobs fixtures, plus the sync-x-mentions submit/reconcile wiring and enqueue dedupe. Not checked: the live Cloudflare queue consumer's failed_jobs write path and the real outage cycle in production.

1 follow-up · none block merge

In this change.

2026-12-03 16:35 UTC · Harlan Agent Kit automated review, not Harlan's; a person merges · AI policy · @harlan-agent rerun · @harlan-agent stop

@harlan-github-agent harlan-github-agent Bot added the harlan-agent-ready The automated Review passed every gate on this head commit. label Dec 3, 2026

@harlan-github-agent harlan-github-agent Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

🟢 Ready · 1 follow-up · read the review

Harlan Agent Kit automated review, not Harlan's · AI policy

// other unmatched dead-letter.
const retriedPurpose = await input.db
.prepare(
`UPDATE discovery_ledger SET status = 'pending', submitted_at = NULL

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

⚪ Stale 7005 dead-letters loop later failures and mask stalls · 65/100 · does not block merge

The retriedPurpose UPDATE matches any historical failed_jobs row whose exception contains 'AiGatewayError: 7005:', with no recency bound and no exclusion for an active submission job, and nothing ever deletes failed_jobs rows. When a repo with 7005 history later dead-letters with any unmatched exception (for example 'Repository purpose classification failed: invalid_answer'), every 15-minute reconcile still matches the stale row, returns the row to pending, and re-enqueues a job that fails again forever while reconcileStalled reports 0. During an ongoing outage the branch also fires seconds after each fresh submission while the job's five attempts (about 15 minutes total at 60/120/240/480-second delays) are still running, so the retry cadence is ~15 minutes per dead-letter, not the ~90 minutes the PR documents.

Fix: Bound the match to the operative failure, for example the repo's newest failed_jobs row or a recency window, so older 7005 history cannot retry newer unrelated failures.

  • Ask an agent to verify and fix this finding

Harlan Agent Kit automated review, not Harlan's · AI policy

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

Labels

harlan-agent-ready The automated Review passed every gate on this head commit.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dead-lettered purpose job stalls its discovery ledger row

0 participants