Skip to content

fix(#70): job token uses the job's timeout; keep own enterprise token - #135

Open
fullsend-ai-coder[bot] wants to merge 2 commits into
mainfrom
agent/70-job-token-timeout-minutes
Open

fullsend-ai-coder[bot] wants to merge 2 commits into
mainfrom
agent/70-job-token-timeout-minutes

Conversation

@fullsend-ai-coder

Copy link
Copy Markdown
Contributor

Summary

The upstream runner's job token is supposed to live for the job's timeout-minutes plus 5 minutes, capped at 24 hours. job_token_lifetime reads job.timeout_minutes, but WorkflowJob had no such column, and the timeout-minutes value parsed in workflow_service was never stored. So every token lived 365 minutes. That is too long for a timeout-minutes: 30 job. For a job longer than 360 minutes, the token expired before the job ended, and from plan version 8 the job's completion report then got 401.

Separately, _with_gh_enterprise_token filled each enterprise variable on its own. A step that set only GITHUB_ENTERPRISE_TOKEN still got GH_ENTERPRISE_TOKEN copied from GH_TOKEN. gh reads GH_ENTERPRISE_TOKEN first, so it used the copied token instead of the one the workflow chose.

Changes

  • src/app/models/actions.py: new nullable WorkflowJob.timeout_minutes. NULL means the 360-minute default.
  • alembic/versions/0022_workflow_job_timeout_minutes.py: adds the column on top of the current head, 0021_runner_registration_broker. It follows the idempotent add-column pattern of 0020/0021.
  • src/app/services/workflow_service.py: build_job_graph turns timeout-minutes into a positive integer or None, via _timeout_minutes. Job creation stores it. An expression like ${{ inputs.timeout }} is not evaluated here, so it gets the default.
  • src/app/services/workflow_scheduler.py: dynamic-matrix instances copy timeout_minutes from the job they are expanded from. Static matrix jobs already go through the creation path above.
  • src/app/api/actions_distributed_task.py: the token is copied into the enterprise variables only when the step's environment sets neither of them. A step that sets one of them gets nothing copied, and other steps still get the token copied as before.
  • docs/bugs/fixed/job-token-ignores-the-jobs-timeout-minutes.md: work-ledger record.

Testing

  • tests/actions/test_runner_job_outputs.py: jobs created from workflow YAML with timeout-minutes: 30 and with none. The test checks the stored value (30 / NULL), job_token_lifetime, and the claimed token's exp - iat (35 min / 365 min).
  • tests/actions/test_dynamic_matrix.py: every dynamic-matrix instance keeps timeout_minutes.
  • tests/actions/test_runner_gh_host.py: a step with GH_TOKEN and GITHUB_ENTERPRISE_TOKEN keeps its own value, and no GH_ENTERPRISE_TOKEN is added.
  • tests/test_database_migrations.py: 0022 adds the column to a database at 0021, and existing jobs get NULL.
  • Full suite: 1564 passed, 2 failed. The failures are test_runner_shutdown::test_a_shutdown_signal_fails_the_running_step_and_stops_its_processes and test_security_headers::test_admin_ui_and_unreserved_admin_path_include_security_headers (the frontend dist is not built in the sandbox). Both fail the same way on unmodified main.
  • ruff check (0.17.3) passes on every file changed here. I also fixed one import-order finding that was already in tests/actions/test_dynamic_matrix.py, because a touched file must pass ruff.
  • pre-commit could not fetch its hook repositories in the sandbox. The pre-commit-hooks v6.0.0 checks, ruff and the secret scan were run directly and passed. shellcheck, actionlint, zizmor and the frontend hooks don't match any changed file.

🤖 Generated with Claude Code


Closes #70

Post-script verification

  • Branch is not main/master (agent/70-job-token-timeout-minutes)
  • Secret scan passed (gitleaks — 0454bace16539f60483343fc2079d8b7d7a6ebc7..HEAD)
  • PR body secret scan passed (gitleaks — no-git)
  • Final PR description secret scan passed (gitleaks — no-git)

job_token_lifetime reads timeout_minutes from the job, but WorkflowJob
had no such column and the parsed timeout-minutes was never stored, so
every upstream-runner job token lived 360 + 5 minutes: longer than a
short job may run, and expiring before a job over 360 minutes ends.

- Add nullable workflow_jobs.timeout_minutes (migration 0022 on head
  0021); NULL means the 360-minute default.
- Store the parsed timeout-minutes at job creation when it is a
  positive number; an unevaluated expression gets the default. Dynamic
  matrix instances copy it in workflow_scheduler.
- _with_gh_enterprise_token mirrors GH_TOKEN/GITHUB_TOKEN into the
  enterprise variables only when the step sets neither of them. gh
  reads GH_ENTERPRISE_TOKEN first, so mirroring it beside a workflow's
  own GITHUB_ENTERPRISE_TOKEN overrode that choice.

Tests cover the stored value, job_token_lifetime and the issued
token's exp - iat with and without timeout-minutes, matrix instances,
the enterprise-token case, and the migration on an existing database.

pre-commit could not fetch its hook repos in the sandbox; the
pre-commit-hooks checks and ruff 0.17.3 were run directly and passed.
Full suite: 1564 passed; test_runner_shutdown and test_security_headers
(frontend dist not built) fail identically on main.

Closes #70

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fullsend-ai-coder fullsend-ai-coder Bot added the ready-for-review Triggers review agent dispatch label Dec 3, 2026
@fullsend-ai-review

fullsend-ai-review Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

🤖 Finished Review · ✅ Success · Started 2:50 PM UTC · Completed 2:58 PM UTC

Commit: bb9d107 · View workflow run →

Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $1.41

@fullsend-ai-review fullsend-ai-review Bot added the risk/moderate PR risk: moderate label Dec 3, 2026
@fullsend-ai-review

Copy link
Copy Markdown

Risk Assessment: moderate (2/5)

Details

Moderate risk driven by a schema migration and recent churn in workflow service files, balanced by moderate diff size, strong test coverage, and exact alignment with linked issue #70.

@fullsend-ai-review

Copy link
Copy Markdown

Review

Head SHA: bb9d107

PR #135 stores timeout-minutes on WorkflowJob (new nullable column plus migration 0022), copies it to dynamic-matrix instances, and stops mirroring GH_TOKEN into the enterprise variables when a step sets either one. The change matches issue #70. The correctness, security, style, intent-coherence and docs-currency reviewers found no problems in the migration, the scheduler copy, the enterprise-token change or the docs. The new tests cover these paths.

Findings

  • low / edge-case — src/app/services/workflow_service.py:279 (_timeout_minutes): the helper is meant to return None for any value it cannot use, but some values make it raise.
    • .inf raises OverflowError.
    • A quoted Unicode digit such as "2" raises ValueError.
    • An integer of 2**63 or more is accepted and then fails on insert into the Integer column.
    • Any of these aborts workflow-run creation. I ran the function body and reproduced the first two.
    • The values are contrived, but the helper's contract is to fall back to the default, and the fix is small. Return None for non-finite floats, catch conversion errors or require ASCII digits, cap the value, and add tests for these inputs.

Risk assessment: moderate (2/5). It includes a schema migration, with strong test coverage and a close match to the linked issue.


Labels: PR is a bug fix for the job token timeout.


Next steps:

  • /fs-fix — agent addresses review findings automatically
  • /fs-fix <your instruction> — agent fixes with your specific guidance
  • Push commits directly — review re-runs automatically on push
  • /fs-fix-stop — disable automatic fix runs for this PR

fullsend-ai-review[bot]

This comment was marked as outdated.

@fullsend-ai-review fullsend-ai-review Bot added the bug Something isn't working label Dec 3, 2026
@fullsend-ai-coder

fullsend-ai-coder Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 Finished Fix · ✅ Success · Started 3:00 PM UTC · Completed 3:04 PM UTC

Commit: bb9d107 · View workflow run →

Runtime: claude · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $0.32

_timeout_minutes now returns None for non-finite floats, non-ASCII digit
strings and strings too long to convert, and caps the value at 24 hours
(the job token lifetime cap) so it always fits the Integer column.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@fullsend-ai-coder

Copy link
Copy Markdown
Contributor Author

🔧 Fix agent — iteration 1 (bot-triggered)

Made timeout-minutes normalization total (non-finite floats, Unicode digit strings, oversized values) and added tests.

Fixed (1):

  1. _timeout_minutes can raise or return a value the Integer column cannot store (src/app/services/workflow_service.py) [f_badf943509ef1854, fixed]: _timeout_minutes now returns None for non-finite floats (inf, nan), accepts strings only when they are ASCII digits, catches ValueError/OverflowError from conversion (including over-long digit strings), and caps the value at 24 hours (the token lifetime cap), so it always fits the column. Added a parametrized test covering these inputs plus the existing valid and default cases.

Tests: passed

CI inspections (2):

  1. test (passing, success): Project test job passed on the PR head.
  2. pre-commit (passing, success): Hygiene pre-commit job passed on the PR head.

Conflict update: skipped; strategy none; forge MERGEABLE; target main

Finding threads:

  • f_badf943509ef1854 (fixed): replied and resolved — thread

Next steps:

  • /fs-review — request a re-review of the changes
  • /fs-fix <your instruction> — run another fix pass with specific guidance
  • Push commits directly — review re-runs automatically on push

Updated by fullsend fix agent

@fullsend-ai-review

fullsend-ai-review Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

🤖 Finished Review · ✅ Success · Started 3:07 PM UTC · Completed 3:13 PM UTC

Commit: 92fb87f · View workflow run →

Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $1.00

@fullsend-ai-review

Copy link
Copy Markdown

Risk Assessment: moderate (2/5)

Details

Moderate risk driven by an Alembic schema migration and recent churn in workflow service files, balanced by moderate change size, bot authorship, solid test coverage, and complete alignment with linked issue #70.

@fullsend-ai-review

fullsend-ai-review Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Looks good to me

Earlier findings

  • src/app/services/workflow_service.py:279, edge-case — resolved: _timeout_minutes now rejects non-ASCII digit strings and non-finite floats, catches conversion errors, and caps the stored value at 24 hours; the new test_timeout_minutes_is_total covers these inputs.

@fullsend-ai-review
fullsend-ai-review Bot dismissed their stale review December 3, 2026 15:13

Superseded by updated review

@fullsend-ai-review fullsend-ai-review Bot added the ready-for-merge All reviewers approved — ready to merge label Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ready-for-merge All reviewers approved — ready to merge ready-for-review Triggers review agent dispatch risk/moderate PR risk: moderate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issue the job token for the job's own timeout-minutes; keep a workflow's own enterprise token

1 participant