Skip to content

fix(channels): tombstone corrupt ingress rows - #105259

Merged
steipete merged 19 commits into
mainfrom
codex/pr-98402-replacement
Jul 12, 2026
Merged

steipete merged 19 commits into
mainfrom
codex/pr-98402-replacement

Conversation

@steipete

@steipete steipete commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Replaces #98402 on current main. A malformed durable channel-ingress payload could throw during JSON parsing, hide later valid rows behind list limits, and repeatedly starve claimNext without making durable progress.

Why This Change Was Made

The replacement centralizes a Kysely compare-and-set tombstone operation for corrupt pending and claimed rows. It scrubs payload, metadata, and claim fields; validates JSON before limited pending selection; makes claimNext durably advance past corrupt rows; and reuses the same guarded cleanup during stale-claim recovery. Recovery counts only rows actually changed, preventing an older worker from clearing a newer claim generation.

This preserves @Pick-cat's contributor commits while removing the unrelated gateway test edit and consolidating the final repair at the ingress-queue owner boundary.

User Impact

One corrupt durable ingress row no longer blocks later valid channel messages. Corrupt data is retained only as a failed tombstone with a bounded reason, while valid queued work remains listable and claimable.

Evidence

  • Blacksmith Testboxes tbx_01kxarzhjkg0ypn8ttfx5smybz and tbx_01kxat2vsnk60cwbghnym4j6py: 163 focused core queue, Telegram spool, polling, and webhook tests passed.
  • Four type lanes passed: tsgo:core, tsgo:test:src, tsgo:extensions, and tsgo:extensions:test.
  • Full pnpm build passed, including the public Plugin SDK declaration graph check (5,057,529 / 5,100,000 bytes).
  • The pinned Plugin SDK surface test passed at 10,630 public exports, including the three additive corrupt-claim re-exports.
  • Regression coverage includes limited-list visibility, scanLimit: 1 convergence, direct claim cleanup, pending duplicate cleanup, active-claim preservation, stale-claim compare-and-set races, and recovery-predicate ownership.
  • The additive shouldRecoverCorrupt SDK contract is documented in docs/plugins/sdk-runtime.md.
  • Fresh final autoreview is clean with no accepted or actionable findings (confidence 0.86).

Supersedes #98402.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: telegram Channel integration: telegram plugin: file-transfer size: L maintainer Maintainer-authored PR labels Jul 12, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8b4405bd9e

ℹ️ 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 on lines +591 to +593
const record = baseRecord<TPayload, TMetadata>(row);
if (record) {
records.push(record);

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.

P2 Badge Keep skipped corrupt rows recoverable

When a pending row has corrupt payload_json, this filters it out of listPending() without tombstoning it or surfacing its id. In the Telegram polling/webhook drains, candidateUpdateIds is built from listTelegramSpooledUpdates() and then passed to claimNext, so a corrupt pending row skipped here is never included in the candidate set that would tombstone it; after later valid rows drain, the candidate set is empty and the corrupt row stays pending until TTL, causing repeated scans and failing the intended scrub/tombstone behavior for the main spool path.

Useful? React with 👍 / 👎.

Comment thread CHANGELOG.md
@@ -34,6 +34,7 @@ Docs: https://docs.openclaw.ai
- **Gradium TTS credential egress:** reject non-HTTPS, foreign-host, and hostname-lookalike base URLs before dispatching API keys, and pin guarded transport to Gradium's documented API hostname. (#101280) Thanks @zhangguiping-xydt.
- **Gateway command SecretRefs:** preserve authoritative active-snapshot values when another command secret remains unresolved, falling back locally only for missing paths instead of emitting a per-turn `secrets.resolve` failure. (#96661) Thanks @SunnyShu0925.
- **Cron delivery status:** keep successful isolated agent turns at `status=ok` when downstream delivery fails, while preserving the send failure separately in delivery state and run logs. (#95419) Thanks @Alix-007.
- **Channel ingress recovery:** tombstone and scrub malformed durable ingress payloads without letting corrupt rows hide or starve later valid messages. (#98402) Thanks @Pick-cat.

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.

P2 Badge Remove the hand-written changelog entry

This is a normal fix commit, but root AGENTS.md says CHANGELOG.md is release-only and “Do not edit for normal PRs, direct main fixes, or ship it; release generation owns it.” Keeping this manual Unreleased entry risks stale or duplicated release notes because the release generator derives changelog content from merged PRs and direct commits.

Useful? React with 👍 / 👎.

@steipete
steipete force-pushed the codex/pr-98402-replacement branch from 8b4405b to e9117d7 Compare July 12, 2026 09:53

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e9117d70e8

ℹ️ 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 on lines +625 to +627
return rows
.map((row) => claimedRecord<TPayload, TMetadata>(row))
.filter((rec): rec is ChannelIngressQueueClaim<TPayload, TMetadata> => rec !== null);

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.

P2 Badge Keep preserved corrupt claims blocking their lane

When shouldRecoverCorrupt declines to tombstone a corrupt claimed row (for example because extensions/telegram/src/polling-session.ts:954 sees a fresh live owner), this filter drops that still-claimed row from listClaims(). The Telegram polling and webhook drains build claimedLaneKeys only from listTelegramSpooledUpdateClaims() (polling-session.ts:960, webhook.ts:783), so the preserved corrupt claim's lane_key no longer blocks later pending updates in the same chat; a sibling process that claimed the original row before corruption may still be producing side effects, breaking the spool's per-lane ordering guarantee.

Useful? React with 👍 / 👎.

Pick-cat and others added 19 commits July 12, 2026 02:58
…tale recovery

Two P1 gaps: enqueue() threw on duplicate when the existing row had corrupt
payload_json, and recoverStaleClaims() silently skipped corrupt claimed rows,
leaving them invisible to recovery. Both paths now tombstone the unrecoverable
row as failed with reason "corrupt_payload" and return a proper result.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@steipete
steipete force-pushed the codex/pr-98402-replacement branch from e9117d7 to c255f3c Compare July 12, 2026 10:01
@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Jul 12, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c255f3c2b3

ℹ️ 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".

throw new Error(`Failed to tombstone corrupt ingress event ${queueName}/${eventId}`);
}
return {
kind: "failed",

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.

P2 Badge Do not ack valid redeliveries as failed duplicates

When the existing row is a corrupt pending entry and the platform redelivers the same event with a valid payload, returning kind: "failed" here makes callers treat the enqueue as an idempotent duplicate even though no handler ever processed the event. For example, Telegram writeTelegramSpooledUpdate() ignores the enqueue result, so webhook returns 200 after line 955/963 and polling acks the worker at polling-session.ts:1321-1328; the row has been tombstoned as failed, no pending copy remains, and later redeliveries hit the failed tombstone as well. This should either preserve/reinsert the redelivered payload as pending or surface an error so the transport does not acknowledge the update.

Useful? React with 👍 / 👎.

@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready proof for exact head c255f3c2b3807a529cd90f2a0a736f3041a632a4:

  • Blacksmith Testboxes tbx_01kxarzhjkg0ypn8ttfx5smybz and tbx_01kxat2vsnk60cwbghnym4j6py: 163 focused ingress-queue, Telegram spool, polling, and webhook tests passed.
  • Type lanes passed: tsgo:core, tsgo:test:src, tsgo:extensions, and tsgo:extensions:test.
  • Fresh Testbox tbx_01kxaw8abdmeq8h50mrr44159n: Plugin SDK surface suite passed 10/10 at 10,630 public exports; full pnpm build passed with a 5,057,529 / 5,100,000 byte declaration graph.
  • Fresh final autoreview: no accepted or actionable findings (confidence 0.86).
  • Exact-head hosted CI run 29188456196: 50 successful jobs, 11 skipped, zero failures.
  • Repo-native review artifacts validated with recommendation READY FOR /prepare-pr, zero findings; OPENCLAW_TESTBOX=1 scripts/pr prepare-run 105259 passed.

Known proof gap: no synthetic multi-process fault injection beyond the token/cutoff race tests. The implementation remains compare-and-set guarded, and Telegram's live-process/lane ownership paths are covered by focused tests.

@steipete
steipete merged commit a824078 into main Jul 12, 2026
117 of 122 checks passed
@steipete
steipete deleted the codex/pr-98402-replacement branch July 12, 2026 10:09
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 13, 2026
* fix(infra): guard channel ingress queue parseJson against corrupted JSON

* fix(infra): fix type assertion in ingress queue test

* fix(infra): use tagged parse result and validate payload before claiming

* fix(infra): remove unnecessary non-null assertion in ingress queue test

* fix(infra): scan corrupt ingress rows in claimNext

* test(gateway): avoid typed empty mock call tuple access

* fix(infra): tombstone corrupt ingress rows on duplicate enqueue and stale recovery

Two P1 gaps: enqueue() threw on duplicate when the existing row had corrupt
payload_json, and recoverStaleClaims() silently skipped corrupt claimed rows,
leaving them invisible to recovery. Both paths now tombstone the unrecoverable
row as failed with reason "corrupt_payload" and return a proper result.

Co-Authored-By: Claude Opus 4.7 <[email protected]>

* fix(infra): resolve lint shadow and await-thenable in recoverStaleClaims

Co-Authored-By: Claude Opus 4.7 <[email protected]>

* fix(channels): tombstone corrupt ingress rows

* test(channels): use explicit placeholder claim tokens

* refactor(channels): name claim token values

* refactor(channels): keep claim projection direct

* fix(channels): preserve active ingress claims

* fix(channels): make corrupt recovery policy-aware

* refactor(channels): name corrupt claim token

* fix(channels): bound corrupt ingress reconciliation

* fix(channels): paginate pending ingress by key

* refactor(telegram): return live owner check directly

* build(plugin-sdk): refresh public export budget

---------

Co-authored-by: Pick-cat <[email protected]>
Co-authored-by: Claude Opus 4.7 <[email protected]>
wheakerd pushed a commit to wheakerd/clawdbot that referenced this pull request Jul 15, 2026
* fix(infra): guard channel ingress queue parseJson against corrupted JSON

* fix(infra): fix type assertion in ingress queue test

* fix(infra): use tagged parse result and validate payload before claiming

* fix(infra): remove unnecessary non-null assertion in ingress queue test

* fix(infra): scan corrupt ingress rows in claimNext

* test(gateway): avoid typed empty mock call tuple access

* fix(infra): tombstone corrupt ingress rows on duplicate enqueue and stale recovery

Two P1 gaps: enqueue() threw on duplicate when the existing row had corrupt
payload_json, and recoverStaleClaims() silently skipped corrupt claimed rows,
leaving them invisible to recovery. Both paths now tombstone the unrecoverable
row as failed with reason "corrupt_payload" and return a proper result.

Co-Authored-By: Claude Opus 4.7 <[email protected]>

* fix(infra): resolve lint shadow and await-thenable in recoverStaleClaims

Co-Authored-By: Claude Opus 4.7 <[email protected]>

* fix(channels): tombstone corrupt ingress rows

* test(channels): use explicit placeholder claim tokens

* refactor(channels): name claim token values

* refactor(channels): keep claim projection direct

* fix(channels): preserve active ingress claims

* fix(channels): make corrupt recovery policy-aware

* refactor(channels): name corrupt claim token

* fix(channels): bound corrupt ingress reconciliation

* fix(channels): paginate pending ingress by key

* refactor(telegram): return live owner check directly

* build(plugin-sdk): refresh public export budget

---------

Co-authored-by: Pick-cat <[email protected]>
Co-authored-by: Claude Opus 4.7 <[email protected]>
(cherry picked from commit a824078)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: telegram Channel integration: telegram docs Improvements or additions to documentation maintainer Maintainer-authored PR plugin: file-transfer scripts Repository scripts size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants