Repository navigation
Communication (aka run-twice) Support Implementation - #42
Open
Student-FastDev wants to merge 7 commits into
Open
Student-FastDev wants to merge 7 commits into
Student-FastDev wants to merge 7 commits into
Conversation
Student-FastDev
force-pushed
the
communication
branch
from
October 18, 2026 16:34
9a92fde to
c4b9fb5
Compare
Author
|
I've attached an example package for |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds communication problems for #40. A submission can run several times within one test, with a problem manager deciding what each execution receives. Executions can also run concurrently. Contestants use ordinary
stdin/stdout.For an encoder/decoder task, the manager runs the encoder, checks its output against the channel restrictions, and passes the permitted encoding to a fresh decoder. It compares the decoded answer with the private input and returns the test result. The same runner supports interactive phases and participants that keep running across several turns.
Package settings
Communication mode is configured in the ordinary
Simfile:communicationmanagermanager/instancesmin_instancesinstanceswhen omittedmax_concurrentinstancesFor a two-run task, the only communication-specific settings needed are
communication: trueand the manager path. The remaining limits default to two executions, both required, with one running at a time. A communication package cannot specify a legacy checker or contain checker sources undercheck/orchecker/.These settings bound the whole package. The manager chooses the actual count and schedule for each test, using its private input or the task's rules. The example permits two sequential runs on one test, eight simultaneous participants on another, and 32 runs in waves of four on another. The manager must check that each test's required work was completed.
Processes
JudgeWorkercompiles the contestant and manager through the existing language suites.PreparedProgramowns the executable or script and its seccomp filter. Each execution uses the language-specific runner and a fresh sandbox supervisor. Compiled submissions are reused across executions without recompilation.The manager receives private input as read-only
/in. Itsstdoutcarries framed commands to the host session runner, itsstdinreceives events, and itsstderrcarries the final checker result. Contestantstdoutis always data. Contestants receive only the input selected by the manager, and have no direct pipes to each other.The host owns the pipes and temporary spools. It polls manager commands, contestant output, startup, and termination independently. Bounded spooling lets the runner drain a writer while another participant waits to write.
Batch execution reserves an ID, accepts all input, then starts on commit. The
stdinis a read-only file ending atEOF. The runner drains output privately and releases it to the manager after successful termination. Ordinary buffered solutions therefore work without interactive flushes.Streaming execution starts immediately. The manager can send input during execution and close it when
EOFis required. Output arrives incrementally while the contestant runs. Batch and streaming executions can share a session. If a streaming execution exits early, queued input that can no longer be delivered is discarded but still counts against the limits.IDs begin at 1, increase consecutively, and cannot be reused. A batch reservation counts towards
instancesbefore commit; it occupies a concurrency slot only when committed and launched. The manager must wait forEndedbefore reusing a concurrency slot.OutputClosedreportsEOFonstdout.Endedrequires successful termination and complete output drainage. A contestant failure aborts through the runner's verdict path.Each participant has separate namespaces and a cgroup, with the existing sandbox's capability dropping,
no_new_privs, descriptor closure, read-only runtime mounts, and language-specific seccomp filter. Managers and contestants have a one-process/thread limit. Fresh execution adds opt-in startup events, nonblocking supervisor requests, signal-mask reset, and parent-owned cgroup cleanup. Error and cancellation paths kill and reap supervisors and remove their cgroups.Writing a manager
SIP supplies
templates/communication_manager.ccas a self-contained C++ source, with a lowercase-message encoder/decoder example. It requires no additional link library.run_batch()runs one batch execution at a time and either returns a string or delivers output chunks to a callback.start_stream(),send(),close_input(), andreceive()provide streaming operation.The helper handles framing. Problem authors implement channel validation, query budgets, turn rules, and answer checking. A ten-bit channel requires the manager to validate and, where needed, canonicalize those ten bits before forwarding them. SIM's transport limits do not enforce task-specific channel restrictions. Concurrent managers must dispatch interleaved events by instance ID, handle fragmented output, and wait for all successful
Endedevents. The stockrun_batch()helper expects events for its own run. Overlapping it with another execution requires adapting that event loop.Manager wire interface
The manager runs with
--sim-communication /in. The1inHelloidentifies the wire format; it is not aSimfilesetting. Each frame starts with three unsigned 32-bit little-endian fields: type, instance ID, and payload length. The 12-byte header and payload may span reads or writes. Payloads allow arbitrary bytes, includingNULbytes, up to 65,536 bytes.HelloPrepareBatchBatchInputCommitBatchStartInputCloseInputFinishHelloStartedOutputOutputClosedEOFonstdoutEndedHellomust come first. Instance events have nonzero IDs. Bytes retain their order within an instance. Managers must flush commands and reservestdoutfor frames.Verdicts, limits, and scoring
Acceptance requires every reserved or started execution to finish successfully, with the count between
min_instancesandinstances. Uncommitted reservations and unfinished runs prevent acceptance. The manager sendsFinishwith payload byte1, writes the existing checker result format tostderr, and exits normally:The percentage permits partial credit. For early rejection, the manager sends
Finishwith payload byte0and usesWRONGas the first line of the checker result onstderr. SIM cancels outstanding runs.Finishandstderrmust agree, and no commands may followFinish. Comments pass through the bounded checker-output parser and must not disclose private input.A manager cannot accept a contestant that exceeded a limit or exited abnormally. Invalid frames or lifecycle operations, manager crashes, and missing or contradictory results produce checker errors. Cancellation after early rejection is recorded separately. Each test still produces one result using existing group scoring and submission status logic. Standard time and memory fields report the maximum individual usage.
JudgeWorkerContestants each receive the test's CPU and memory limits. Memory admission adds maximum concurrency times contestant memory, manager memory, the relay reservation, and an accounting page per sandbox. Conversion checks the standard budget before calibration; the worker checks its actual manager limit. The 2 GiB budget is an admission check. Each process has its own cgroup enforcing its individual limit. Spool accounting is cumulative, including framed or forwarded copies. Manager control input is also bounded. Operators must provision temporary storage for their worker pool.
Batch runs keep their individual wall deadlines. Streaming runs may wait for the manager or other participants within this session allowance:
The calculation uses the configured maximum count, even on smaller tests. Individual CPU limits still apply. Session expiry with an occupied concurrency slot produces
TLE; otherwise it produces a checker error.Calibration requires a complete, full-score model result on every test. Authors can use
sip test --keep-limitsto inspect partial scores without changing limits.SIP workflow
sip communication initwrites the settings and manager template, refusing to overwrite an existingSimfileormanager/manager.cc.sip genandsip regengenerate private inputs without.outfiles.sip genoutis rejected for communication packages.sip testruns communication sessions and normally calibrates the model.--keep-limitsdisables calibration, works before or after solution patterns, and leaves theSimfileunchanged.sip packvalidates before using the existing ZIP workflow.The aliases
sip communication test,sip communication gen,sip communication regen, andsip communication packrequire communication mode.Existing installations
The C++
ExecutionFormatenum hasLegacy = 0andCommunication = 1.Legacycovers existing batch and interactive tasks. The upgrader adds the numericproblems.execution_formatcolumn withDEFAULT 0andALGORITHM=INSTANT, so existing problems need no per-row update or package rewrite.The upgrader accepts the current baseline and the preceding schema missing the submission
full_statusindex, applying that existing index change when needed.Existing batch and interactive judge implementations keep their execution paths. Existing language-suite calls retain their runner functions and request options.
Closes #40.