Skip to content

Reset smoke harness idempotence state#750

Merged
dahlia merged 3 commits intofedify-dev:mainfrom
dahlia:fix-sharkey-smoke-reset-idempotence
Apr 30, 2026
Merged

Reset smoke harness idempotence state#750
dahlia merged 3 commits intofedify-dev:mainfrom
dahlia:fix-sharkey-smoke-reset-idempotence

Conversation

@dahlia
Copy link
Copy Markdown
Member

@dahlia dahlia commented Apr 29, 2026

Fixes #749.

Summary

This fixes the smoke-sharkey failure in #749 by resetting Fedify's inbox idempotence state when the smoke harness reset endpoint is called.

The test harness already cleared its visible inbox state in test/smoke/harness/backdoor.ts, but it kept the underlying MemoryKvStore used by the Fedify federation instance in test/smoke/harness/federation.ts. That meant repeated activities with the same ActivityPub id could be accepted at the HTTP delivery layer but skipped before reaching the inbox listeners.

What we found

After reproducing the failure locally, Sharkey 2025.4.6 was not failing to deliver Undo(Follow) outright. Its deliver queue contained successful Undo jobs to https://fedify-harness/users/testuser/inbox.

The important detail was that Sharkey reused the same Undo activity id across repeated follow/unfollow cycles for the same pair of actors:

https://sharkey/follows/<followerId>/<followeeId>/undo

Fedify correctly treats already-seen inbox activities as idempotent for one day. Since /_test/reset only cleared the harness' visible inbox array, the next Sharkey Undo with the same id was filtered as already processed and never reached the test store. The smoke assertion then timed out even though Sharkey's delivery job reported success.

Changes

  • Keep a reference to the smoke harness MemoryKvStore in test/smoke/harness/federation.ts.
  • Add a test-only reset helper that deletes ["_fedify", "activityIdempotence"] entries.
  • Call that helper from /_test/reset in test/smoke/harness/backdoor.ts.

Verification

  • deno fmt test/smoke/harness/federation.ts test/smoke/harness/backdoor.ts
  • deno cache test/smoke/harness/main.ts
  • Local smoke-sharkey reproduction test passed:
✓ Mastodon → Fedify (Follow)
✓ Fedify → Mastodon (Follow)
✓ Fedify → Mastodon (Create Note)
✓ Mastodon → Fedify (Reply)
✓ Mastodon → Fedify (Unfollow)
✓ Fedify → Mastodon (Unfollow)
  • Commit hooks passed: format, lint, markdown, fixture usage, version checks, workspace protocol check, and type checks.

Clear the Fedify harness inbox idempotence keys when the smoke test reset
endpoint is called.  This keeps repeated Sharkey follow/unfollow scenarios
from being filtered as duplicate activities after the visible test inbox has
already been cleared.

Fixes fedify-dev#749

Assisted-by: Codex:gpt-5.5
@dahlia dahlia self-assigned this Apr 29, 2026
@dahlia dahlia added type/test Testing related activitypub/interop Interoperability issues component/ci CI/CD workflows and GitHub Actions labels Apr 29, 2026
@dahlia
Copy link
Copy Markdown
Member Author

dahlia commented Apr 29, 2026

@codex review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 29, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: d14e5f6b-2d26-4d7c-8566-1aeec1432c5e

📥 Commits

Reviewing files that changed from the base of the PR and between c85cc2a and 2cf85f5.

📒 Files selected for processing (1)
  • test/smoke/harness/federation.ts

📝 Walkthrough

Walkthrough

Adds federation test-state cleanup: the federation harness reuses a single in-memory KV store and exposes resetFederationTestState() to clear its entries; the test backdoor POST /_test/reset now calls that helper after clearing the in-memory store and recipientCache.

Changes

Cohort / File(s) Summary
Federation state cleanup
test/smoke/harness/federation.ts
Create a single MemoryKvStore instance reused by createFederation; add export async function resetFederationTestState() that enumerates kv.list() and deletes each KV entry (awaiting each deletion) to clear federation-related state.
Backdoor reset integration
test/smoke/harness/backdoor.ts
POST /_test/reset now imports and awaits resetFederationTestState() after clearing the in-memory store and recipientCache, extending teardown to include federation KV cleanup.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Reset smoke harness idempotence state' accurately captures the main change: resetting Fedify's inbox idempotence state when the smoke harness reset endpoint is called.
Description check ✅ Passed The description clearly explains the fix for issue #749, detailing the root cause (retained idempotence entries in MemoryKvStore) and the solution with verification steps.
Linked Issues check ✅ Passed The changes directly address the investigation findings in #749 by implementing the solution to reset idempotence state, resolving the Mastodon → Fedify unfollow timeout issue.
Out of Scope Changes check ✅ Passed All changes are scoped to resetting federation KV state (adding resetFederationTestState helper and calling it from the reset endpoint) with no unrelated modifications present.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 6/8 reviews remaining, refill in 10 minutes and 31 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

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

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@test/smoke/harness/federation.ts`:
- Around line 19-25: resetFederationTestState currently only clears the
["_fedify","activityIdempotence"] prefix so leftover federation caches remain;
update resetFederationTestState to also list and delete keys for the other
Federation KV prefixes used by the harness (["_fedify","remoteDocument"],
["_fedify","publicKey"], ["_fedify","httpMessageSignaturesSpec"],
["_fedify","acceptSignatureNonce"]) by iterating over each prefix with
kv.list(...) and adding their keys to the deletion batch (then await Promise.all
on kv.delete calls) so /_test/reset produces a full clean slate.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 21710b6c-fd9e-4c71-b1b9-8a2c08b0d782

📥 Commits

Reviewing files that changed from the base of the PR and between 9071ca0 and 2416c89.

📒 Files selected for processing (2)
  • test/smoke/harness/backdoor.ts
  • test/smoke/harness/federation.ts

Comment thread test/smoke/harness/federation.ts
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a state reset mechanism for the smoke test harness by adding a resetFederationTestState function and integrating it into the /_test/reset backdoor endpoint. The feedback suggests making the reset more robust by clearing all entries in the KV store rather than just specific idempotence keys, which helps prevent potential test flakiness from stale cached data.

Comment thread test/smoke/harness/federation.ts
Clear the smoke harness KV store completely when /_test/reset is called
because the harness owns its MemoryKvStore exclusively.  This covers
idempotence and cached federation documents, keys, signature state, and
nonces so each smoke scenario starts from clean federation state.

Resolves review comments:
fedify-dev#750 (comment)
fedify-dev#750 (comment)

Assisted-by: Codex:gpt-5.5
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 29, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dahlia
Copy link
Copy Markdown
Member Author

dahlia commented Apr 29, 2026

@codex review

@dahlia
Copy link
Copy Markdown
Member Author

dahlia commented Apr 29, 2026

/gemini review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

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

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds a resetFederationTestState function to clear the KV store and integrates it into the test reset endpoint. Feedback indicates that the current implementation clears more than intended and suggests using a prefix to target specific states, while also recommending a more type-safe approach for deleting keys to align with repository standards.

Comment thread test/smoke/harness/federation.ts Outdated
Delete each smoke harness KV entry as it is listed instead of collecting
keys first.  The harness still clears the full dedicated MemoryKvStore so
/_test/reset remains a clean federation-state reset.

Resolves review comment:
fedify-dev#750 (comment)

Assisted-by: Codex:gpt-5.5
@dahlia
Copy link
Copy Markdown
Member Author

dahlia commented Apr 29, 2026

/gemini review

@dahlia
Copy link
Copy Markdown
Member Author

dahlia commented Apr 29, 2026

@codex review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a state reset mechanism for the federation test harness by clearing the key-value store during the /_test/reset operation. A technical issue was identified in the resetFederationTestState function where the kv.list() method is called without the required selector argument, which could lead to runtime exceptions.

Comment thread test/smoke/harness/federation.ts
@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

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

@dahlia
Copy link
Copy Markdown
Member Author

dahlia commented Apr 29, 2026

@codex review

@dahlia
Copy link
Copy Markdown
Member Author

dahlia commented Apr 29, 2026

/gemini review

@dahlia dahlia requested a review from sij411 April 29, 2026 08:51
@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

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

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds a way to reset the federation test state by clearing the KV store. It introduces the resetFederationTestState function in the test harness and updates the backdoor reset endpoint to call it. Feedback was provided regarding the scope of the KV store clearing, suggesting that a targeted deletion using specific key prefixes might be more appropriate than a full wipe.

Comment thread test/smoke/harness/federation.ts
@dahlia
Copy link
Copy Markdown
Member Author

dahlia commented Apr 30, 2026

@codex review

@dahlia
Copy link
Copy Markdown
Member Author

dahlia commented Apr 30, 2026

/gemini review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

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

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a state reset mechanism for the smoke test harness by adding a resetFederationTestState function that clears the MemoryKvStore. Feedback suggests refining this function to specifically target idempotency-related keys using the ["_fedify", "activityIdempotence"] prefix, ensuring the reset is more precise and avoids clearing unrelated state.

Comment thread test/smoke/harness/federation.ts
@dahlia dahlia merged commit 16f9539 into fedify-dev:main Apr 30, 2026
17 checks passed
@dahlia dahlia deleted the fix-sharkey-smoke-reset-idempotence branch April 30, 2026 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

activitypub/interop Interoperability issues component/ci CI/CD workflows and GitHub Actions type/test Testing related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Investigate smoke-sharkey timeout in Mastodon → Fedify unfollow scenario

2 participants