Skip to content

fix(functions): set TTL when saving jobs dedupe markers in Redis - #15839

Open
saiyyedfardeen wants to merge 1 commit into
appwrite:mainfrom
saiyyedfardeen:fix-15746-jobs-dedupe-ttl
Open

saiyyedfardeen wants to merge 1 commit into
appwrite:mainfrom
saiyyedfardeen:fix-15746-jobs-dedupe-ttl

Conversation

@saiyyedfardeen

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes #15746.

In src/Appwrite/Platform/Modules/Functions/Workers/Jobs.php, build/execution callback deduplication markers (jobs-event-{projectSequence}-{eventId}) are checked using $cache->load($key, self::DEDUPE_TTL) (3600 seconds), but were saved via $cache->save($key, true) without passing a TTL.

Because Utopia\Cache\Cache::save() defaults to $ttl = 0, the Redis adapter never set an EXPIRE on these keys, causing jobs-event-* hashes to accumulate indefinitely in Redis with TTL = -1 and compete with document caches and queues under allkeys-lru.

Changes

  • src/Appwrite/Platform/Modules/Functions/Workers/Jobs.php: Passed ttl: self::DEDUPE_TTL (3600 seconds) to $cache->save() for both non-log build callbacks (artifact, exit, complete) and log callbacks (onLog).
  • tests/unit/Platform/Modules/Functions/Workers/JobsDedupeTest.php: Added unit tests verifying that:
    • Non-log and log callbacks save jobs-event-* markers with ttl: 3600.
    • Duplicate events arriving within the DEDUPE_TTL window are skipped without redundant database reads/writes or realtime broadcasts.

Test Plan

  • Ran php -l syntax checks on all modified/created files.
  • Formatted with vendor/bin/pint (PSR-12 compliant).
  • Ran vendor/bin/phpstan static analysis (0 errors).
  • Ran PHPUnit unit tests (vendor/bin/phpunit tests/unit/Platform/Modules/Functions/Workers/JobsDedupeTest.php — 5 tests, 36 assertions passing; full Workers/ suite — 11 tests, 49 assertions passing).

Related PRs and Issues

Checklist

  • Have you read the Contributing Guidelines on issues?
  • If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs? (N/A: Internal worker Redis cache TTL fix; no public API schema changes)

@appwrite

appwrite Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Code review

Commit Status Tier Verdict Details
b675cd6 Reviewed Reviewed 🟢 S · Ready to merge 💬 Commented View review

The Functions jobs worker now saves build callback deduplication markers with the same one-hour TTL used when checking them. An end-to-end test deploys a function and inspects the resulting Redis marker TTLs.

Note

@saiyyedfardeen does not have write access to this repository, so Hansi does not approve automatically. A maintainer can review and approve.

Walkthrough (2)
File Change
src/Appwrite/Platform/Modules/Functions/Workers/Jobs.php Passes the deduplication TTL when saving build and log callback markers.
tests/e2e/Services/Functions/FunctionsCustomServerTest.php Adds an end-to-end check of Redis marker TTLs after a function deployment.
Fixed since the last review (2)
  • Remove the embedded Git repository snapshot · .git-uninitialized-backup/HEAD:1
  • Remove the checked-in Git object backup · .git-uninitialized-backup/HEAD:1
Filtered out (1)

Findings Hansi considered but did not post.

Finding Why
Exclude pre-existing markers from the TTL assertion Verifier: The test uses ProjectCustom::getProject(), which creates a new project with a unique ID for this test class, then filters Redis keys by that project's internal sequence. Markers left by earlier runs/projects therefore do not match this pattern in the normal E2E lifecycle. In the current code all markers created for this project use the newly added TTL (including log callbacks), so the assertion does not encounter the alleged stale no-TTL markers absent an unsupported sequence-reuse/reset scenario.

Reviewed b675cd6

Tip

Comment @appwrite review to re-run, or mention @appwrite with a question.

@appwrite appwrite 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.

🔵 Tier A · See the inline comments. Summary

@appwrite appwrite 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.

🔵 Tier A · See the inline comments. Summary

Comment thread .git-uninitialized-backup/HEAD Resolved

@appwrite appwrite 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.

🔵 Tier A · See the inline comments. Summary

Comment thread .git-uninitialized-backup/HEAD Resolved
@saiyyedfardeen
saiyyedfardeen force-pushed the fix-15746-jobs-dedupe-ttl branch from 3f4d50b to b675cd6 Compare November 19, 2026 18:42

@appwrite appwrite 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.

🟢 Tier S · Looks good to merge. Summary

This branch has not been deployed

No deployments
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.

🐛 Bug Report: Jobs worker stores its dedupe markers (jobs-event-*) in Redis without TTL

1 participant