Skip to content

πŸ› fix(task-mcp): a remote task's MCP token works for as long as its lease is renewed - #16915

Merged
hivecommons-hive[bot] merged 1 commit into
hivecommons:v6from
Danathar:fix/task-mcp-lease-token-outlives-renewal
Nov 6, 2026
Merged

hivecommons-hive[bot] merged 1 commit into
hivecommons:v6from
Danathar:fix/task-mcp-lease-token-outlives-renewal

Conversation

@Danathar

@Danathar Danathar commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Summary

On hives with task_mcp.remote_enabled, a remote contributor's task MCP stopped answering 30 minutes after the task was assigned. The token it uses expired with the first task-lease window, although the hub keeps renewing that lease while the relay reports progress. Any task that ran longer got HTTP 403 from its task MCP for the rest of the task. The token now works for as long as the hub's lease on the task is alive, and for no more than 24 hours after assignment. It is still refused the moment the lease ends.

What went wrong

The hub mints the token once, at assignment, and never sends a new one. It stamped the token with the end of the first lease window: assignment plus 30 minutes. Every accepted task_progress moves the lease forward. Nothing moved the token.

A task assigned 31 minutes ago, whose relay reported progress 30 seconds ago, before this change:

task assigned 31m0s ago still holds its lease (29m30s left) but the task MCP answers HTTP 403 forbidden

The docs said the token has "the same expiry as the hub's task lease". That was only true for the first 30 minutes.

What changes

  • The token's own expiry is now a hard cap: 24 hours after assignment. Hub-launched task MCP tokens already default to the same value.
  • Before the cap, the hub's lease record decides, exactly as it did before. The token is accepted only while a lease for the same contributor and task exists, has not expired, and still holds this token's id and hash.
  • No check was loosened. The only behaviour change is the expiry stamped in the two places a token is minted.
  • mcp.expires_at in task_assign now carries the cap, not the end of the first lease window. The reference relay only writes that value into its MCP config.
  • The docs describe the rule as it now is.

Why this is safe: the token cannot outlive its lease. The checks that tie it to the lease were already there and are unchanged.

Event Token after the event
Task released, completed, failed, yanked or requeued refused at once
Relay goes silent and the lease lapses refused
Task handed to another contributor refused
Lease recorded again, or a newer token minted for it refused
24 hours after assignment, lease still being renewed refused

How long a leaked token works:

  • Before: at most 30 minutes after assignment.
  • Now: only while the task is alive on the hub, and at most 24 hours after assignment.
  • If the relay goes silent, the lease lapses within 30 minutes of its last progress report, and the token goes with it.
  • A staged run parked at a checkpoint keeps its lease, and so its token, while it waits there.
  • The token is still read-only, rate-limited, and scoped to the one task's repository.

Not in this change:

  • Minting a new token on every renewal. It needs a new relay message and a relay that rewrites its MCP config in the middle of a task. The lease record gives the same revocation with no protocol change.
  • A setting for the cap. task_mcp.launch_token_ttl still covers hub-launched agents only.
  • A task that runs for more than 24 hours loses its task MCP at the cap. The reference relay ends a task after 4 hours by default.

Files

  • src/pkg/dashboard/task_mcp_lease.go: new constant taskMCPLeaseTokenMaxTTL (24 hours); comments on mintTaskMCPForAssignment and authenticateTaskMCPLease state the rule. No logic change.
  • src/pkg/dashboard/contribute_select.go: selectTaskPass stamps the token with the cap.
  • src/pkg/dashboard/contribute_standby_dispatch.go: assignStandbyTask stamps the token with the cap.
  • src/pkg/dashboard/task_mcp_lease_lifetime_test.go: the new tests.
  • src/docs/design/task-mcp.md: the lifetime rule, and what expires_at means.
  • src/docs/contributor-relay.md: the same, in one sentence, for contributors.
  • changelog.d/fixed-task-mcp-lease-token-renewal.md: the release note.

Tests

These fail without the change:

  • TestTaskAssignMCPTokenOutlivesFirstLeaseWindow: a real ready to task_assign round trip. The token must still verify 31 minutes and 23h59m after assignment, and must be refused after 24 hours.
  • TestStandbyDispatchMCPTokenOutlivesFirstLeaseWindow: the same for a standby dispatch.
  • TestContributeMCPRenewedLeaseKeepsItsTokenWorking: a task assigned 31 minutes or 6 hours ago, with its lease renewed 30 seconds ago, gets 200 from the endpoint.

These pass with and without the change. They pin the checks that make the longer cap safe:

  • TestContributeMCPLeaseTokenDiesWithItsLease: 403 after the task is released, after the lease expires unrenewed, after the expired lease is pruned, after the task goes to another contributor, after the lease is recorded again, and after a newer token replaces this one.
  • TestContributeMCPLeaseTokenIsMatchedByHash: a re-signed copy with the same token id and a later expiry gets 403.
  • TestContributeMCPLeaseTokenRefusedPastItsHardCap: 403 past the cap although the lease is still being renewed, 200 one hour before it.

With the lease-expiry, token-id and token-hash checks switched off by hand, four of those pins fail. So they do guard the checks.

go test -count=1 -run 'TaskMCP|ContributeMCP|LeaseToken|Lease|Standby|TaskAssign|SelectTask' ./pkg/dashboard/ passes, and so does go test -count=1 ./crux/taskmcp/.

πŸ€– Generated with Claude Code

…ease is renewed

With task_mcp.remote_enabled, the task MCP bearer handed out in task_assign
expired with the first task-lease window (assignment + 30 minutes). The hub
renews that lease on every accepted task_progress but mints the token once
and never re-sends it, so a task that ran longer got HTTP 403 from its task
MCP from minute 30 on.

The token's own expiry is now only a hard cap, 24 hours after assignment.
Before the cap the server-side lease record decides, as it already did: no
record, an expired record, or one holding another token id or hash refuses
the token, so it still never outlives its lease. No check is loosened; only
the expiry stamped at the two mint sites (selectTask, standby dispatch)
changes. Docs describe the rule; tests pin both directions.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Signed-off-by: Danathar <Danathar@users.noreply.github.com>
@kubestellar-prow kubestellar-prow Bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Nov 6, 2026
@kubestellar-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign nicholasjackson for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubestellar-prow kubestellar-prow Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 6, 2026
@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Open PR overlap check

Base branch: v6

Conflicts are checked with every PR merged onto the current tip of v6, so a PR that only needs a rebase is not reported as conflicting with its siblings.

PR Title Relation Files
#16919 πŸ› fix(taskmcp): knowledge answers multi-word queries and serves full bodies same files src/docs/design/task-mcp.md

@hivecommons-hive hivecommons-hive Bot 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.

Decision needed: @clubanderson should confirm that a remote contributor's task-MCP token may stay presentable for up to 24h after assignment (previously 30 min), given revocation now rests entirely on the server-side lease record.

The code is correct for what it sets out to do; the only thing I am not willing to settle alone is the credential-lifetime policy, because the author is an OWNERS approver and this widens how long one minted token is accepted.

Verified against v6

  • The revocation claim holds: authenticateTaskMCPLease (pkg/dashboard/task_mcp_lease.go:136-170 on base) requires a live lease record for {identity, task}, !time.Now().After(l.expiresAt), matching mcpTokenID, constant-time mcpTokenHash match, same repo/number, and stage. So before the cap the token lives exactly as long as the lease β€” release/yank/complete delete the record, and an unrenewed lease lapses via l.expiresAt.
  • renewLease (contribute_leases.go:883) advances l.expiresAt = now.Add(leaseTTL) on each accepted progress report; nothing re-minted the token, which is the 30-minute cliff the PR fixes.
  • taskMCPLeaseTokenMaxTTL = config.DefaultTaskMCPLaunchTokenTTL is 24h (pkg/config/task_mcp_config.go:13), and both mint sites (contribute_select.go:1426, contribute_standby_dispatch.go:340) now pass assignedAt.Add(taskMCPLeaseTokenMaxTTL); the token's exp is still enforced by taskmcp.VerifyLeaseToken, so the cap is real.
  • Design doc and contributor-relay doc updated to say mcp.expires_at is an upper bound, not the lease window. go build ./pkg/dashboard/ clean on d3b970c.

What a maintainer should weigh: a leaked lease token was previously dead within 30 minutes regardless of lease state; now it is usable for as long as the compromised relay keeps the lease renewed, up to 24h. Mitigations already present: per-request lease-record check, HMAC-signed claims, rate limiting (allowTaskMCPCall), read-only tool set. If that trade is acceptable, this looks correct to me. Sign-off survives the squash and native-queue-policy show CANCELLED rather than failed on this head β€” likely a concurrency cancel; a re-run should settle them.

β€” hive: agent=reviewer backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive

Copy link
Copy Markdown
Contributor

Needs a decision, not a merge:

  • the reviewer swarm returned requires_human @d3b970c
  • the review found: the reviewer marked this change high-risk
  • reviewer question: @clubanderson should confirm that a remote contributor's task-MCP token may stay presentable for up to 24h after assignment (previously 30 min), given revocation now rests entirely on the server-side lease record.
  • the automerge lane will not merge this unattended

Head: verdict requires_human @d3b970c, 65/65 checks green, DCO yes, soak 0s of 10m0s.

How to release it:

  • After reading the verdict, a trusted merger can submit a GitHub Approve review for the current head and the lane clears the hold on its next pass; /hive approve replies on a PR are acknowledged but not consumed.

Clear the cause and the hive re-evaluates on its next pass; the stage moves to stage/090-ready-for-human-merge, stage/095-pre-merge-soak or the merge queue on its own. Approval does not bypass CI, hold labels or other merge gates.

@hivecommons-hive
hivecommons-hive Bot merged commit 8521076 into hivecommons:v6 Nov 6, 2026
73 of 76 checks passed
@hivecommons-hive

Copy link
Copy Markdown
Contributor

Hive status β€” updated in place; edits do not notify. Full history is in the Activity Monitor.

Evidence bundle `#16915d3b970c` sha256:7f5fa1a02efdf9f5c46a41fc77905b368c29e6c2ce26145459ff32e709512a51 β€” download from the dashboard or `hivectl review evidence #16915`.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dco-signoff: yes Indicates the PR's author has signed the DCO. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant