Skip to content

Feat: Count the build and the download in setup's ready in - #2106

Merged
huang195 merged 1 commit into
rossoctl:mainfrom
huang195:setup-total-time
Nov 24, 2026
Merged

huang195 merged 1 commit into
rossoctl:mainfrom
huang195:setup-total-time

Conversation

@huang195

Copy link
Copy Markdown
Member

Problem

The logo line "ready in 2.6s" counted only setup's own steps. make dev-install took much longer, because the go build ran before setup started. The curl | sh install also did not count the download.

Change

Each caller gives setup its start time in CORTEX_SETUP_STARTED, in Unix seconds. Setup measures "ready in" from that time.

  • Makefile: make reads the time before the cortex and agentop prerequisites build.
  • scripts/install.sh: the clock starts at the top of the script.
  • agentop update: the clock starts when installRelease starts.
  • cmd/agentop/cmd_setup.go: setup reads the variable and calculates the total. Setup still subtracts the time at the Continue? [Y/n] prompt.

This is an environment variable, not a flag, for the same reason as CORTEX_INSTALLER_DREW: the hand-off flags are frozen, and an older agentop ignores the variable. Setup ignores a value that does not parse or that is in the future. Setup removes the variable after it reads it.

Limits

  • Whole seconds only, because macOS date has no fractions. "Ready in" can be up to 1s too high.
  • For curl | sh, the download of the script itself is not counted.

Tests

  • New TestSetupReadyInCountsFromTheCaller: it checks the total without the prompt time, that a future value is ignored, and that the variable is removed. I put back each of the two bugs, and the test failed each time.
  • scripts/dev/go-test-shards.sh -race cmd/agentop: 1253 tests pass.
  • scripts/install_test.sh: 255 pass.
  • make -n dev-install shows the variable on the setup command.
  • I did not run a real make dev-install, because it restarts the shared proxy.

Assisted-By: Claude (Anthropic AI) [email protected]

Before this change, "ready in" counted only setup's own steps. After
make dev-install, the time did not include the go build. After the
curl | sh install, the time did not include the download.

Each caller now gives setup its start time in CORTEX_SETUP_STARTED, in
Unix seconds: the Makefile, install.sh and agentop update. Setup measures
ready in from that time. Setup still subtracts the time at the prompt.
This is an environment variable, not a flag, because the hand-off flags
are frozen. An older agentop ignores the variable.

Setup ignores a value that does not parse or that is in the future.
Setup removes the variable, so the processes that it starts do not get it.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Hai Huang <[email protected]>
@huang195
huang195 requested a review from a team as a code owner November 24, 2026 02:03
@coderabbitai

coderabbitai Bot commented Nov 24, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 32 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: aeb58601-59c9-45c6-9749-8bd7f14b9d9b
Commits

Reviewing files that changed from the base of the PR and between 235be43 and 4ddc61e.

Files selected for processing: 5

  • Makefile
  • cmd/agentop/cmd_setup.go
  • cmd/agentop/cmd_update.go
  • cmd/agentop/setup_e2e_test.go
  • scripts/install.sh
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions github-actions Bot added the ready-for-ai-review Request automated AI code review from clawgenti label Nov 24, 2026

@clawgenti clawgenti left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Clean, small change. I traced the arithmetic and checked each caller. Make expands the target-specific DEV_INSTALL_STARTED := $(shell date +%s) at parse time, before the prerequisites build: a throwaway Makefile with a 2s prerequisite shows started=T, recipe=T+2, and make -n dev-install puts the variable on the setup line. install.sh's clock starts at the top, and the case guard drops a missing or non-numeric value. installRelease passes the value only in the staged child's c.Env, so agentop update itself never holds it, and exec.Cmd's env dedup lets the appended value win over an inherited one. Setup unsets it before it starts any process. took = now - callerAt - (started - promptAt) still leaves out the prompt, and because date +%s rounds down, the error is at most +1s, as the PR says. There are no must-fix issues. One suggestion about caller-side test coverage, and one nit.

Author: huang195 (MEMBER — maintainer)
Areas reviewed: Go (cmd/agentop setup/update), Shell (install.sh), Makefile, tests
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, all signed-off: yes
CI status: passing (annotations are only Node 20 / cache-restore warnings, and no failing tests are hidden behind green jobs)

Verified locally at 4ddc61e: go test -race -run 'TestSetupReadyIn|TestInstallRelease|TestUpdate|TestRunStaged' ./cmd/agentop passes; scripts/install_test.sh passes 255/255; make -n dev-install shows CORTEX_SETUP_STARTED=<epoch> on the setup command.

Comment thread cmd/agentop/cmd_update.go
c := exec.Command(filepath.Join(stage, "agentop"), args...)
c.Stdin, c.Stdout, c.Stderr = os.Stdin, stdout, stderr
c.Env = slices.DeleteFunc(os.Environ(), func(e string) bool { return strings.HasPrefix(e, installerDrewEnv+"=") })
c.Env = append(c.Env, callerStartedEnv+"="+strconv.FormatInt(began.Unix(), 10))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: The new test covers only the setup side, where the value is read. Neither of the two senders in this PR is tested. This hand-off and install.sh's hand_off could stop passing CORTEX_SETUP_STARTED, and every test would still pass. The fakes already record the sibling variable: fakeSetup in cmd_update_test.go writes drew=${CORTEX_INSTALLER_DREW-unset}, and install_test.sh's fake setup logs drew [...]. A started=${CORTEX_SETUP_STARTED-unset} beside each, with an assertion that it is a whole number no later than the time the test reads after the run, would cover both callers for a few lines.

Comment thread cmd/agentop/cmd_setup.go
}
_ = os.Unsetenv(callerStartedEnv)
// shortcut: whole seconds, so ready in can be up to 1s high; take a fraction if a caller can give one.
secs, err := strconv.ParseInt(v, 10, 64)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Values that parse but make no sense still get through: 0, a negative number, or a timestamp left over from a stray export CORTEX_SETUP_STARTED=.... Each turns "ready in" into years or days. CORTEX_INSTALLER_DREW guards a leftover value by also requiring the hand-off flags. The Makefile path has no such flags, so a cheap equivalent would be to also ignore secs <= 0, or a start time older than some generous limit (an hour, say). Not blocking: none of the three callers can produce such a value.

@huang195
huang195 merged commit 94e67fd into rossoctl:main Nov 24, 2026
41 checks passed
@huang195
huang195 deleted the setup-total-time branch November 24, 2026 02:23
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Nov 24, 2026

@clawgenti clawgenti left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

磨刀不误砍柴工 — sharpening the axe does not slow the woodcutting, and this PR stops losing the time spent sharpening. The design is right: the caller owns the clock (the Makefile at parse time, install.sh at its first line, installRelease before the download), setup stays the single place that computes the total, and the hand-off is an environment variable precisely because the flags are frozen. I checked every claim in the body against head; all of them hold. Two non-blocking notes below.

Author: huang195 (MEMBER — maintainer)
Areas reviewed: Go (cmd/agentop), shell (scripts/install.sh), Makefile, tests
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, all signed-off: yes
CI status: passing

Not checked:

  • A real make dev-install — it restarts the shared proxy, the same reason you give; checked instead with make -n plus a standalone GNU make probe of the target-specific := timing.
  • agentop update end to end — needs a live release; the wiring in installRelease was read, not run.

Verified by:

  • go test ./cmd/agentop -run TestSetupReadyIn -count=1 → both tests PASS
  • Three mutations, each killed: dropping callerAt (ready in 1.0s, want 62.0s), counting the prompt (3663.0s, want 62.0s), dropping the future guard (ready in 9223368435.9s, want 1.0s)
  • sh scripts/install_test.sh → 255 passed, 0 failed
  • make -n dev-install → CORTEX_SETUP_STARTED=1795486922 /tmp/.../bin/agentop setup ...
  • Standalone GNU make 4.4.1 probe: a target-specific := $(shell date +%s) was captured 3s before the recipe, matching the 2s+1s prerequisite sleeps, so the build is inside the total
  • gofmt -l clean and go vet ./cmd/agentop clean on the changed files
  • Stale-value probe (throwaway test, deleted afterwards): "-5" → v9.9.9 ready in 1795486964.0s, a 48h-old value → 172801.0s

Generated by RepoMan github-pr-review@9672454 (https://github.com/rossoctl/agent-skills/blob/96724547c162978f58d845b9a8331a679bf39444/skills/github-pr-review/SKILL.md).

Comment thread scripts/install.sh
case "${script_started}" in
'' | *[!0-9]*) unset CORTEX_SETUP_STARTED ;;
*)
CORTEX_SETUP_STARTED=${script_started}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion — 千里之行,始于足下: this export is the first step of the whole feature, and it is the one line no test asserts. The Go side is covered by TestSetupReadyInCountsFromTheCaller, but the shell half of the contract is not: scripts/install_test.sh's fake agentop already records what the handoff passes (printf 'drew [%s]\n' "${CORTEX_INSTALLER_DREW-<unset>}", line 1088), and CORTEX_INSTALLER_DREW has several checks against it (e.g. line 1596).

Suggested fix: add printf 'started [%s]\n' "${CORTEX_SETUP_STARTED-<unset>}" beside the drew line, then two checks next to the existing handoff ones: one that the value equals the run's epoch second (the suite already fakes date), and one that an inherited non-numeric value is unset rather than passed on — that pins the case guard added above.

Why it matters now: a later edit to hand_off can drop the export, or pass a non-numeric value, and nothing in CI notices; every future caller of this contract (a new Makefile target, another installer) inherits that gap.

Comment thread cmd/agentop/cmd_setup.go
_ = os.Unsetenv(callerStartedEnv)
// shortcut: whole seconds, so ready in can be up to 1s high; take a fraction if a caller can give one.
secs, err := strconv.ParseInt(v, 10, 64)
if err != nil || time.Unix(secs, 0).After(setupNow()) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit — The guard rejects a value that does not parse or is in the future, but any parseable past value is accepted, and checklist.FormatDuration is %.1fs, so nothing bounds what the logo prints. Probe on head (throwaway test, deleted afterwards): CORTEX_SETUP_STARTED=-5 → v9.9.9 ready in 1795486964.0s; a value 48h old → 172801.0s.

The realistic route is the case this PR already discusses: an older agentop ignores the variable and does not unset it, so the processes setup starts inherit it, and a setup run launched later from one of those counts from that stale instant.

Suggested fix: bound the value as well as validate it — ignore a start older than the run could plausibly be (24h is generous), and clamp before printing (if took < 0 { took = 0 }) so a backward clock step cannot print a negative "ready in".

Why it matters now: the variable is inherited by every child of the handoff process, so a stale value is cheap to produce and lands in the single number this PR exists to make trustworthy.

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

Labels

ready-for-ai-review Request automated AI code review from clawgenti

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants