Agent Skillsstella/stella › conventions-ingestion

conventions-ingestion

GitHub

定义外部数据摄入、同步及修复作业的开发规范,确保幂等性、回放安全与断点续传。适用于构建或审查涉及导入、Webhook、连接器轮询及状态检查点的后端逻辑。

.claude/skills/conventions-ingestion/SKILL.md stella/stella

触发场景

构建外部数据摄入管道 审查同步或修复作业代码 实现Webhook处理逻辑 设计连接器轮询机制

安装

npx skills add stella/stella --skill conventions-ingestion -g -y
更多选项

非标准路径

npx skills add https://github.com/stella/stella/tree/main/.claude/skills/conventions-ingestion -g -y

不安装直接使用

npx skills use stella/stella@conventions-ingestion

指定 Agent (Claude Code)

npx skills add stella/stella --skill conventions-ingestion -a claude-code -g -y

安装 repo 全部 skill

npx skills add stella/stella --all -g -y

预览 repo 内 skill

npx skills add stella/stella --list

SKILL.md

Frontmatter
{
    "name": "conventions-ingestion",
    "description": "Apply when building or reviewing external ingestion, imports, connector polling, webhooks, extraction workers, sync cursors, checkpoints, or repair jobs. Enforces replay safety, idempotency, durable progress, and bounded recovery."
}

Replay-Safe Ingestion Conventions

Apply to any workflow that turns external or asynchronous input into durable stella state: paginated imports, connector sync, webhooks, file extraction, queue workers, migrations, and repair scans.

Target Property

A retry, duplicate delivery, worker restart, or overlapping run must converge to the same durable state as one successful run. Idempotency is one ingredient; replay safety also requires correct checkpoint ordering, durable retries, and protection from stale work.

Required Design

  1. Stable identity. Give every source item a stable, tenant-scoped identity. Enforce it with a database unique constraint whose leading columns preserve the tenant or source boundary. Do not rely on a hash collision check alone.
  2. Idempotent persistence. Upsert, claim, or transition by stable identity. Reapplying the same input must not duplicate rows, counters, notifications, or other effects.
  3. Explicit outcomes. Distinguish terminal outcomes (applied, unchanged, deliberately rejected) from retryable failures. A skipped item is terminal only when losing it is intentional and auditable.
  4. Checkpoint last. Advance a cursor, watermark, or checkpoint only after every earlier item is terminal or has a durable retry record. On an ambiguous failure, hold the old checkpoint and replay.
  5. Atomic database batches. For database-only work, persist the items and checkpoint in one short transaction with commitReplaySafeIngestionBatch from apps/api/src/lib/replay-safe-ingestion.ts.
  6. External side effects. Object storage, search indexes, email, and remote APIs cannot join the database transaction. Make the database record the source identity/fingerprint and retry state first; use deterministic object keys or provider idempotency keys. Persist the cursor only after all page work is durable.
  7. Compare-and-set cursors. Capture the cursor loaded at run start and require it in the checkpoint update. A stale run must return the persisted winner, never overwrite newer progress. Public corpus ingestion uses advanceCorpusIngestionCheckpoint from apps/api/src/lib/corpus-ingestion-checkpoint.ts.
  8. Stale-work protection. Mutable inputs need a source version or content fingerprint. A late worker must compare the claimed version before overwriting newer state. AI outputs also include schema, model, prompt, and parser versions in their identity/provenance.
  9. Durable execution. Do not rely on detached promises or process memory for required work. Use a durable queue/outbox and deterministic job identity. Add a bounded repair scan when enqueue and commit cannot be atomic.
  10. Bounded recovery. Repair scans and list reads use cursor pagination and configured limits. Workers remain stateless and safe under concurrency.
  11. Owned schema. The vertical slice owns its source, item, attempt, and failure tables. Shared code provides transaction and identity primitives, not a cross-domain ingestion framework.
  12. Bounded external calls. Every remote request has an explicit timeout, bounded retry policy with jitter, provider-aware rate limiting, and a maximum concurrency. Persist retry state; do not hold a database transaction while waiting on the provider.
  13. Poison-item isolation. One malformed or permanently rejected item must not stall an entire source forever. Persist the item identity, classified terminal/retryable outcome, sanitized error context, and operator-visible repair path before allowing later progress.
  14. Accounted-for source fields. Every field a source states on a page the adapter already fetches is stored, or excluded with the reason. See below.

Checkpoint Boundary

Direct Drizzle writes to syncCursor are banned by no-direct-ingestion-checkpoint-write. Public corpus cursors go through advanceCorpusIngestionCheckpoint; database-only batches keep the write inside the persistCheckpoint callback passed to commitReplaySafeIngestionBatch. The lint rule enforces the visible boundary; it does not prove that preceding external effects are durable.

Source-Field Inventory

A field an adapter never noticed is indistinguishable from one it decided to leave. Case-law adapters therefore declare what their source states, and the declaration is part of the contract: SourceAdapter.sourceFields is required, so an adapter without one does not compile.

An inventory has three parts, in the adapter beside the readers it mirrors:

  • SOURCE_FIELDS, the list of names the source labels on the per-decision pages this adapter parses, as const;
  • a disposition map written as const satisfies Record<<that union>, SourceFieldDisposition>, so the map is total by type and a new name without a decision does not compile. Each entry is { disposition: "stored", target } (a metadata key, a result field, the parsed document, or the row's identity), or excludedSourceField(reason), where the reason says what the field is and why the row does not carry it. "Not read today" is not a reason; duplicate of a stored field, derived elsewhere, no field on the row, and data minimization are. The constructor is the only way to write an exclusion, and a blank reason does not compile;
  • listSourceFields(payload), which reads a page back and answers what the publisher labelled on it.

source-field-inventory.test.ts drives every registered adapter from the registry: each enrolled adapter's fixture goes through its own listSourceFields, every name that comes out must be in the map, and every field the map stores must be on the decision built from that fixture, at the target the disposition names. A field on the page that is in neither set fails with its name.

Enrolment is a ratchet. PENDING_SOURCE_FIELD_INVENTORY is the one sanctioned way to not have an inventory, and adapters/source-field-inventory-baseline.json lists exactly which adapters use it. The suite fails when a pending adapter is missing from the baseline and when a baseline entry has since enrolled, so the set only shrinks. To enrol one: declare the three parts above, add a fixture to the conformance suite, and delete the adapter's line from the baseline.

Refresh a fixture from the live page when the source changes. The suite certifies the adapter against the page it is given, so a fixture that stopped matching the publisher certifies nothing.

Raw Holds Every Fetched Response

An inventory decides what is read; the stored raw decides what can still be read later. Where a source serves one decision across several responses (a detail page beside the document), store all of them, with encodeSourceRawEnvelope and SOURCE_RAW_ENVELOPE_CONTENT_TYPE, naming each part by its role. A raw that holds only the page the parser read makes a field captured later unrecoverable for every stored row: replay can only re-read what was kept.

reparseStoredRaw decodes with decodeSourceRawEnvelope and handles null, which is what a row stored before its adapter had an envelope reads as. Bump the adapter's entry in PARSER_VERSIONS when the replay's output changes, and state in the pull request what a replay does and does not backfill: rows stored before the change hold what they held, and only a re-crawl adds to them.

Verification

Test the behavior that types and lint cannot prove:

  • replay the same batch and assert the same fixed point;
  • fail item persistence and assert the checkpoint does not advance;
  • fail checkpoint persistence and assert database item writes roll back;
  • deliver duplicates concurrently and assert one durable effect;
  • crash after a remote side effect and before acknowledgment, then replay;
  • finish stale work after a newer version and assert it cannot overwrite;
  • leave an enqueue gap and assert the bounded repair scan finds it;
  • exhaust the retry budget for one poison item and assert later items still reach a durable terminal state without silently dropping the failure;
  • overlap two workers at the provider concurrency limit and assert calls stay bounded and the persisted winner cannot be overwritten;
  • read a source fixture back through the adapter's own listSourceFields and assert every field it states is stored or excluded with a reason.

Prefer invariant and state-machine tests over one example retry.

Existing References

  • Upload finalization: apps/api/src/handlers/uploads/update.ts
  • Case-law ingestion: apps/api/src/handlers/case-law/ingestion/pipeline.ts
  • Legislation ingestion: apps/api/src/handlers/legislation/ingestion.ts
  • Hosted usage webhook deduplication: apps/api/src/lib/hosted-usage-provider/webhook-store.ts

These are examples, not blanket proof: audit each new side effect and checkpoint independently.

版本历史

  • 7b52e43 当前 2026-09-09 03:28

同 Skill 集合

.agents/skills/click-around/SKILL.md
.agents/skills/conventions-ai/SKILL.md
.agents/skills/conventions-db/SKILL.md
.agents/skills/conventions-i18n/SKILL.md
.agents/skills/conventions-ingestion/SKILL.md
.agents/skills/conventions-mcp/SKILL.md
.agents/skills/conventions-perf/SKILL.md
.agents/skills/conventions-scale/SKILL.md
.agents/skills/conventions-security/SKILL.md
.agents/skills/conventions-use-effect/SKILL.md
.agents/skills/conventions-ux/SKILL.md
.agents/skills/dev/SKILL.md
.agents/skills/finish-pr/SKILL.md
.agents/skills/new-handler/SKILL.md
.agents/skills/open-pr/SKILL.md
.agents/skills/plan/SKILL.md
.agents/skills/product-deep-think/SKILL.md
.agents/skills/product-think/SKILL.md
.agents/skills/rabbit-round/SKILL.md
.agents/skills/regression-hunt/SKILL.md
.agents/skills/security-audit/SKILL.md
.agents/skills/update-deps/SKILL.md
.ai/local-skills/click-around/SKILL.md
.ai/local-skills/conventions-ai/SKILL.md
.ai/local-skills/conventions-db/SKILL.md
.ai/local-skills/conventions-i18n/SKILL.md
.ai/local-skills/conventions-ingestion/SKILL.md
.ai/local-skills/conventions-mcp/SKILL.md
.ai/local-skills/conventions-perf/SKILL.md
.ai/local-skills/conventions-scale/SKILL.md
.ai/local-skills/conventions-security/SKILL.md
.ai/local-skills/conventions-use-effect/SKILL.md
.ai/local-skills/conventions-ux/SKILL.md
.ai/local-skills/dev/SKILL.md
.ai/local-skills/new-handler/SKILL.md
.ai/local-skills/open-pr/SKILL.md
.ai/local-skills/plan/SKILL.md
.ai/local-skills/product-deep-think/SKILL.md
.ai/local-skills/rabbit-round/SKILL.md
.ai/local-skills/security-audit/SKILL.md
.ai/local-skills/update-deps/SKILL.md
.claude/skills/conventions-ai/SKILL.md
.claude/skills/conventions-db/SKILL.md
.claude/skills/conventions-i18n/SKILL.md
.claude/skills/conventions-mcp/SKILL.md
.claude/skills/conventions-perf/SKILL.md
.claude/skills/conventions-scale/SKILL.md
.claude/skills/conventions-security/SKILL.md
.claude/skills/conventions-use-effect/SKILL.md

元信息

文件数
0
版本
7b52e43
Hash
dd8fd784
收录时间
2026-09-09 03:28

首页 - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-09-09 04:50
浙ICP备14020137号-1 $访客地图$