Skip to content

fix(scheduler): unhang poll-timeout test via configurable grace buffer (#415) - #434

Merged
vybe merged 1 commit into
mainfrom
fix/415-scheduler-poll-timeout-test
Apr 21, 2026
Merged

vybe merged 1 commit into
mainfrom
fix/415-scheduler-poll-timeout-test

Conversation

@dolho

@dolho dolho commented Apr 21, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #415.

tests/scheduler_tests/test_async_dispatch.py::TestDBPolling::test_poll_timeout_raises_exception hung for the full 60s pytest-timeout window on every scheduler test run. Test-only failure — production behavior unchanged.

Root cause

_poll_execution_completion computed its deadline with a hardcoded 60s grace buffer:

# src/scheduler/service.py:946 (before)
deadline = time.monotonic() + float(timeout_seconds) + 60

The test passed timeout_seconds=0 expecting "immediate deadline," but the literal pushed the deadline 60s into the future. pytest-timeout (60s cap) fired first and killed the loop before the service's own Polling deadline exceeded exception could be raised.

The test's existing patch("scheduler.service.config") block couldn't help — the buffer was a literal, not a config read.

Fix

Extract the literal to SchedulerConfig.poll_deadline_buffer (env override POLL_DEADLINE_BUFFER, default 60 to preserve current production behavior). The target test now sets mock_config.poll_deadline_buffer = 0 and trips the deadline on the first iteration (~10ms total).

Companion tests in the same file that patch scheduler.service.config for other reasons now explicitly set poll_deadline_buffer = 60 so float + MagicMock doesn't raise TypeError.

Test plan

  • tests/scheduler_tests/test_async_dispatch.py — 15/15 pass in 0.73s (was: 14 pass + 1 hang hitting 60s timeout).
  • Target test isolated: TestDBPolling::test_poll_timeout_raises_exception passes in 0.13s.
  • Production deadline math unchanged when POLL_DEADLINE_BUFFER unset (default 60 = old literal).

Scope

  • src/scheduler/config.py — new field + env plumbing.
  • src/scheduler/service.py — one-line read swap.
  • tests/scheduler_tests/test_async_dispatch.py — 5 patch sites updated.

No router, DB schema, or external API change.

🤖 Generated with Claude Code

#415)

`test_poll_timeout_raises_exception` passed `timeout_seconds=0` expecting
immediate deadline, but `_poll_execution_completion` added a hardcoded
60s buffer for slot acquisition and cleanup. Deadline landed 60s in the
future; pytest-timeout (60s cap) fired before the service's own
Exception could be raised. Result: 60s hang on every scheduler test run.

Extract the literal to `SchedulerConfig.poll_deadline_buffer` (env:
POLL_DEADLINE_BUFFER, default 60). The existing `patch("scheduler.service.config")`
block in the test now overrides the buffer to 0 and the deadline trips
on the first iteration — test completes in ~10ms. Other tests in the
file that patch config set the buffer explicitly to 60 so existing
timing semantics are preserved.

Production behavior unchanged (default 60 matches the old literal).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

@vybe vybe left a comment

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.

Validated via /validate-pr: clean test fix, preserves production default. ✅

@vybe
vybe merged commit e75e98f into main Apr 21, 2026
trinity-ability pushed a commit that referenced this pull request Oct 13, 2026
CodeQL py/incomplete-url-substring-sanitization (#434, #435): the
registered-host assertions checked "peer.tail1234.ts.net" in the URL
string. Compare urlsplit(url).hostname exactly instead. No other
ent885/ent838 test file carries the pattern.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
vybe added a commit that referenced this pull request Oct 14, 2026
…eyless trusted-network path; the trusted list becomes an outbound allowlist (ent#885) (#3684)

* refactor(a2a): drop the keyless inbound door, the internal scope and the inbound half of the trusted list (ent#885)

Operator ruling 2026-10-10 (ent#862), confirmed in the ent#885 body: a caller
with no Trinity credential never runs a task, whatever network it arrives from.
The admin trusted-networks list STAYS, outbound-only (operator ruling
2026-10-13, ent#885 comment 19:25Z): nothing inbound reads it any more.

Removed in `routers/a2a.py`: `_InternalGate`/`_internal_gate`/`_UNSET`,
`_card_base_url_for`, the three `A2A_INTERNAL_*` budgets, `caller_source` /
`source_host=` threading through `_a2a_idem_scope`, `_run_a2a_task`,
`_stream_task` and the AAuth-era `_dispatch_jsonrpc`, `_keyless_owns`, the
`unexposed=` arm of `_anonymous_jsonrpc`, the `.refuse` gate on the bearer and
AAuth doors, `source_host` in three audit `details`. `a2a_jsonrpc` is the
two-arm `if current_user is None … else _authorize_inbound(...)` again;
`_not_authenticated()` stays a returned JSONResponse (AAuth decorates it).

`services/a2a_trusted_networks.py` loses its inbound half (`internal_source`,
`_source_address`, `_proxy_ips`, the proxy/ingress constants, `internal_base_url`,
`validate_internal_base_url`, `INTERNAL_BASE_URL_KEY`); the list + predicates +
the gateway guard `set_entries` needs stay. The `get_a2a_scope`/`set_a2a_scope`
mixin methods and their `database.py` delegators go; the columns from 0096 stay,
unread. The settings route keeps its path and key but drops `internal_base_url`;
the generic-PUT rung keeps `a2a_trusted_networks` only.

TDD: `tests/unit/test_ent885_keyless_refused.py` drives the real router over the
real unit SQLite with an rc-shaped row (`a2a_scope='internal'`,
`a2a_keyless_internal=1`) and a seeded trusted CIDR. Red at the base: the
tailnet peer got 200 + a dispatch, the keyed public caller and the card got 404.
Its static "nothing reads the inert columns" assertion still names `source_host`
in the dispatch plumbing — closed by the next commit.

Tests re-pinned in this commit: the AAuth suite loses its `get_a2a_scope` stub
and the two `test_internal_scope_*` cases (they patched the deleted
`internal_source`); six keyed/x402 fakes lose their `get_a2a_scope` stub;
`test_ent838` keeps its admin-list + outbound + gateway-guard groups only.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* refactor(a2a): drop the source_host dispatch plumbing (ent#885)

The FREEZE-classified `source_host` field was only ever set by the keyless
inbound door removed in the previous commit ("a declared field is not a sent
field", learning 2026-10-08). Gone from `execute_task`'s signature and both
`TaskExecutionFields(...)` sites, `DISPATCH_FIELDS`, `TaskExecutionFields`,
`ScheduleExecution`, and the row mapper. The `schedule_executions.source_host`
column stays in the DDL + 0096 + its SQLite twin, unwritten and unread (binding:
no drop-column migration in freeze week). `test_1482`'s field set shrinks with it
and `test_ent885`'s static assertion is now green.

`tests/registry.json`: the ent#838 entry is reworded outbound-only; the new
`test_ent885_keyless_refused.py` entry is added.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* refactor(a2a): prove the trusted list is an outbound-only allowlist, both sides (ent#885)

Operator ruling 2026-10-13 (ent#885 comment 19:25Z + the body's "Kept"
section): the admin trusted-networks list stays and governs OUTBOUND ONLY. An
A2A endpoint on a CGNAT address or plain http:// may be registered and called
only when its host is on the list; a host off it gets the v0.9.5 SSRF refusal.
Managed instances talk over a tailnet on plain http, and the keyed builder-agent
cross-instance test (ent#762) must run there before 1.0; token sign-in
(ent#862) stays post-1.0.

`tests/unit/test_ent885_outbound_allowlist.py` drives the two production
readers of the stored list — `a2a_outbound.upsert_endpoint` (register) and
`a2a_client.validate_endpoint` (every call) — with the list written through
the real `set_entries` into the real unit SQLite and the peer name resolving to
100.70.1.2. Off the list: EndpointValidationError at register,
A2ACallError(endpoint_not_https / endpoint_private_address) at call time. On
the list (CIDR, *.suffix or exact name): registered and called on port 80.
A stranger's name under another suffix gets nothing; un-listing refuses the
next call. Neither reader is handed `trusted_entries=` — the stored row is
what admits the host.

No code change in this commit: the `url_validation.py` hook and the outbound
half of `services/a2a_trusted_networks.py` were kept as ruled; the inbound
half went in the first ent#885 commit. Registry entry added.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* refactor(a2a): drop the scope controls from the A2A panel (ent#885)

The keyless trusted-network door and the internal-only scope are gone on
the backend, so the A2A tab loses its "Who can reach it" select, the
keyless toggle, the internal-URL row and the internal cardUrl branch (and
the four base-primitive imports only that block used). setA2aExposure is
back to (name, enabled) and PUTs exactly { enabled }.

The outbound endpoint copy now names the admin's outbound endpoint
allowlist as the one way a private-network or plain-http:// endpoint is
accepted (setting key and route unchanged). The Vite /a2a/ X-Real-IP
overwrite stays (T3 keep), its comment now citing
routers/public.py::_get_client_ip (#181) rather than the trusted-network
check that no longer exists.

a2aPanelScope.spec.js is replaced by a2aPanelNoScope.spec.js, mounted
over the real store with axios stubbed: red before this change on the
three removed behaviours (scope controls rendered, internal card URL,
store forwarding scope/keyless), green after.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* refactor(a2a): rewrite the trusted-networks docs as an outbound-only allowlist (ent#885)

The admin's a2a_trusted_networks list now governs outbound only, so the
docs that described the keyless trusted-network door are rewritten, not
deleted:

- requirements mcp.md §32.7: "A2A Outbound Endpoint Allowlist" — the list
  admits a private/CGNAT or plain-http:// endpoint at register and call
  time; nothing inbound reads it; the inert rc-era columns are named.
- feature-flows a2a-inbound-server.md: the trusted-network section becomes
  the outbound allowlist, with what was removed before 1.0 listed.
- feature-flows a2a-outbound-call.md: the SSRF bullets and the two
  refusal rows name the allowlist as the single exception.
- architecture security.md §5b: outbound-only; inbound needs a credential
  or a payment from any network.
- user-docs a2a-protocol.md "Between your own instances": a keyed call to
  a tailnet peer once its host is on the admin list; the keyless step and
  the scope select are gone.

No release-notes line (binding: the keyless path never shipped stable).

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* refactor(a2a): clean up the keyless-refused test's seeded rows (ent#885)

test_ent885_keyless_refused seeds a2a_trusted_networks = ["100.64.0.0/10"]
and an rc-era agent_ownership row into the island's shared SQLite and left
them there. The outbound validator does read that list, so under
pytest-randomly any later test asserting "CGNAT is refused" admitted the
address: with randomization off, keyless_refused followed by
test_736_a2a_url_validation fails 3 cases (DID NOT RAISE) before this
change and passes after. The door fixture now yields and deletes both rows,
and drops the trusted-networks entry cache if another test loaded it (this
file still never imports the module).

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* refactor(a2a): make the inert-column pin catch a get_a2a_scope read (ent#885)

The static guard's leading \b meant `get_a2a_scope` never matched (`_` is a
word character), so a re-added scope read written through getattr slipped
past it. Dropping the leading boundary on the two column names closes that;
`source_host` keeps it. Mutation: a getattr(db, "get_a2a_scope", ...) read
in a2a_jsonrpc with no behaviour change was green before, is red now.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* refactor(a2a): mark the rc-era A2A columns inert and close §32.7 (ent#885)

- db/tables.py + db/schema.py: the a2a_scope / a2a_keyless_internal column
  comments described the removed inbound keyless door; they now read
  "inert since ent#885; drop under #746" on both tracks (comment-only, no
  migration — the columns stay in the DDL per the ruling).
- requirements/mcp.md §32.7: status 🚧 In Progress → ✅ Implemented, outbound
  allowlist only.

A grep of docs/ found no other stale keyless-A2A / In Progress claim; the
remaining "keyless" hits are the #848 MCP email sign-in tier.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(a2a): compare the parsed host, not a substring (ent#885)

CodeQL py/incomplete-url-substring-sanitization (#434, #435): the
registered-host assertions checked "peer.tail1234.ts.net" in the URL
string. Compare urlsplit(url).hostname exactly instead. No other
ent885/ent838 test file carries the pattern.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Trinity Agent (trinity) <[email protected]>
Co-authored-by: Claude Fable 5.1 <[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.

test: scheduler async dispatch poll-timeout test hangs event loop

2 participants