Repository navigation
Feat: Count the build and the download in setup's ready in - #2106
Conversation
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]>
|
Warning Review limit reachedYou'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. View limit details
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. |
clawgenti
left a comment
There was a problem hiding this comment.
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.
| 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)) |
There was a problem hiding this comment.
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.
| } | ||
| _ = 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) |
There was a problem hiding this comment.
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.
clawgenti
left a comment
There was a problem hiding this comment.
磨刀不误砍柴工 — 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 withmake -nplus a standalone GNU make probe of the target-specific:=timing. agentop updateend to end — needs a live release; the wiring ininstallReleasewas 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 failedmake -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 -lclean andgo vet ./cmd/agentopclean 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).
| case "${script_started}" in | ||
| '' | *[!0-9]*) unset CORTEX_SETUP_STARTED ;; | ||
| *) | ||
| CORTEX_SETUP_STARTED=${script_started} |
There was a problem hiding this comment.
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.
| _ = 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()) { |
There was a problem hiding this comment.
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.
Problem
The logo line "ready in 2.6s" counted only setup's own steps.
make dev-installtook much longer, because the go build ran before setup started. Thecurl | shinstall 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 thecortexandagentopprerequisites build.scripts/install.sh: the clock starts at the top of the script.agentop update: the clock starts wheninstallReleasestarts.cmd/agentop/cmd_setup.go: setup reads the variable and calculates the total. Setup still subtracts the time at theContinue? [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
datehas no fractions. "Ready in" can be up to 1s too high.curl | sh, the download of the script itself is not counted.Tests
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-installshows the variable on the setup command.make dev-install, because it restarts the shared proxy.Assisted-By: Claude (Anthropic AI) [email protected]