Skip to content

fix: Sentry triage — session pipeline false alarms and N+1 queries - #773

Merged
artempartos merged 2 commits into
developfrom
fix/sentry-triage-backend
Nov 18, 2026
Merged

artempartos merged 2 commits into
developfrom
fix/sentry-triage-backend

Conversation

@artempartos

Copy link
Copy Markdown
Contributor

Backend half of the 2026-11-18 Sentry triage. The frontend half is a separate PR.

Errors

Issue Cause Fix
PALAD-AI-TEMPORAL-2A A cleanup whose Kubernetes API call timed out (kubeclient raises it as an HttpError with no status) was wrapped as non-retryable, skipping the activity's retry policy and the workflow's 15 s cleanup loop, and the slot waited for the reconciler. ContainerRuntime#transient_error? (Kubernetes: no status, 429, 5xx, refused/reset connection). A transient error in cleanup returns the pass as cleanup_pending, the same as an unfinished delete.
PALAD-AI-TEMPORAL-29 SessionService.revalidate_admission! raises AgentCredential::PreflightError before any phase runs, outside ContainerService::PhaseError, so #447's benign check never saw it. Every preflight refusal is benign. SessionService::PREFLIGHT_REFUSALS is shared with SessionLaunchRelay, which already treated them as expected.
PALAD-AI-RAILS-3S (regressed on 1.15.0) The queue health check and the reconciler's drain both tick on the minute. A company's only slot was released just before the check and granted about 2 s after it, but the check read it as free capacity nobody was granting. Slots released in the last two minutes (DRAIN_GRACE) count as live. A slot that stays unreleased after its session ended still warns.

N+1 queries

Issue Path Fix
PALAD-AI-RAILS-4N, 4G WorkflowService.create: find_or_create_by! per step, so 3 queries per step on every launch StepRun.insert_all! + increment!(:step_runs_count). The run was saved one line earlier, so the lookup could never find anything. StepRun has no create callbacks.
PALAD-AI-RAILS-4M ProjectTeams::Picker: accessible_by? and default_agent_runtime ran per member while holding the team row lock Project#accessible_user_ids: 2 queries for the whole team. The default runtime is read from the credentials the picker already loads.
PALAD-AI-RAILS-4J Tracker app webhooks: one heartbeat UPDATE per matched subscription One update_all
PALAD-AI-RAILS-4H, 4F Admin projects index; a board task's runs on admin show Preload owner/company; stop skipping workflow on nested runs (a task's runs can come from several workflows)

Not changed, with reason

Tests

New tests cover each fix: activity cleanup with an API timeout vs a 403, the re-check refusal being benign, transient_error?, the drain grace window, picker query count independent of team size, accessible_user_ids agreeing with accessible_by?, step-run creation order/state/counter with a step-independent query count, a single heartbeat write for three matched subscriptions, and admin index/show under Bullet with several projects/workflows. The admin tests fail with Bullet::Notification::UnoptimizedQueryError without the fix.

Locally, the touched test files pass, and rubocop and brakeman are clean. CI is the full-suite verification.

Unrelated, found on the way: test/integration/hosted_runtime_unchanged_test.rb fails on clean develop when run alone. A first-use schema query (pg_index for runner_operations) lands in runner_gateway_queries when the schema cache is cold.

🤖 Generated with Claude Code

artempartos and others added 2 commits November 18, 2026 14:39
PALAD-AI-TEMPORAL-2A: a cleanup whose Kubernetes API call timed out was
wrapped as a non-retryable failure, skipping both the activity's retry
policy and the workflow's cleanup timer, and was left to the reconciler.
A transient API error (no status, 429, 5xx, refused or reset connection)
now returns the pass as pending, like a delete still in progress.

PALAD-AI-TEMPORAL-29: the launch re-check raises a credential preflight
refusal before any phase runs, outside ContainerService::PhaseError, so the
benign check from #447 never saw it. Every preflight refusal is now benign,
in one list shared with SessionLaunchRelay.

PALAD-AI-RAILS-3S: the queue health check and the reconciler's drain both
tick on the minute; a slot released just before the check read as free
capacity nobody was granting. A slot released in the last two minutes now
counts as live.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
…ebhooks

- PALAD-AI-RAILS-4N, 4G: WorkflowService.create looked up and created each
  step run one by one, three queries per step, on every launch. The run was
  saved a line earlier, so the lookup never found anything: one insert_all
  and one counter update now.
- PALAD-AI-RAILS-4M: a team pick checked project access and read the
  member's default runtime with queries per member, while holding the team
  row lock. Project#accessible_user_ids answers access for the whole team in
  two queries; the default runtime comes from the credentials already loaded.
- PALAD-AI-RAILS-4J: a Jira or Linear app webhook updated each matched
  subscription's heartbeat separately; one update_all now.
- PALAD-AI-RAILS-4H, 4F: the admin projects index did not preload owner and
  company, and a board task's runs did not preload their workflows.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
@artempartos
artempartos merged commit 154286f into develop Nov 18, 2026
29 of 31 checks passed
@artempartos
artempartos deleted the fix/sentry-triage-backend branch November 18, 2026 06:56
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