Skip to content

docs: Add a concurrency section to AGENTS.md - #6009

Draft
runningcode wants to merge 1 commit into
mainfrom
no/agents-concurrency-guidance
Draft

docs: Add a concurrency section to AGENTS.md#6009
runningcode wants to merge 1 commit into
mainfrom
no/agents-concurrency-guidance

Conversation

@runningcode

Copy link
Copy Markdown
Contributor

📜 Description

Adds a Concurrency section to AGENTS.md, next to the existing exception-handling guidance. The core rule: never hold a lock across a call that can re-enter the SDK — read what you need under the lock, release it, then make the call.

Also covers the second-lock escape hatch for compound operations that were only atomic because the lock spanned them, plus two supporting rules (volatile for cross-thread fields, and reading mutable shared state once per operation).

💡 Motivation and Context

Requested by @buenaflor while reviewing #6007.

Two production ANRs came from the same mistake. In #6007, AppStartExtension held its lock while calling finish() on the app start transaction; finishing captures synchronously and runs PerformanceAndroidEventProcessor, which takes its own lock and then calls back into AppStartExtension — opposite lock order, main thread blocked, ANR. JAVA-553 was the same shape in ReplayIntegration. The volatile and single-read rules come from #6006, where AppStartMetrics.appStartType was read three times in one pass and could disagree with itself.

The exception-handling section already establishes the format for this kind of repository-wide rule, so this follows it: the rule, why it fails, a wrong/right code pair, and the scope.

💚 How did you test it?

Documentation only. ./gradlew spotlessApply is clean.

📝 Checklist

  • I added GH Issue ID & Linear ID
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.
  • Public API changes reviewed by another Mobile SDK team member or implemented according to the develop docs spec.

🔮 Next steps

Independent of #6007 — this documents the rule, that PR fixes the instance.

#skip-changelog

Two production ANRs in the Android SDK came from holding a lock across a
call that re-enters the SDK: finishing a span or transaction captures
synchronously on the calling thread and runs every event processor, and
those processors lock and call back into the component that is still
holding its own lock.

Write the rule down next to the exception-handling guidance, with the
snapshot-then-call pattern, the second-lock escape hatch for compound
operations that were only atomic because the lock spanned them, and the
volatile and single-read rules.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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