Skip to content

refactor: replace CLI and migration logError callbacks with spans - #13491

Merged
loks0n merged 6 commits into
mainfrom
codex/ce-span-error-cleanup
Sep 5, 2026
Merged

loks0n merged 6 commits into
mainfrom
codex/ce-span-error-cleanup

Conversation

@loks0n

@loks0n loks0n commented Sep 5, 2026

Copy link
Copy Markdown
Member

What does this PR do?

Remove logError callback injection from CLI tasks and migration workers. Global CLI/worker error handlers export terminal failures once; recovered migration and embedding failures attach warning attributes using Span::add(). The sampler exports warning listener spans and marks recovered failures as warnings without attaching a Throwable or changing successful HTTP responses into Sentry errors. Partial embedding responses also expose the existing error count on the span.

CLI success now finishes its operation span, and worker errors before project/span initialization still get an error span. Pagination read failures propagate instead of potentially reprocessing the previous page; skipValidation() restores validation on both success and failure.

Realtime and presence reporting keep their existing handling for this first pass.

Test Plan

  • Existing migration tests: 12 tests / 84 assertions pass locally and in the Swoole Docker runtime.
  • Actual CLI entrypoint in Docker: version produces one success span; an unknown task produces one terminal error span and exits 1.
  • Manual sampler/pagination drill: recovered listener warning is exported without an exception; terminal error retains error severity; next listener has no stale warning; failed second page stops traversal and restores database validation. Reverting the sampler and pagination hunks fails both checks; restoring them passes.
  • Pint and targeted PHPStan pass for all changed files.

No new HTTP/queue end-to-end drill or staging deployment has been performed. Existing migration HTTP E2E remains a CI gate; partial embedding warning behavior has not been exercised against a live embedding backend.

Related PRs and Issues

Cloud follow-up: https://github.com/appwrite-labs/cloud/pull/5670 (held while this CE change goes first). Cloud overrides Migrations::action(): remove its logger parameter and forwarded argument when updating its server-ce dependency. Do not bump Cloud to this CE commit without that coordinated signature update.

@greptile-apps

greptile-apps Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR replaces injected CLI and migration error callbacks with span-based terminal-error and recovered-warning reporting.

  • Ensures terminal CLI and worker failures are exported even under project-selective tracing.
  • Records recoverable migration and embedding failures as warning attributes without marking successful operations as errors.
  • Propagates pagination failures while restoring database validation through skipValidation().
  • Finishes successful CLI operation spans and adds coverage for migration warning reporting.

Confidence Score: 5/5

The PR appears safe to merge; no outstanding correctness or repository-rule violations remain.

The previously reported early-worker diagnostic loss is fixed because error-bearing spans now bypass selective tracing filters, and the resolved span-storage concern is also fixed with unconditional cleanup in a finally block. The only post-review change relaxes an assertion to the warning-span convention already used by related tests and does not introduce a demonstrated failure.

Important Files Changed

Filename Overview
app/init/span.php Updates sampling so terminal errors bypass selective filters and recovered listener or embedding warnings are exported at warning level.
app/worker.php Replaces direct worker error logging with a terminal span, including failures occurring before message-span initialization.
app/cli.php Adds lifecycle-managed CLI operation spans and records terminal task failures without callback injection.
src/Appwrite/Platform/Action.php Propagates pagination read failures and scopes disabled database validation through skipValidation().
src/Appwrite/Platform/Workers/Migrations.php Replaces migration logger callbacks with warning span attributes for recoverable failures.
src/Appwrite/Platform/Modules/Databases/Http/Embeddings/Text/Create.php Reports partial embedding failures through warning metadata and exposes the aggregate error count.
tests/unit/Migration/MigrationsWorkerExportTest.php Verifies notification failures become warnings and reliably restores process-global span storage.

Reviews (5): Last reviewed commit: "test: satisfy Rector nullable exception ..." | Re-trigger Greptile

Comment thread app/worker.php
Comment on lines +155 to +156
$span = Span::current() ?? Span::init("worker.{$workerName}");
$span->finish(error: $error);

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.

P1 Early worker errors disappear

When project-selective tracing is enabled, an error before project resolution creates this fallback span without project.id. The sampler rejects that span because it cannot match the configured project. Since this callback also removes direct console error output, the worker failure can produce no terminal diagnostics unless another error exporter is configured.

Knowledge Base Used:

Prompt To Fix With AI
This is a comment left during a code review.
Path: app/worker.php
Line: 155-156

Comment:
**Early worker errors disappear**

When project-selective tracing is enabled, an error before project resolution creates this fallback span without `project.id`. The sampler rejects that span because it cannot match the configured project. Since this callback also removes direct console error output, the worker failure can produce no terminal diagnostics unless another error exporter is configured.

**Knowledge Base Used:**
- [Application bootstrap and runtime lifecycle](https://app.greptile.com/appwrite/-/custom-context/knowledge-base/appwrite/appwrite/-/docs/application-bootstrap.md)
- [Background processing and scheduling](https://app.greptile.com/appwrite/-/custom-context/knowledge-base/appwrite/appwrite/-/docs/background-processing.md)

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Claude Code Fix in Codex

@github-actions

github-actions Bot commented Sep 5, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → codex/ce-span-error-cleanup (after).

Metric Before After Change
🚀 Requests/sec 181.02 175 ⚪ -3.3%
⏱️ Latency P50 98.17 ms 99.82 ms ⚪ +1.7%
⏱️ Latency P95 219.44 ms 227.24 ms ⚪ +3.6%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 99.82 227.24 11,172 175 +7.79
Account 187.86 348.33 588 9.81 +26.05
TablesDB 99.36 181.68 6,076 97.93 +4.62
Storage 85.72 190.63 2,940 49.22 +12.28
Functions 137.9 274.77 1,568 26.76 +7.17

Top API waits (after)

API request Max wait (ms)
account.name.update 611.08
functions.create 550.07
account.prefs.update 436.68
functions.variables.update 436.32
functions.delete 425.87

@loks0n
loks0n force-pushed the codex/ce-span-error-cleanup branch from 8c3b489 to 6b3f96d Compare September 5, 2026 13:18
@loks0n
loks0n merged commit b803410 into main Sep 5, 2026
84 of 87 checks passed
@ChiragAgg5k ChiragAgg5k mentioned this pull request Sep 10, 2026
2 of 4 tasks
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.

1 participant