Skip to content

fix: production Sentry triage — N+1s, admission lock hold, expected-error noise - #447

Merged
artempartos merged 5 commits into
developfrom
artempartos/sentry-issue-7781020950-triage
Oct 8, 2026
Merged

artempartos merged 5 commits into
developfrom
artempartos/sentry-issue-7781020950-triage

Conversation

@artempartos

Copy link
Copy Markdown
Contributor

Summary

Production Sentry triage, 2026-10-08. 60 issues were unresolved. 42 are now closed in Sentry: 37 resolved (already fixed in 1.0.0, one-off rails runner scripts, deploy races) and 5 ignored as noise. This PR fixes the remaining 18, which group into five changes, one commit each:

Issue(s) Problem Change
RAILS-3K, -3D Every session MCP request ran the two repository injection rules once per tool definition: 32 queries Tools::Context#repository_providers, one memoized query
RAILS-3E, -34 board_get_board_info loaded each column's workflow binding separately preload column_workflow_binding: :workflow (also in the columns API)
RAILS-30 personal list_sessions loaded each session's admission includes(:session_admission)
RAILS-2Z finish_session waited up to 20 s on the global SessionAdmissionPolicy lock create_for_workflow_step builds the session under the step_run row lock only, then admits it in a short second transaction
RAILS-3C An expired agent login gave a 500 on Aixle Builder start rescue the preflight errors and redirect back with the message
TEMPORAL-S, -10, -13, -Z, -15..-18, -1N Expected outcomes (login expired, run already cancelled, activity cancelled, phase failing during teardown) reported as errors raised with the BENIGN category; a launch for a cancelled run is also no longer retried
TEMPORAL-1H A permanent vendor refusal of a token refresh was an error reported as a warning; transient failures stay errors
RAILS-39 "Queue is not draining" fired every minute for a full pool that was draining normally (879 events) Silent while the pool keeps granting slots. A pool that has granted nothing for 30 min while a session waits now raises a warning naming the pool, its limit and occupancy. Both reports use a fixed fingerprint.

RAILS-2Z: why the session build now runs outside the lock

SessionAdmissionService.transaction documents that nothing slow may run inside the lock, "no record save that touches half a dozen join tables". create_for_workflow_step did exactly that: rendered the instructions, created the session, resolved its config and attached resources. Now:

  • The build runs in its own transaction under the step_run row lock, so a retried launch never builds twice.
  • Admission takes the writer lock, locks the run and enqueues. Lock order stays policy → run, which is the order WorkflowService#cancel uses, so no new deadlock pair.
  • If the run was stopped between the two steps, the built session is cancelled here: the cancel fan-out skips it because it has no admission to close.
  • A retry after a crash between the two steps queues the session it finds.

The holder of the lock behind the production waits could not be confirmed, because the worker emits no transactions to Sentry. This change removes the one documented violation of that lock's contract. If waits continue, Postgres log_lock_waits would identify the holder.

Test plan

  • New tests for each change. The N+1 and lock-order tests were checked to fail on origin/develop and pass here.
  • Locally in Docker: the changed files plus the admission, relay, workflow-execution, tools, MCP, terminal-session and board API suites, 492 runs, green. Rubocop clean, brakeman no warnings.
  • Full suite: CI.

After deploy, resolve these by hand: Sentry's commit integration points at palad-ai/palad-app, so Fixes keywords here will not close them.
RAILS-3K, -3D, -3E, -34, -30, -2Z, -3C, -39; TEMPORAL-S, -10, -13, -Z, -15, -16, -17, -18, -1N, -1H.

🤖 Generated with Claude Code

artempartos and others added 5 commits October 8, 2026 21:24
Every session MCP request evaluated the two repository injection rules once
per tool definition, 32 queries for one answer (PALAD-AI-RAILS-3K). The
board_get_board_info tool loaded each column's workflow binding separately
(PALAD-AI-RAILS-3E), and the personal list_sessions tool each session's
admission (PALAD-AI-RAILS-30).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
create_for_workflow_step held the installation-wide SessionAdmissionPolicy
lock while it rendered instructions, created the session and attached its
resources, which that lock's own contract forbids. finish_session waited up
to 20 s behind it in production (PALAD-AI-RAILS-2Z).

The session is now built under the step_run row lock alone and admitted in a
second, short transaction. A run stopped in between cancels the built
session, since the cancel fan-out has no admission to close for it; a retry
after a crash between the two queues the session it finds.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
AixleBuilderController#start did not rescue the session-start preflight
errors, so an expired agent login gave the user a 500
(PALAD-AI-RAILS-3C). It now redirects back with the message, as the API
already answers with a 422.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
- An expired agent login refusing a step launch or an exec phase is the
  user's to renew and is shown on the step (PALAD-AI-TEMPORAL-S, -10).
- A step launch for a run already cancelled is final, not retried five
  times (PALAD-AI-TEMPORAL-13).
- A cancelled activity wrapped into an ApplicationError slipped past the
  interceptor's cancellation check (PALAD-AI-TEMPORAL-Z, -15..-18).
- A phase failing after a stop was requested is the teardown, not a fault
  (PALAD-AI-TEMPORAL-1N).

All of these are now raised with the BENIGN category. A permanent vendor
refusal of an agent token refresh is reported as a warning rather than an
error (PALAD-AI-TEMPORAL-1H); transient failures stay errors.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
The oldest admission wait was reported as an error every minute while the
pool was draining normally, 879 events in PALAD-AI-RAILS-39. A long wait in
a pool that keeps granting slots is now silent; a pool that has granted
nothing for the threshold while a session waits is a warning naming the
pool, its limit and occupancy. Both reports carry a fixed fingerprint.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
@artempartos
artempartos merged commit 728b956 into develop Oct 8, 2026
8 checks passed
@artempartos artempartos mentioned this pull request Oct 8, 2026
artempartos added a commit that referenced this pull request Oct 8, 2026
Adds the entries #441, #445 and #447 merged without, then moves
[Unreleased] into 1.1.0. Minor, not patch: the release carries new
features (comment editing, custom analytics range, Sessions & Runs
sorting and date filters, /changelog, Managed by Aixle).

Signed-off-by: Artem Petrov <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
artempartos added a commit that referenced this pull request Nov 18, 2026
)

* fix(sessions): stop three Sentry false alarms from the session pipeline

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]>

* perf: remove the N+1 queries Sentry flagged on runs, team picks and webhooks

- 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]>

---------

Signed-off-by: Artem Petrov <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
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