Skip to content

Preselect the configured interview length - #584

Open
RWong04 wants to merge 1 commit into
sysprog21:mainfrom
RWong04:preselect-configured-duration
Open

RWong04 wants to merge 1 commit into
sysprog21:mainfrom
RWong04:preselect-configured-duration

Conversation

@RWong04

@RWong04 RWong04 commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Problem and behavior

CODETRIAL_DURATION_MIN is documented as the length the lobby preselects, but only check-gemini, the setup probe and the recording cap check read it, so an operator who set 30 still saw 45 for Medium and Hard, and a token request that named no length got the constant 45.
With this change /api/session reports the default as defaultDurationMin, the lobby preselects it once the session answers (Medium and Hard take it, Easy at most 30, snapped to the nearest enabled button), and Start sends the length on screen. A token request that names no length is granted the default, unsnapped.
With the variable unset the lobby still starts on 45. Two direct-link cases change: ?duration=-5 and ?duration=30abc now name no length and get the default instead of 10 and 30.

Approach

default_duration in src/web/token.rs clamps the configured value into 10 to 90 and to the recording ceiling, and both /api/session and /api/token call it.
configured_duration in src/config.rs reads the setting for the web server and the agent modes: text that is no whole number refuses startup, and a number outside 10 to 90 is clamped and named once on stderr.
web/app.js re-suggests the length when the session answers, except under a Start already on its way, so the length on screen is the one that ships.

Validation

cargo test --locked, cargo clippy --locked --all-targets and node --test tests/browser/ pass, apart from time-dependent livekit startup tests and browser timeouts outside this change, which fail now and then on this machine, one of them on a clean upstream/main too. Each new rule has a test that fails when its line is reverted.
./scripts/test.sh was not rerun on this head. I did not check the lobby by hand in a browser.

Interactive review

This is one commit over the 200-line threshold, so each pushed head went through the local interactive review.
Suggested reading order: src/web/token.rs (default_duration, token_duration_min), src/config.rs (configured_duration), web/app.js (suggestedDuration, loadAccount, the Start handler), then the tests.

Closes #582


Summary by cubic

CODETRIAL_DURATION_MIN now preselects the interview length in the lobby and becomes the default granted to a token request that names none; previously the lobby always started on 45 for Medium and Hard, and a nameless request got the constant 45.

  • Values outside 10–90 are clamped and named at startup on the agent modes too; text that is not a number refuses startup.
  • With recording on, startup refuses a recording cap below the clamped value.
  • /api/session reports the default as defaultDurationMin; the lobby preselects it for Medium and Hard, caps Easy at 30, and snaps non-button values to the nearest enabled button.
  • A length or problem the candidate already chose is never replaced.
  • A token request naming no length is granted the configured default, unsnapped (75 stays 75); null, false, 0 and non-finite text name no length either.
  • The interview page omits durationMin when the URL names none, cuts fractions to whole minutes, and waits for /api/session before drawing its round plan; a Start pressed before /api/session answers leaves the length out unless the lobby already changed it.

With the variable unset, behavior is unchanged.

Closes #582

Written for commit cf1ad2b. Summary will update on new commits.

View guided diff

jserv

This comment was marked as outdated.

cubic-dev-ai[bot]

This comment was marked as resolved.

@jserv jserv added the explained label Nov 4, 2026
@RWong04
RWong04 force-pushed the preselect-configured-duration branch from 72f6667 to e64598e Compare November 4, 2026 11:39
jserv

This comment was marked as resolved.

@Alan52254 Alan52254 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.

The server side is well factored: default_duration is the single source for both /api/session and /api/token, which is exactly what docs/interview-length.md asks for. My comments are about where an invalid or missing input silently changes the result, and about two test-scope issues. The one change I would make before merging is the defaultDuration fallback in web/app.js; the others are smaller. I did not repeat the open threads on web/interview.js:355.

Comment thread web/app.js Resolved
Comment thread src/main.rs Resolved
Comment thread src/web/token.rs Resolved
Comment thread tests/unit/bin.rs Resolved
Comment thread tests/web/token_default.rs Resolved
ColtenOuO

This comment was marked as resolved.

jserv

This comment was marked as resolved.

cubic-dev-ai[bot]

This comment was marked as resolved.

@RWong04
RWong04 force-pushed the preselect-configured-duration branch from 0609ef1 to ceaea79 Compare November 5, 2026 06:21
cubic-dev-ai[bot]

This comment was marked as resolved.

@RWong04
RWong04 force-pushed the preselect-configured-duration branch from ceaea79 to 46a811e Compare November 5, 2026 06:25
jserv

This comment was marked as resolved.

jserv

This comment was marked as resolved.

jserv

This comment was marked as resolved.

jserv

This comment was marked as outdated.

@RWong04
RWong04 force-pushed the preselect-configured-duration branch from 46a811e to 32f8528 Compare November 5, 2026 07:51
cubic-dev-ai[bot]

This comment was marked as resolved.

jserv

This comment was marked as resolved.

jserv

This comment was marked as resolved.

jserv

This comment was marked as resolved.

jserv

This comment was marked as resolved.

jserv

This comment was marked as resolved.

jserv

This comment was marked as outdated.

@RWong04
RWong04 force-pushed the preselect-configured-duration branch from 32f8528 to 4d13dd5 Compare November 5, 2026 08:35
jserv

This comment was marked as outdated.

jserv

This comment was marked as resolved.

Comment thread web/app.js Resolved
jserv

This comment was marked as resolved.

jserv

This comment was marked as resolved.

jserv

This comment was marked as resolved.

@RWong04
RWong04 force-pushed the preselect-configured-duration branch from b1d70b9 to 99b6a95 Compare November 12, 2026 06:19
jserv

This comment was marked as resolved.

jserv

This comment was marked as resolved.

jserv

This comment was marked as resolved.

@RWong04
RWong04 force-pushed the preselect-configured-duration branch from 51964a9 to 3176e85 Compare November 16, 2026 16:09
@RWong04
RWong04 requested a review from alanhc as a code owner November 16, 2026 16:09
Comment thread web/interview.js Resolved

@jserv jserv 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.

Rebase the current branch onto the upstream default branch and resolve any conflicts. Run /codetrial-review in AI agents (use $codetrial-review in Codex) and resolve all identified issues. Rework the series into minimal, logically coherent commits, squash closely related commits, and ensure all commit messages follow the project’s rules.

@jserv

jserv commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Some review comments on this pull request are not settled yet. Please refine the change per the review comments listed below, reply on each thread with what you changed or why you did not, and mark each thread resolved yourself once it is settled (Resolve conversation, at the bottom of the thread). The pull request stays blocked while review threads are open.

Not addressed at the current head:

Checked at 3176e85.

@RWong04
RWong04 force-pushed the preselect-configured-duration branch from 3176e85 to 462a74d Compare November 16, 2026 19:06
Comment thread README.md Resolved
Comment thread docs/interview-length.md Resolved
Comment thread src/config.rs Resolved
Comment thread src/web/token.rs Resolved
@RWong04
RWong04 force-pushed the preselect-configured-duration branch from 462a74d to ffc61f6 Compare November 16, 2026 20:06
Comment thread web/app.js Resolved
The README and docs/interview-length.md call CODETRIAL_DURATION_MIN the
length the lobby preselects, but only check-gemini, the setup probe and
the recording cap check read it. The lobby always started on 45 for
Medium and Hard, and a token request that named no length got the
constant, so an operator who set 30 saw no change.

/api/session now reports the default as defaultDurationMin, clamped into
the range and to the recording ceiling by the same function that
/api/token uses for a request that names no length. The lobby
preselects it for Medium and Hard, and at most 30 for Easy. A value that
is not one of the buttons selects the nearest one, and a length the
candidate chose is left alone. With the variable unset, nothing changes.

Closes sysprog21#582

Change-Id: I73ad723880f8df815252f4cb49cd3df5d992559e
@RWong04
RWong04 force-pushed the preselect-configured-duration branch from ffc61f6 to cf1ad2b Compare November 17, 2026 04:26
@RWong04

RWong04 commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

gates (rust) failed in a desktop test this PR does not touch (Text file busy when executing a freshly written script); a rerun should clear it.

Comment thread web/interview.js
void sessionPromise.then((session) => {
applyGrantedDuration(session?.defaultDurationMin);
renderRoundPlan();
});

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.

There is a race condition here if /api/session resolves after /api/token has already granted the session's actual duration (for example, when /api/token clamps the duration down to a recording ceiling, while /api/session returns the unclamped defaultDurationMin).

Because sessionPromise.then(...) unconditionally calls applyGrantedDuration(session?.defaultDurationMin), a late /api/session response will overwrite the server-granted durationMin with defaultDurationMin and re-render the round plan with a mismatched length—violating the contract documented above applyGrantedDuration (lines 470–473).

Consider tracking whether a token-granted duration has already been applied (or guarding this callback so it only applies before connect() receives a granted duration):

Suggested change
});
else
void sessionPromise.then((session) => {
if (!grantedDurationApplied) {
applyGrantedDuration(session?.defaultDurationMin);
}
renderRoundPlan();
});

(with let grantedDurationApplied = false; set to true when connect() applies the /api/token response).

Local validation environment & test evidence:

  • Environment: MINGW64_NT-10.0-26200 / Node v26.13.0
  • Command: node --test tests/browser/
  • Result: tests 350 | pass 350 | fail 0 (existing suite passes, but no test currently covers out-of-order /api/session vs /api/token settlement when !namedDuration).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This branch runs only when the URL names no length, so /api/token grants default_duration(CODETRIAL_DURATION_MIN, cap). /api/session reports defaultDurationMin from the same default_duration and cap (src/web/auth.rs), so a late answer applies the length already granted; it is not unclamped. Leaving it as is.

Comment thread web/app.js
Comment on lines 1846 to 1853
function suggestedDuration(difficulties) {
return difficulties.has("Medium") || difficulties.has("Hard") ? 45 : 30;
const hard = difficulties.has("Medium") || difficulties.has("Hard");
const wanted = hard ? defaultDuration : Math.min(30, defaultDuration);
const offered = durations.map((button) => Number(button.dataset.duration));
return offered.reduce((best, value) =>
Math.abs(value - wanted) < Math.abs(best - wanted) ? value : best,
);
}

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.

docs/interview-length.md (lines 18–19) specifies: "A default that is not one of the three buttons selects the nearest enabled one". Currently, suggestedDuration maps over all durations without filtering out button.disabled, relying solely on downstream underCeiling() in setDuration() to correct values above durationCeiling. If any button is disabled for reasons other than a ceiling (or if suggestedDuration is reused elsewhere), it returns a disabled duration.

Filtering to enabled buttons first aligns suggestedDuration directly with the documented contract:

Suggested change
function suggestedDuration(difficulties) {
return difficulties.has("Medium") || difficulties.has("Hard") ? 45 : 30;
const hard = difficulties.has("Medium") || difficulties.has("Hard");
const wanted = hard ? defaultDuration : Math.min(30, defaultDuration);
const offered = durations.map((button) => Number(button.dataset.duration));
return offered.reduce((best, value) =>
Math.abs(value - wanted) < Math.abs(best - wanted) ? value : best,
);
}
function suggestedDuration(difficulties) {
const hard = difficulties.has("Medium") || difficulties.has("Hard");
const wanted = hard ? defaultDuration : Math.min(30, defaultDuration);
const enabled = durations.filter((button) => !button.disabled);
const pool = enabled.length > 0 ? enabled : durations;
const offered = pool.map((button) => Number(button.dataset.duration));
return offered.reduce((best, value) =>
Math.abs(value - wanted) < Math.abs(best - wanted) ? value : best,
);
}

Local reproduction & test evidence:

  • Environment: MINGW64_NT-10.0-26200 / Node v26.13.0
  • Reproduction command: node -e 'const durations = [{ dataset: { duration: "30" }, disabled: false }, { dataset: { duration: "45" }, disabled: true }, { dataset: { duration: "60" }, disabled: true }]; const wanted = 60; const offered = durations.map((b) => Number(b.dataset.duration)); const picked = offered.reduce((best, value) => Math.abs(value - wanted) < Math.abs(best - wanted) ? value : best); console.log({ enabledButtons: durations.filter(b => !b.disabled).map(b => b.dataset.duration), picked });'
  • Output: { enabledButtons: [ '30' ], picked: 60 }
  • Browser test suite (node --test tests/browser/): 350 passed, 0 failed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Only applyDurationCeiling disables a button, and setDuration passes the suggestion through underCeiling, which lands on the largest enabled length. Compared with the filtered version for every default and cap from 10 to 90 and both difficulty groups (6642 cases), the result is the same in all of them, so I am leaving it as is.

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.

CODETRIAL_DURATION_MIN does not preselect the interview length in the lobby

5 participants